Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathan hoffstadt committed May 9, 2024
1 parent a311108 commit cea1c31
Show file tree
Hide file tree
Showing 7 changed files with 387 additions and 31 deletions.
65 changes: 37 additions & 28 deletions apps/app.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,6 @@ typedef struct plAppData_t
plEntity tMainCamera;
plEntity tSunlight;

// CSM TESTING
plEntity tTestCamera;

// views
uint32_t uSceneHandle0;
uint32_t uViewHandle0;
Expand Down Expand Up @@ -244,7 +241,7 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData)


// create main camera
ptAppData->tMainCamera = gptEcs->create_perspective_camera(ptMainComponentLibrary, "main camera", (plVec3){0, 2.0f, 5.0f}, PL_PI_3, ptIO->afMainViewportSize[0] / ptIO->afMainViewportSize[1], 0.01f, 400.0f);
ptAppData->tMainCamera = gptEcs->create_perspective_camera(ptMainComponentLibrary, "main camera", (plVec3){0, 2.0f, 5.0f}, PL_PI_3, ptIO->afMainViewportSize[0] / ptIO->afMainViewportSize[1], 0.01f, 100.0f);
gptCamera->set_pitch_yaw(gptEcs->get_component(ptMainComponentLibrary, PL_COMPONENT_TYPE_CAMERA, ptAppData->tMainCamera), 0.0f, PL_PI);
gptCamera->update(gptEcs->get_component(ptMainComponentLibrary, PL_COMPONENT_TYPE_CAMERA, ptAppData->tMainCamera));

Expand All @@ -253,15 +250,10 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData)
gptCamera->set_pitch_yaw(gptEcs->get_component(ptMainComponentLibrary, PL_COMPONENT_TYPE_CAMERA, ptAppData->tCullCamera), 0.0f, PL_PI);
gptCamera->update(gptEcs->get_component(ptMainComponentLibrary, PL_COMPONENT_TYPE_CAMERA, ptAppData->tCullCamera));

ptAppData->tTestCamera = gptEcs->create_perspective_camera(ptMainComponentLibrary, "test camera", (plVec3){0.0f, 2.0f, 10.0f}, PL_PI_3, 1.0f, 0.01f, 25.0f);
gptCamera->set_pitch_yaw(gptEcs->get_component(ptMainComponentLibrary, PL_COMPONENT_TYPE_CAMERA, ptAppData->tTestCamera), 0.0f, PL_PI);
gptCamera->update(gptEcs->get_component(ptMainComponentLibrary, PL_COMPONENT_TYPE_CAMERA, ptAppData->tTestCamera));


// create lights
ptAppData->tSunlight = gptEcs->create_directional_light(ptMainComponentLibrary, "sunlight", (plVec3){-1.0f, -1.0f, 0.0f});
plLightComponent* ptLight = gptEcs->get_component(ptMainComponentLibrary, PL_COMPONENT_TYPE_LIGHT, ptAppData->tSunlight);
gptEcs->set_light_shadows(ptMainComponentLibrary, ptAppData->tSunlight, ptAppData->tTestCamera, PL_MAX_SHADOW_CASCADES);
gptEcs->set_light_shadows(ptMainComponentLibrary, ptAppData->tSunlight, ptAppData->tMainCamera, 3);

// load models

Expand Down Expand Up @@ -394,7 +386,9 @@ pl_app_update(plAppData* ptAppData)

plCameraComponent* ptCamera = gptEcs->get_component(ptMainComponentLibrary, PL_COMPONENT_TYPE_CAMERA, ptAppData->tMainCamera);
plCameraComponent* ptCullCamera = gptEcs->get_component(ptMainComponentLibrary, PL_COMPONENT_TYPE_CAMERA, ptAppData->tCullCamera);
plCameraComponent* ptTestCamera = gptEcs->get_component(ptMainComponentLibrary, PL_COMPONENT_TYPE_CAMERA, ptAppData->tTestCamera);

