@@ -227,12 +227,16 @@ void ShadowCubeApp::Init()
227
227
// ========= Shadow Pass Resources =========
228
228
229
229
// Shadow-pass resource bindings for cube rendering
230
- frame.shadow_pass .cube_program_bindings = shadow_state_settings.program .CreateBindings ({ }, frame.index );
231
- frame.shadow_pass .cube_program_bindings .SetName (fmt::format (" Cube Shadow-Pass Bindings {}" , frame.index ));
230
+ ShadowCubeFrame::PassResources::ProgramBindings& shadow_cube_binds = frame.shadow_pass .cube_bindings ;
231
+ shadow_cube_binds.program_bindings = shadow_state_settings.program .CreateBindings ({ }, frame.index );
232
+ shadow_cube_binds.program_bindings .SetName (fmt::format (" Cube Shadow-Pass Bindings {}" , frame.index ));
233
+ shadow_cube_binds.mesh_uniforms_binding_ptr = &shadow_cube_binds.program_bindings .Get ({ rhi::ShaderType::Vertex, " g_mesh_uniforms" });
232
234
233
235
// Shadow-pass resource bindings for floor rendering
234
- frame.shadow_pass .floor_program_bindings = shadow_state_settings.program .CreateBindings ({}, frame.index );
235
- frame.shadow_pass .floor_program_bindings .SetName (fmt::format (" Floor Shadow-Pass Bindings {}" , frame.index ));
236
+ ShadowCubeFrame::PassResources::ProgramBindings& shadow_floor_binds = frame.shadow_pass .floor_bindings ;
237
+ shadow_floor_binds.program_bindings = shadow_state_settings.program .CreateBindings ({}, frame.index );
238
+ shadow_floor_binds.program_bindings .SetName (fmt::format (" Floor Shadow-Pass Bindings {}" , frame.index ));
239
+ shadow_floor_binds.mesh_uniforms_binding_ptr = &shadow_cube_binds.program_bindings .Get ({ rhi::ShaderType::Vertex, " g_mesh_uniforms" });
236
240
237
241
// Create depth texture for shadow map rendering
238
242
frame.shadow_pass .rt_texture = render_context.CreateTexture (shadow_texture_settings);
@@ -251,20 +255,26 @@ void ShadowCubeApp::Init()
251
255
// ========= Final Pass Resources =========
252
256
253
257
// Final-pass resource bindings for cube rendering
254
- frame.final_pass .cube_program_bindings = final_state_settings.program .CreateBindings ({
258
+ ShadowCubeFrame::PassResources::ProgramBindings& final_cube_binds = frame.final_pass .cube_bindings ;
259
+ final_cube_binds.program_bindings = final_state_settings.program .CreateBindings ({
255
260
{ { rhi::ShaderType::Pixel, " g_constants" }, rhi::RootConstant (g_scene_constants) },
256
261
{ { rhi::ShaderType::Pixel, " g_shadow_map" }, frame.shadow_pass .rt_texture .GetResourceView () },
257
262
{ { rhi::ShaderType::Pixel, " g_shadow_sampler" }, m_shadow_sampler.GetResourceView () },
258
263
{ { rhi::ShaderType::Pixel, " g_texture" }, m_cube_buffers_ptr->GetTexture ().GetResourceView () },
259
264
{ { rhi::ShaderType::Pixel, " g_texture_sampler" }, m_texture_sampler.GetResourceView () },
260
265
}, frame.index );
261
- frame.final_pass .cube_program_bindings .SetName (fmt::format (" Cube Final-Pass Bindings {}" , frame.index ));
266
+ final_cube_binds.program_bindings .SetName (fmt::format (" Cube Final-Pass Bindings {}" , frame.index ));
267
+ final_cube_binds.scene_uniforms_binding_ptr = &final_cube_binds.program_bindings .Get ({ rhi::ShaderType::Pixel, " g_scene_uniforms" });
268
+ final_cube_binds.mesh_uniforms_binding_ptr = &final_cube_binds.program_bindings .Get ({ rhi::ShaderType::Vertex, " g_mesh_uniforms" });
262
269
263
270
// Final-pass resource bindings for floor rendering - patched a copy of cube bindings
264
- frame.final_pass .floor_program_bindings = rhi::ProgramBindings (frame.final_pass .cube_program_bindings , {
271
+ ShadowCubeFrame::PassResources::ProgramBindings& final_floor_binds = frame.final_pass .floor_bindings ;
272
+ final_floor_binds.program_bindings = rhi::ProgramBindings (frame.final_pass .cube_bindings .program_bindings , {
265
273
{ { rhi::ShaderType::Pixel, " g_texture" }, m_floor_buffers_ptr->GetTexture ().GetResourceView () },
266
274
}, frame.index );
267
- frame.final_pass .floor_program_bindings .SetName (fmt::format (" Floor Final-Pass Bindings {}" , frame.index ));
275
+ final_floor_binds.program_bindings .SetName (fmt::format (" Floor Final-Pass Bindings {}" , frame.index ));
276
+ final_floor_binds.scene_uniforms_binding_ptr = &final_floor_binds.program_bindings .Get ({ rhi::ShaderType::Pixel, " g_scene_uniforms" });
277
+ final_floor_binds.mesh_uniforms_binding_ptr = &final_floor_binds.program_bindings .Get ({ rhi::ShaderType::Vertex, " g_mesh_uniforms" });
268
278
269
279
// Bind final pass RT texture and pass to the frame buffer texture and final pass.
270
280
frame.final_pass .rt_texture = frame.screen_texture ;
@@ -314,12 +324,11 @@ bool ShadowCubeApp::Update()
314
324
if (!UserInterfaceApp::Update ())
315
325
return false ;
316
326
317
- // Update scene uniforms
318
- const rhi::RootConstant scene_uniforms_constant (
319
- hlslpp::SceneUniforms{
320
- /* eye_position */ hlslpp::float4 (m_view_camera.GetOrientation ().eye , 1 .F ),
321
- /* light_position */ hlslpp::float4 (m_light_camera.GetOrientation ().eye , 1 .F )
322
- });
327
+ const hlslpp::SceneUniforms scene_uniforms{
328
+ /* eye_position */ hlslpp::float4 (m_view_camera.GetOrientation ().eye , 1 .F ),
329
+ /* light_position */ hlslpp::float4 (m_light_camera.GetOrientation ().eye , 1 .F )
330
+ };
331
+ const rhi::RootConstant scene_uniforms_constant (scene_uniforms);
323
332
324
333
// Prepare homogenous [-1,1] to texture [0,1] coordinates transformation matrix
325
334
static const hlslpp::float4x4 s_homogen_to_texture_coords_matrix = hlslpp::mul (
@@ -333,38 +342,34 @@ bool ShadowCubeApp::Update()
333
342
const ShadowCubeFrame& frame = GetCurrentFrame ();
334
343
335
344
// Update Cube uniforms
336
- frame.final_pass .cube_program_bindings .Get ({ rhi::ShaderType::Pixel, " g_scene_uniforms" }).SetRootConstant (scene_uniforms_constant);
337
- frame.final_pass .cube_program_bindings .Get ({ rhi::ShaderType::Vertex, " g_mesh_uniforms" }).SetRootConstant (
338
- rhi::RootConstant (hlslpp::MeshUniforms{
339
- hlslpp::transpose (cube_model_matrix),
340
- hlslpp::transpose (hlslpp::mul (cube_model_matrix, m_view_camera.GetViewProjMatrix ())),
341
- hlslpp::transpose (hlslpp::mul (hlslpp::mul (cube_model_matrix, m_light_camera.GetViewProjMatrix ()), s_homogen_to_texture_coords_matrix))
342
- })
343
- );
344
- frame.shadow_pass .cube_program_bindings .Get ({ rhi::ShaderType::Vertex, " g_mesh_uniforms" }).SetRootConstant (
345
- rhi::RootConstant (hlslpp::MeshUniforms{
346
- hlslpp::transpose (cube_model_matrix),
347
- hlslpp::transpose (hlslpp::mul (cube_model_matrix, m_light_camera.GetViewProjMatrix ())),
348
- hlslpp::float4x4 ()
349
- })
350
- );
345
+ const hlslpp::MeshUniforms final_cube_uniforms{
346
+ hlslpp::transpose (cube_model_matrix),
347
+ hlslpp::transpose (hlslpp::mul (cube_model_matrix, m_view_camera.GetViewProjMatrix ())),
348
+ hlslpp::transpose (hlslpp::mul (hlslpp::mul (cube_model_matrix, m_light_camera.GetViewProjMatrix ()), s_homogen_to_texture_coords_matrix))
349
+ };
350
+ const hlslpp::MeshUniforms shadow_cube_uniforms{
351
+ hlslpp::transpose (cube_model_matrix),
352
+ hlslpp::transpose (hlslpp::mul (cube_model_matrix, m_light_camera.GetViewProjMatrix ())),
353
+ hlslpp::float4x4 ()
354
+ };
355
+ frame.final_pass .cube_bindings .scene_uniforms_binding_ptr ->SetRootConstant (scene_uniforms_constant);
356
+ frame.final_pass .cube_bindings .mesh_uniforms_binding_ptr ->SetRootConstant (rhi::RootConstant (final_cube_uniforms));
357
+ frame.shadow_pass .cube_bindings .mesh_uniforms_binding_ptr ->SetRootConstant (rhi::RootConstant (shadow_cube_uniforms));
351
358
352
359
// Update Floor uniforms
353
- frame.final_pass .floor_program_bindings .Get ({ rhi::ShaderType::Pixel, " g_scene_uniforms" }).SetRootConstant (scene_uniforms_constant);
354
- frame.final_pass .floor_program_bindings .Get ({ rhi::ShaderType::Vertex, " g_mesh_uniforms" }).SetRootConstant (
355
- rhi::RootConstant (hlslpp::MeshUniforms{
356
- hlslpp::transpose (scale_matrix),
357
- hlslpp::transpose (hlslpp::mul (scale_matrix, m_view_camera.GetViewProjMatrix ())),
358
- hlslpp::transpose (hlslpp::mul (hlslpp::mul (scale_matrix, m_light_camera.GetViewProjMatrix ()), s_homogen_to_texture_coords_matrix))
359
- })
360
- );
361
- frame.shadow_pass .floor_program_bindings .Get ({ rhi::ShaderType::Vertex, " g_mesh_uniforms" }).SetRootConstant (
362
- rhi::RootConstant (hlslpp::MeshUniforms{
363
- hlslpp::transpose (scale_matrix),
364
- hlslpp::transpose (hlslpp::mul (scale_matrix, m_light_camera.GetViewProjMatrix ())),
365
- hlslpp::float4x4 ()
366
- })
367
- );
360
+ const hlslpp::MeshUniforms final_floor_uniforms{
361
+ hlslpp::transpose (scale_matrix),
362
+ hlslpp::transpose (hlslpp::mul (scale_matrix, m_view_camera.GetViewProjMatrix ())),
363
+ hlslpp::transpose (hlslpp::mul (hlslpp::mul (scale_matrix, m_light_camera.GetViewProjMatrix ()), s_homogen_to_texture_coords_matrix))
364
+ };
365
+ const hlslpp::MeshUniforms shadow_floor_uniforms{
366
+ hlslpp::transpose (scale_matrix),
367
+ hlslpp::transpose (hlslpp::mul (scale_matrix, m_light_camera.GetViewProjMatrix ())),
368
+ hlslpp::float4x4 ()
369
+ };
370
+ frame.final_pass .floor_bindings .scene_uniforms_binding_ptr ->SetRootConstant (scene_uniforms_constant);
371
+ frame.final_pass .floor_bindings .mesh_uniforms_binding_ptr ->SetRootConstant (rhi::RootConstant (final_floor_uniforms));
372
+ frame.shadow_pass .floor_bindings .mesh_uniforms_binding_ptr ->SetRootConstant (rhi::RootConstant (shadow_floor_uniforms));
368
373
369
374
return true ;
370
375
}
@@ -395,8 +400,8 @@ void ShadowCubeApp::RenderScene(const RenderPassState& render_pass, const Shadow
395
400
cmd_list.SetViewState (render_pass.view_state );
396
401
397
402
// Draw scene with cube and floor
398
- m_cube_buffers_ptr->Draw (cmd_list, render_pass_resources.cube_program_bindings );
399
- m_floor_buffers_ptr->Draw (cmd_list, render_pass_resources.floor_program_bindings );
403
+ m_cube_buffers_ptr->Draw (cmd_list, render_pass_resources.cube_bindings . program_bindings );
404
+ m_floor_buffers_ptr->Draw (cmd_list, render_pass_resources.floor_bindings . program_bindings );
400
405
401
406
if (render_pass.is_final_pass )
402
407
{
0 commit comments