Skip to content

Commit f8a50b5

Browse files
committed
WIP
WIP
1 parent 6b07a3f commit f8a50b5

11 files changed

Lines changed: 286 additions & 300 deletions

editor/app.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -437,8 +437,9 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData)
437437

438438
// create main camera
439439
plCamera* ptMainCamera = NULL;
440-
ptAppData->tMainCamera = gptCamera->create_perspective(ptAppData->ptComponentLibrary, "main camera", pl_create_vec3_d(fXOffset -4.012, fYOffset + 2.984, fZOffset-1.109), PL_PI_3, ptIO->tMainViewportSize.x / ptIO->tMainViewportSize.y, 0.1f, 650.0f, true, &ptMainCamera);
441-
gptCamera->set_pitch_yaw(ptMainCamera, -0.465f, 1.341f);
440+
// ptAppData->tMainCamera = gptCamera->create_perspective(ptAppData->ptComponentLibrary, "main camera", pl_create_vec3_d(fXOffset -4.012, fYOffset + 2.984, fZOffset-1.109), PL_PI_3, ptIO->tMainViewportSize.x / ptIO->tMainViewportSize.y, 0.1f, 650.0f, true, &ptMainCamera);
441+
ptAppData->tMainCamera = gptCamera->create_perspective(ptAppData->ptComponentLibrary, "main camera", pl_create_vec3_d(fXOffset, fYOffset + 2.984, fZOffset), PL_PI_3, ptIO->tMainViewportSize.x / ptIO->tMainViewportSize.y, 0.1f, 650.0f, true, &ptMainCamera);
442+
gptCamera->set_pitch_yaw(ptMainCamera, 0.0f, PL_PI_2);
442443
gptCamera->update(ptMainCamera);
443444
gptScript->attach(ptAppData->ptComponentLibrary, "pl_script_camera", PL_SCRIPT_FLAG_PLAYING | PL_SCRIPT_FLAG_RELOADABLE, ptAppData->tMainCamera, NULL);
444445

@@ -470,13 +471,14 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData)
470471

471472
// create lights
472473
plLightComponent* ptLight = NULL;
473-
plEntity tDirectionLight = gptRenderer->create_directional_light(ptAppData->ptComponentLibrary, "direction light", pl_create_vec3(0.425f, -1.0f, -0.384f), &ptLight);
474+
// plEntity tDirectionLight = gptRenderer->create_directional_light(ptAppData->ptComponentLibrary, "direction light", pl_create_vec3(0.425f, -1.0f, -0.384f), &ptLight);
475+
plEntity tDirectionLight = gptRenderer->create_directional_light(ptAppData->ptComponentLibrary, "direction light", pl_create_vec3(0.0f, -1.0f, 0.0f), &ptLight);
474476
ptLight->uCascadeCount = 4;
475477
ptLight->fIntensity = 18.0f;
476478
ptLight->uShadowResolution = 1024 * 2;
477479
ptLight->afCascadeSplits[0] = 0.005f;
478480
ptLight->afCascadeSplits[1] = 0.020f;
479-
ptLight->afCascadeSplits[2] = 0.25f;
481+
ptLight->afCascadeSplits[2] = 0.10f;
480482
ptLight->afCascadeSplits[3] = 1.00f;
481483
ptLight->tFlags |= PL_LIGHT_FLAG_CAST_SHADOW | PL_LIGHT_FLAG_VISUALIZER;
482484

extensions/pl_camera_ext.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,11 +137,12 @@ pl_camera_update(plCamera* ptCamera)
137137
break;
138138
}
139139

140-
case PL_CAMERA_TYPE_ORTHOGRAPHIC:
140+
case PL_CAMERA_TYPE_ORTHOGRAPHIC: // reverse z
141141
{
142142
ptCamera->tProjMat.col[0].x = 2.0f / ptCamera->fWidth;
143143
ptCamera->tProjMat.col[1].y = 2.0f / ptCamera->fHeight;
144144
ptCamera->tProjMat.col[2].z = 1 / (ptCamera->fFarZ - ptCamera->fNearZ);
145+
ptCamera->tProjMat.col[3].z = -ptCamera->fFarZ / (ptCamera->fNearZ - ptCamera->fFarZ);
145146
ptCamera->tProjMat.col[3].w = 1.0f;
146147
break;
147148
}

extensions/pl_renderer_ext.c