plLightComponent* ptLight = gptEcs->get_component(ptMainComponentLibrary, PL_COMPONENT_TYPE_LIGHT, ptAppData->tSunlight);
plCameraComponent* ptShadowCamera = gptEcs->get_component(ptMainComponentLibrary, PL_COMPONENT_TYPE_CAMERA, ptLight->atShadowCameras[0]);

static const float fCameraTravelSpeed = 4.0f;
static const float fCameraRotationSpeed = 0.005f;
Expand Down Expand Up @@ -423,7 +417,6 @@ pl_app_update(plAppData* ptAppData)

gptCamera->update(ptCamera);
gptCamera->update(ptCullCamera);
gptCamera->update(ptTestCamera);

// run ecs system
gptRenderer->run_ecs(ptAppData->uSceneHandle0);
Expand All @@ -436,7 +429,8 @@ pl_app_update(plAppData* ptAppData)
uint64_t ulValue2 = ulValue0 + 2;
uint64_t ulValue3 = ulValue0 + 3;
uint64_t ulValue4 = ulValue0 + 4;
ptAppData->aulNextTimelineValue[ptGraphics->uCurrentFrameIndex] = ulValue4;
uint64_t ulValue5 = ulValue0 + 5;
ptAppData->aulNextTimelineValue[ptGraphics->uCurrentFrameIndex] = ulValue5;


// first set of work
Expand Down Expand Up @@ -476,6 +470,32 @@ pl_app_update(plAppData* ptAppData)
};
gptGfx->submit_command_buffer(ptGraphics, &tCommandBuffer, &tSubmitInfo00);

plViewOptions tShadowViewOptions = {
.bShowAllBoundingBoxes = false,
.bShowVisibleBoundingBoxes = false,
.bShowOrigin = false,
.bCullStats = false,
.ptViewCamera = ptShadowCamera,
.ptCullCamera = NULL
};

const plBeginCommandInfo tBeginInfo11 = {
.uWaitSemaphoreCount = 1,
.atWaitSempahores = {ptAppData->atSempahore[ptGraphics->uCurrentFrameIndex]},
.auWaitSemaphoreValues = {ulValue2}
};
tCommandBuffer = gptGfx->begin_command_recording(ptGraphics, &tBeginInfo11);
gptRenderer->do_shadows(tCommandBuffer, ptAppData->uSceneHandle0, ptAppData->uViewHandle0, tShadowViewOptions);

gptGfx->end_command_recording(ptGraphics, &tCommandBuffer);

const plSubmitInfo tSubmitInfo11 = {
.uSignalSemaphoreCount = 1,
.atSignalSempahores = {ptAppData->atSempahore[ptGraphics->uCurrentFrameIndex]},
.auSignalSemaphoreValues = {ulValue3}
};
gptGfx->submit_command_buffer(ptGraphics, &tCommandBuffer, &tSubmitInfo11);

