public void RenderForLight(MatrixD lightViewProjection, Matrix lightViewProjectionAtZero, ref Vector3D lightPosition, Texture shadowRenderTarget, Texture shadowDepth, int spotIndex, List <uint> ignoredObjects) { m_renderElementsForShadows.Clear(); m_castingRenderObjectsUnique.Clear(); m_spotFrustum.Matrix = lightViewProjection; //MyRender.GetEntitiesFromPrunningStructure(ref lightBoundingBox, m_castingRenderObjects); //MyRender.GetEntitiesFromShadowStructure(ref lightBoundingBox, m_castingRenderObjects); int occludedItemsStats = 0; //always 0 for shadows MyRender.PrepareEntitiesForDraw(ref m_spotFrustum, lightPosition, (MyOcclusionQueryID)(1), m_castingRenderObjects, null, m_castingCullObjects, m_castingManualCullObjects, null, ref occludedItemsStats); foreach (MyElement element in m_castingRenderObjects) { MyRenderObject renderObject = (MyRenderObject)element; if (ignoredObjects.Contains(renderObject.ID)) { continue; } renderObject.GetRenderElementsForShadowmap(MyLodTypeEnum.LOD0, m_renderElementsForShadows, null); } // Set our targets MyRender.SetRenderTarget(shadowRenderTarget, shadowDepth); MyRender.GraphicsDevice.Clear(ClearFlags.All, new ColorBGRA(1.0f), 1.0f, 0); DepthStencilState.Default.Apply(); RasterizerState.CullNone.Apply(); BlendState.Opaque.Apply(); RenderShadowMap(lightViewProjectionAtZero); MyRender.TakeScreenshot("ShadowMapSpot", shadowRenderTarget, MyEffectScreenshot.ScreenshotTechniqueEnum.Color); }
/// <summary> /// Renders a list of models to the shadow map, and returns a surface /// containing the shadow occlusion factor /// </summary> public void Render() { if (MyRender.Sun.Direction == Vector3.Zero) { return; } MyRender.GetRenderProfiler().StartProfilingBlock("MyShadowRenderer::Render"); if (MultiThreaded) { WaitUntilPrepareForDrawCompleted(); } else { //PrepareFrame(); PrepareCascadesForDraw(); } IssueQueriesForCascades(); MyRender.GetRenderProfiler().StartProfilingBlock("Set & Clear RT"); // Set our targets MyRender.SetRenderTarget(MyRender.GetRenderTarget(m_shadowRenderTarget), MyRender.GetRenderTarget(m_shadowDepthTarget)); MyRender.GraphicsDevice.Clear(ClearFlags.ZBuffer, new ColorBGRA(0.0f), 1.0f, 0); DepthStencilState.Default.Apply(); RasterizerState.CullNone.Apply(); //RasterizerState.CullCounterClockwise.Apply(); BlendState.Opaque.Apply(); MyRender.GetRenderProfiler().EndProfilingBlock(); MyRender.GetRenderProfiler().StartProfilingBlock("Render 4 ShadowMaps"); // Render our scene geometry to each split of the cascade for (int i = 0; i < NumSplits; i++) { if (m_skip[i]) { continue; } if (!m_visibility[i]) { continue; } RenderShadowMap(i); //IssueQueriesForShadowMap(i); } //Restore viewport MyRenderCamera.UpdateCamera(); MyRender.SetDeviceViewport(MyRenderCamera.Viewport); MyRender.GetRenderProfiler().EndProfilingBlock(); // MyGuiManager.TakeScreenshot(); MyRender.TakeScreenshot("ShadowMap", MyRender.GetRenderTarget(m_shadowRenderTarget), MyEffectScreenshot.ScreenshotTechniqueEnum.Color); // Texture.ToFile(MyRender.GetRenderTarget(m_shadowRenderTarget), "c:\\test.dds", ImageFileFormat.Dds); MyRender.GetRenderProfiler().EndProfilingBlock(); }