Lines changed: 42 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1193,7 +1193,7 @@ pl_renderer_create_scene(plSceneInit tInit)
11931193
.iTreeDepth = 6,
11941194
.fMaxHeight = 500.0f,
11951195
.fMinHeight = 0.0f,
1196-
.fMaxBaseError = 1.0f,
1196+
.fMaxBaseError = 0.1f,
11971197
.tCenter = {0}
11981198
};
11991199
plTerrainProcessInfo tTerrainInfo = {
@@ -3100,7 +3100,13 @@ pl_renderer_prepare_scene(plScene* ptScene)
31003100
.tColor = ptLight->tColor,
31013101
.iShadowIndex = (int)ptScene->uDOffset++,
31023102
.iCastShadow = 1,
3103-
.iCascadeCount = (int)ptLight->uCascadeCount
3103+
.iCascadeCount = (int)ptLight->uCascadeCount,
3104+
.afCascadeSplits = {
3105+
ptLight->afCascadeSplits[0],
3106+
ptLight->afCascadeSplits[1],
3107+
ptLight->afCascadeSplits[2],
3108+
ptLight->afCascadeSplits[3]
3109+
}
31043110
};
31053111
pl_sb_push(ptScene->sbtDirectionLightData, tLight);
31063112

@@ -3122,7 +3128,13 @@ pl_renderer_prepare_scene(plScene* ptScene)
31223128
.tColor = ptLight->tColor,
31233129
.iShadowIndex = 0,
31243130
.iCastShadow = ptLight->tFlags & PL_LIGHT_FLAG_CAST_SHADOW,
3125-
.iCascadeCount = (int)ptLight->uCascadeCount
3131+
.iCascadeCount = (int)ptLight->uCascadeCount,
3132+
.afCascadeSplits = {
3133+
ptLight->afCascadeSplits[0],
3134+
ptLight->afCascadeSplits[1],
3135+
ptLight->afCascadeSplits[2],
3136+
ptLight->afCascadeSplits[3]
3137+
}
31263138
};
31273139
pl_sb_push(ptScene->sbtDirectionLightData, tLight);
31283140
}
@@ -3424,7 +3436,7 @@ pl_renderer_prepare_scene(plScene* ptScene)
34243436
.tDLightShadowDataBuffer = ptProbe->tDLightShadowDataBuffer,
34253437
.sbtDLightShadowData = ptProbe->sbtDLightShadowData
34263438
};
3427-
pl__renderer_generate_cascaded_shadow_map(ptCSMEncoder, ptCSMCommandBuffer, ptScene, uFace, uProbeIndex, &atEnvironmentCamera[uFace], tCSMInfo);
3439+
pl__renderer_generate_cascaded_shadow_map(ptCSMEncoder, ptCSMCommandBuffer, ptScene, uFace, uProbeIndex, &atEnvironmentCamera[uFace], tCSMInfo, NULL);
34283440

34293441
gptGfx->pop_render_debug_group(ptCSMEncoder);
34303442
gptGfx->end_render_pass(ptCSMEncoder);
@@ -3510,6 +3522,10 @@ pl_renderer_prepare_view(plView* ptView, plCamera* ptCamera)
35103522
ptView->tData.tFogColor = gptData->tRuntimeOptions.tFogColor;
35113523
ptView->tData.fFogLinearParam0 = 1.0f / (ptView->tData.fFogCutOffDistance - ptView->tData.fFogStart);
35123524
ptView->tData.fFogLinearParam1 = -ptView->tData.fFogStart / (ptView->tData.fFogCutOffDistance - ptView->tData.fFogStart);
3525+
// ptView->tData.tCameraPos.xyz = ptCamera->tPos;
3526+
ptView->tData.tCameraPos.x = ptCamera->fNearZ;
3527+
ptView->tData.tCameraPos.y = ptCamera->fFarZ;
3528+
ptView->tData.tCameraPos.w = (ptCamera->fFarZ - ptCamera->fNearZ);
35133529

35143530
const float fFogDensity = -(float)(ptView->tData.fFogHeightFalloff * (ptCamera->tPos.y - ptView->tData.fFogHeight));
35153531
ptView->tData.tFogDensity = (plVec3){gptData->tRuntimeOptions.fFogDensity, fFogDensity, gptData->tRuntimeOptions.fFogDensity * expf(fFogDensity)};
@@ -3536,7 +3552,7 @@ pl_renderer_prepare_view(plView* ptView, plCamera* ptCamera)
35363552
.tDLightShadowDataBuffer = ptView->atDLightShadowDataBuffer[uFrameIdx],
35373553
.sbtDLightShadowData = ptView->sbtDLightShadowData
35383554
};
3539-
pl__renderer_generate_cascaded_shadow_map(ptCSMEncoder, ptCSMCmdBuffer, ptScene, ptView->uIndex, 0, ptCamera, tCSMInfo);
3555+
pl__renderer_generate_cascaded_shadow_map(ptCSMEncoder, ptCSMCmdBuffer, ptScene, ptView->uIndex, 0, ptCamera, tCSMInfo, ptView->pt3DDrawList);
35403556

