public void GenerateShadowMaps(GraphicsContext ctx, SceneGraph sceneGraph) { if (sceneGraph == null) { throw new ArgumentNullException("sceneGraph"); } // Push current viewport to be restore later State.ViewportState currentViewport = new State.ViewportState(ctx); foreach (SceneObjectLight sceneLight in ShadowLights) { using (SceneGraph shadowGraph = new SceneGraph(sceneGraph, //SceneGraphFlags.CullingViewFrustum | SceneGraphFlags.StateSorting SceneGraphFlags.None )) { shadowGraph.SceneRoot.ObjectState.DefineState(new State.CullFaceState(CullFaceMode.Back)); sceneLight.UpdateShadowMap(ctx, shadowGraph); } } // Restore viewport currentViewport.Apply(ctx, null); // Restore cull face state to default State.CullFaceState.DefaultState.Apply(ctx, null); }
private void DisplayShadowMaps(GraphicsContext ctx) { State.ViewportState viewportState = new State.ViewportState(ctx); OrthoProjectionMatrix orthoProjection = new OrthoProjectionMatrix(0.0f, viewportState.Width, 0.0f, viewportState.Height); ModelMatrix model = new ModelMatrix(); // No depth test State.DepthTestState.DefaultState.Apply(ctx, null); ctx.Bind(_ShadowMapDebugProgram); for (int i = 0; i < _LightManager.ShadowLights.Count; i++) { SceneObjectLight shadowLight = _LightManager.ShadowLights[i]; SceneObjectLightSpot shadowSpotLight = shadowLight as SceneObjectLightSpot; if (shadowSpotLight == null) { continue; } Texture2d shadowTex = shadowSpotLight._ShadowMap; shadowTex.SamplerParams.CompareMode = false; ModelMatrix quadModel = new ModelMatrix(model); quadModel.Scale(shadowTex.Width / 4, shadowTex.Height / 4); _ShadowMapDebugProgram.SetUniform(ctx, "glo_ModelViewProjection", orthoProjection * quadModel); _ShadowMapDebugProgram.SetUniform(ctx, "glo_NearFar", new Vertex2f(0.1f, 100.0f)); _ShadowMapDebugProgram.SetUniform(ctx, "glo_Texture", shadowTex); _ShadowMapQuad.Draw(ctx, _ShadowMapDebugProgram); shadowTex.SamplerParams.CompareMode = true; // Stride right model.Translate(shadowTex.Width, 0.0f); } }