internal static void Combine(RwTexId targetArray, MyShadowCascades firstCascades, MyShadowCascades secondCascades) { if (!MyRender11.Settings.EnableShadows) { return; } ProfilerShort.Begin("MyShadowCascadesPostProcess.Combine"); MyGpuProfiler.IC_BeginBlock("MyShadowCascadesPostProcess.Combine"); firstCascades.FillConstantBuffer(firstCascades.CascadeConstantBuffer); secondCascades.FillConstantBuffer(secondCascades.CascadeConstantBuffer); secondCascades.PostProcessor.MarkCascadesInStencil(secondCascades.CascadeInfo); MyRenderContext renderContext = MyRenderContext.Immediate; DeviceContext deviceContext = renderContext.DeviceContext; deviceContext.PixelShader.SetConstantBuffer(MyCommon.FRAME_SLOT, MyCommon.FrameConstants); deviceContext.PixelShader.SetConstantBuffer(10, firstCascades.CascadeConstantBuffer); deviceContext.PixelShader.SetConstantBuffer(11, secondCascades.CascadeConstantBuffer); deviceContext.PixelShader.SetConstantBuffer(12, m_inverseConstants); for (int subresourceIndex = 0; subresourceIndex < targetArray.Description2d.ArraySize; ++subresourceIndex) { renderContext.BindGBufferForRead(0, MyGBuffer.Main); deviceContext.OutputMerger.SetTargets((DepthStencilView)null, (RenderTargetView)targetArray.SubresourceRtv(subresourceIndex)); deviceContext.PixelShader.SetShaderResource(0, firstCascades.CascadeShadowmapArray.SubresourceSrv(subresourceIndex)); deviceContext.PixelShader.SetShaderResource(1, secondCascades.CascadeShadowmapArray.ShaderView); //deviceContext.PixelShader.SetShaderResource(4, MyGBuffer.Main.DepthStencil.m_SRV_stencil); renderContext.SetPS(m_combinePS); Matrix inverseCascadeMatrix = MatrixD.Transpose(MatrixD.Invert(firstCascades.CascadeInfo[subresourceIndex].CurrentLocalToProjection * MyMatrixHelpers.ClipspaceToTexture)); var mapping = MyMapping.MapDiscard(m_inverseConstants); mapping.WriteAndPosition(ref inverseCascadeMatrix); mapping.Unmap(); MyScreenPass.DrawFullscreenQuad(new MyViewport(0, 0, targetArray.Description2d.Width, targetArray.Description2d.Height)); } deviceContext.OutputMerger.SetTargets(null as DepthStencilView, null as RenderTargetView); deviceContext.PixelShader.SetShaderResource(0, null); deviceContext.PixelShader.SetShaderResource(1, null); deviceContext.PixelShader.SetShaderResource(2, null); MyGpuProfiler.IC_EndBlock(); ProfilerShort.End(); }