35413557
gptGfx->pop_render_debug_group(ptCSMEncoder);
35423558
gptGfx->end_render_pass(ptCSMEncoder);
@@ -3762,6 +3778,27 @@ pl_renderer_render_view(plView* ptView, plCamera* ptCamera, plCamera* ptCullCame
37623778
};
37633779
pl__render_view_gbuffer_fill_pass(ptScene, ptMainEncoder, &tGbufferFillPassInfo);
37643780

3781+
// move to function
3782+
{
3783+
const plMat4 tMVP = pl_mul_mat4(&ptCamera->tProjMat, &ptCamera->tViewMat);
3784+
3785+
gptGfx->set_depth_bias(ptMainEncoder, 0.0f, 0.0f, 0.0f);
3786+
gptGfx->bind_shader(ptMainEncoder, ptScene->tTerrainShader);
3787+
gptGfx->bind_vertex_buffer(ptMainEncoder, ptScene->ptTerrain->tVertexBuffer);
3788+
plBindGroupHandle atBindGroups[] = {ptScene->atSceneBindGroups[uFrameIdx], ptView->atDeferredBG1[uFrameIdx]};
3789+
gptGfx->bind_graphics_bind_groups(
3790+
ptMainEncoder,
3791+
ptScene->tTerrainShader,
3792+
0, 2,
3793+
atBindGroups,
3794+
0, NULL
3795+
);
3796+
3797+
3798+
for(uint32_t i = 0; i < pl_sb_size(ptScene->ptTerrain->sbtChunkFiles); i++)
3799+
pl__render_chunk(ptScene, ptScene->ptTerrain, ptCamera, ptMainEncoder, &ptScene->ptTerrain->sbtChunkFiles[i].tFile.atChunks[0], &ptScene->ptTerrain->sbtChunkFiles[i].tFile, &tMVP, 0);
3800+
}
3801+
37653802
gptGfx->next_subpass(ptMainEncoder, NULL);
37663803

37673804
plDeferredLightingPassInfo tDeferredLightingPassInfo = {
@@ -3796,27 +3833,6 @@ pl_renderer_render_view(plView* ptView, plCamera* ptCamera, plCamera* ptCullCame
37963833
};
37973834
pl__render_view_forward_pass(ptScene, ptMainEncoder, ptView->atViewBG[uFrameIdx], &tForwardPassInfo);
37983835

3799-
// move to function
3800-
{
3801-
const plMat4 tMVP = pl_mul_mat4(&ptCamera->tProjMat, &ptCamera->tViewMat);
3802-
3803-
gptGfx->set_depth_bias(ptMainEncoder, 0.0f, 0.0f, 0.0f);
3804-
gptGfx->bind_shader(ptMainEncoder, ptScene->tTerrainShader);
3805-
gptGfx->bind_vertex_buffer(ptMainEncoder, ptScene->ptTerrain->tVertexBuffer);
3806-
plBindGroupHandle atBindGroups[] = {ptScene->atSceneBindGroups[uFrameIdx], ptView->atViewBG[uFrameIdx]};
3807-
gptGfx->bind_graphics_bind_groups(
3808-
ptMainEncoder,
3809-
ptScene->tTerrainShader,
3810-
0, 2,
3811-
atBindGroups,
3812-
0, NULL
3813-
);
3814-
3815-
3816-
for(uint32_t i = 0; i < pl_sb_size(ptScene->ptTerrain->sbtChunkFiles); i++)
3817-
pl__render_chunk(ptScene, ptScene->ptTerrain, ptCamera, ptMainEncoder, &ptScene->ptTerrain->sbtChunkFiles[i].tFile.atChunks[0], &ptScene->ptTerrain->sbtChunkFiles[i].tFile, &tMVP, 0);
3818-
}
3819-
38203836
gptGfx->pop_render_debug_group(ptMainEncoder);
38213837

38223838
// end main render pass

0 commit comments

Comments
 (0)