| 321 | } |
| 322 | |
| 323 | bool ShadowCubeApp::Update() |
| 324 | { |
| 325 | if (!UserInterfaceApp::Update()) |
| 326 | return false; |
| 327 | |
| 328 | const hlslpp::SceneUniforms scene_uniforms{ |
| 329 | .eye_position = hlslpp::float4(m_view_camera.GetOrientation().eye, 1.F), |
| 330 | .light_position = hlslpp::float4(m_light_camera.GetOrientation().eye, 1.F) |
| 331 | }; |
| 332 | const rhi::RootConstant scene_uniforms_constant(scene_uniforms); |
| 333 | |
| 334 | // Prepare homogenous [-1,1] to texture [0,1] coordinates transformation matrix |
| 335 | static const hlslpp::float4x4 s_homogen_to_texture_coords_matrix = hlslpp::mul( |
| 336 | hlslpp::float4x4::scale(0.5F, -0.5F, 1.F), |
| 337 | hlslpp::float4x4::translation(0.5F, 0.5F, 0.F) |
| 338 | ); |
| 339 | |
| 340 | const hlslpp::float4x4 scale_matrix = hlslpp::float4x4::scale(15.F); |
| 341 | const hlslpp::float4x4 cube_model_matrix = hlslpp::mul(hlslpp::float4x4::translation(0.F, 0.5F, 0.F), scale_matrix); |
| 342 | |
| 343 | const ShadowCubeFrame& frame = GetCurrentFrame(); |
| 344 | |
| 345 | // Update Cube uniforms |
| 346 | const hlslpp::MeshUniforms final_cube_uniforms{ |
| 347 | .model_matrix = hlslpp::transpose(cube_model_matrix), |
| 348 | .mvp_matrix = hlslpp::transpose(hlslpp::mul(cube_model_matrix, m_view_camera.GetViewProjMatrix())), |
| 349 | .shadow_mvpx_matrix = hlslpp::transpose(hlslpp::mul( |
| 350 | hlslpp::mul(cube_model_matrix, m_light_camera.GetViewProjMatrix()), |
| 351 | s_homogen_to_texture_coords_matrix)) |
| 352 | }; |
| 353 | const hlslpp::MeshUniforms shadow_cube_uniforms{ |
| 354 | .model_matrix = hlslpp::transpose(cube_model_matrix), |
| 355 | .mvp_matrix = hlslpp::transpose(hlslpp::mul(cube_model_matrix, m_light_camera.GetViewProjMatrix())), |
| 356 | .shadow_mvpx_matrix = hlslpp::float4x4() |
| 357 | }; |
| 358 | frame.final_pass.cube_bindings.scene_uniforms_binding_ptr->SetRootConstant(scene_uniforms_constant); |
| 359 | frame.final_pass.cube_bindings.mesh_uniforms_binding_ptr->SetRootConstant(rhi::RootConstant(final_cube_uniforms)); |
| 360 | frame.shadow_pass.cube_bindings.mesh_uniforms_binding_ptr->SetRootConstant(rhi::RootConstant(shadow_cube_uniforms)); |
| 361 | |
| 362 | // Update Floor uniforms |
| 363 | const hlslpp::MeshUniforms final_floor_uniforms{ |
| 364 | .model_matrix = hlslpp::transpose(scale_matrix), |
| 365 | .mvp_matrix = hlslpp::transpose(hlslpp::mul(scale_matrix, m_view_camera.GetViewProjMatrix())), |
| 366 | .shadow_mvpx_matrix = hlslpp::transpose(hlslpp::mul( |
| 367 | hlslpp::mul(scale_matrix, m_light_camera.GetViewProjMatrix()), |
| 368 | s_homogen_to_texture_coords_matrix)) |
| 369 | }; |
| 370 | const hlslpp::MeshUniforms shadow_floor_uniforms{ |
| 371 | .model_matrix = hlslpp::transpose(scale_matrix), |
| 372 | .mvp_matrix = hlslpp::transpose(hlslpp::mul(scale_matrix, m_light_camera.GetViewProjMatrix())), |
| 373 | .shadow_mvpx_matrix = hlslpp::float4x4() |
| 374 | }; |
| 375 | frame.final_pass.floor_bindings.scene_uniforms_binding_ptr->SetRootConstant(scene_uniforms_constant); |
| 376 | frame.final_pass.floor_bindings.mesh_uniforms_binding_ptr->SetRootConstant(rhi::RootConstant(final_floor_uniforms)); |
| 377 | frame.shadow_pass.floor_bindings.mesh_uniforms_binding_ptr->SetRootConstant(rhi::RootConstant(shadow_floor_uniforms)); |
| 378 | |
| 379 | return true; |
| 380 | } |
no test coverage detected