plViewOptions tViewOptions = {
.bShowAllBoundingBoxes = ptAppData->bDrawAllBoundingBoxes,
.bShowVisibleBoundingBoxes = ptAppData->bDrawVisibleBoundingBoxes,
Expand All @@ -494,7 +514,7 @@ pl_app_update(plAppData* ptAppData)
const plBeginCommandInfo tBeginInfo1 = {
.uWaitSemaphoreCount = 1,
.atWaitSempahores = {ptAppData->atSempahore[ptGraphics->uCurrentFrameIndex]},
.auWaitSemaphoreValues = {ulValue2}
.auWaitSemaphoreValues = {ulValue3}
};
tCommandBuffer = gptGfx->begin_command_recording(ptGraphics, &tBeginInfo1);
gptRenderer->render_scene(tCommandBuffer, ptAppData->uSceneHandle0, ptAppData->uViewHandle0, tViewOptions);
Expand All @@ -504,7 +524,7 @@ pl_app_update(plAppData* ptAppData)
const plSubmitInfo tSubmitInfo1 = {
.uSignalSemaphoreCount = 1,
.atSignalSempahores = {ptAppData->atSempahore[ptGraphics->uCurrentFrameIndex]},
.auSignalSemaphoreValues = {ulValue3}
.auSignalSemaphoreValues = {ulValue4}
};
gptGfx->submit_command_buffer(ptGraphics, &tCommandBuffer, &tSubmitInfo1);

Expand All @@ -513,7 +533,7 @@ pl_app_update(plAppData* ptAppData)
const plBeginCommandInfo tBeginInfo2 = {
.uWaitSemaphoreCount = 1,
.atWaitSempahores = {ptAppData->atSempahore[ptGraphics->uCurrentFrameIndex]},
.auWaitSemaphoreValues = {ulValue3},
.auWaitSemaphoreValues = {ulValue4},
};
tCommandBuffer = gptGfx->begin_command_recording(ptGraphics, &tBeginInfo2);

Expand Down Expand Up @@ -570,17 +590,6 @@ pl_app_update(plAppData* ptAppData)
ptAppData->bResize = true;
pl_checkbox("Always Resize", &ptAppData->bAlwaysResize);


pl_slider_float("Light X Dir", &ptLight->tDirection.x, -1.0f, 1.0f);
pl_slider_float("Light Y Dir", &ptLight->tDirection.y, -1.0f, 1.0f);
pl_slider_float("Light Z Dir", &ptLight->tDirection.z, -1.0f, 1.0f);

pl_slider_float("Camera Pos X", &ptTestCamera->tPos.x, -100.0f, 100.0f);
pl_slider_float("Camera Pos Y", &ptTestCamera->tPos.y, -100.0f, 100.0f);
pl_slider_float("Camera Pos Z", &ptTestCamera->tPos.z, -100.0f, 100.0f);
pl_slider_float("Camera Yaw", &ptTestCamera->fYaw, -PL_PI, PL_PI);
pl_slider_float("Camera Pitch", &ptTestCamera->fPitch, -PL_PI_2, PL_PI_2);

pl_end_collapsing_header();
}

Expand Down Expand Up @@ -635,7 +644,7 @@ pl_app_update(plAppData* ptAppData)
const plSubmitInfo tSubmitInfo2 = {
.uSignalSemaphoreCount = 1,
.atSignalSempahores = {ptAppData->atSempahore[ptGraphics->uCurrentFrameIndex]},
.auSignalSemaphoreValues = {ulValue4},
.auSignalSemaphoreValues = {ulValue5},
};
gptGfx->end_command_recording(ptGraphics, &tCommandBuffer);
if(!gptGfx->present(ptGraphics, &tCommandBuffer, &tSubmitInfo2))
Expand Down
4 changes: 2 additions & 2 deletions extensions/pl_ecs_ext.c
Original file line number Diff line number Diff line change
Expand Up @@ -1273,15 +1273,15 @@ pl_run_light_update_system(plComponentLibrary* ptLibrary)

for(uint32_t i = 0; i < ptLight->uCascadeCount; i++)
{
const float p = (i + 1) / (float)PL_MAX_SHADOW_CASCADES;
const float p = (i + 1) / (float)ptLight->uCascadeCount;
const float fLog = fMinZ * powf(fRatio, p);
const float fUniform = fMinZ + fRange * p;
const float fD = ptLight->fCascadeSplitLambda * (fLog - fUniform) + fUniform;
afCascadeSplits[i] = (fD - fNearClip) / fClipRange;
}

float fLastSplitDist = 0.0;
for(uint32_t j = 0; j < PL_MAX_SHADOW_CASCADES; j++)
for(uint32_t j = 0; j < ptLight->uCascadeCount; j++)
{
const float fSplitDist = afCascadeSplits[j];

Expand Down
Loading

0 comments on commit cea1c31

Please sign in to comment.