Render shadows for all spot lights
| 710 | |
| 711 | // Render shadows for all spot lights |
| 712 | void MeshRenderer::RenderSpotLightShadowMap(ID3D12GraphicsCommandList* cmdList, const Camera& camera) |
| 713 | { |
| 714 | PIXMarker marker(cmdList, L"Spot Light Shadow Map Rendering"); |
| 715 | CPUProfileBlock cpuProfileBlock("Spot Light Shadow Map Rendering"); |
| 716 | ProfileBlock profileBlock(cmdList, "Spot Light Shadow Map Rendering"); |
| 717 | |
| 718 | Float4x4* shadowMatrices = spotLightShadowMatrices.Map<Float4x4>(); |
| 719 | |
| 720 | spotLightShadowMap.MakeWritable(cmdList); |
| 721 | |
| 722 | const Array<ModelSpotLight>& spotLights = model->SpotLights(); |
| 723 | const uint64 numSpotLights = Min<uint64>(spotLights.Size(), AppSettings::MaxLightClamp); |
| 724 | for(uint64 i = 0; i < numSpotLights; ++i) |
| 725 | { |
| 726 | PIXMarker lightMarker(cmdList, MakeString(L"Rendering Spot Light Shadow %u", i).c_str()); |
| 727 | |
| 728 | // Set the viewport |
| 729 | DX12::SetViewport(cmdList, SpotLightShadowMapSize, SpotLightShadowMapSize); |
| 730 | |
| 731 | // Set the shadow map as the depth target |
| 732 | D3D12_CPU_DESCRIPTOR_HANDLE dsv = spotLightShadowMap.ArrayDSVs[i].CPUHandle; |
| 733 | cmdList->OMSetRenderTargets(0, nullptr, false, &dsv); |
| 734 | cmdList->ClearDepthStencilView(dsv, D3D12_CLEAR_FLAG_DEPTH | D3D12_CLEAR_FLAG_STENCIL, 1.0f, 0, 0, nullptr); |
| 735 | |
| 736 | const ModelSpotLight& light = spotLights[i]; |
| 737 | |
| 738 | // Draw the mesh with depth only, using the new shadow camera |
| 739 | PerspectiveCamera shadowCamera; |
| 740 | shadowCamera.Initialize(1.0f, light.AngularAttenuation.y, 0.1f, AppSettings::SpotLightRange); |
| 741 | shadowCamera.SetPosition(light.Position); |
| 742 | shadowCamera.SetOrientation(light.Orientation); |
| 743 | RenderSpotLightShadowDepth(cmdList, shadowCamera); |
| 744 | |
| 745 | Float4x4 shadowMatrix = shadowCamera.ViewProjectionMatrix() * ShadowScaleOffsetMatrix; |
| 746 | shadowMatrices[i] = Float4x4::Transpose(shadowMatrix); |
| 747 | } |
| 748 | |
| 749 | spotLightShadowMap.MakeReadable(cmdList); |
| 750 | } |
no test coverage detected