/// <summary> /// Update shadow map. /// </summary> /// <param name="ctx"> /// A <see cref="GraphicsContext"/> used for allocating resources. /// </param> public override void UpdateShadowMap(GraphicsContext ctx, SceneGraph shadowGraph) { CheckCurrentContext(ctx); if (shadowGraph == null) { throw new ArgumentNullException("shadowGraph"); } // Compute light matrix IModelMatrix viewMatrix = new ModelMatrix(); // LocalModel.Multiply(LightMatrix.GetInverseMatrix()).GetInverseMatrix(); viewMatrix.LookAtDirection((Vertex3d)LocalModel.Position, (Vertex3f)Direction, Vertex3d.UnitY); // Set light scene view shadowGraph.ProjectionMatrix = new PerspectiveProjectionMatrix(FalloffAngle * 2.0f, 1.0f, 0.1f, 100.0f); shadowGraph.ViewMatrix = viewMatrix; _ShadowFramebuffer.BindDraw(ctx); // Reset viewport new ViewportState(0, 0, (int)_ShadowMap.Width, (int)_ShadowMap.Height).Apply(ctx, null); _ShadowFramebuffer.Clear(ctx, ClearBufferMask.DepthBufferBit); shadowGraph.Draw(ctx, _ShadowProgram); _ShadowFramebuffer.UnbindDraw(ctx); // Cache view matrix _ShadowViewMatrix = _BiasMatrix.Multiply(shadowGraph.ProjectionMatrix.Multiply(viewMatrix)); }
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); }
public SceneGraphContext(SceneGraph sceneGraph) : this(sceneGraph, null) { if (sceneGraph == null) { throw new ArgumentNullException("sceneGraph"); } Scene = sceneGraph; }
/// <summary> /// Static constructor. /// </summary> static SceneObject() { // Static initialization SceneGraph.Touch(); SceneObjectCamera.Touch(); SceneObjectGeometry.Touch(); SceneObjectLight.Touch(); SceneObjectLightZone.Touch(); }
public SceneGraphContext(SceneGraph sceneGraph) { if (sceneGraph == null) { throw new ArgumentNullException("sceneGraph"); } Scene = sceneGraph; ViewFrustumPlanes = Plane.GetFrustumPlanes(Scene.ProjectionMatrix); }
public SceneGraphContext(SceneGraph sceneGraph, SceneObjectCamera currentView) { if (sceneGraph == null) { throw new ArgumentNullException("sceneGraph"); } Scene = sceneGraph; CurrentView = currentView; }
/// <summary> /// Construct a SceneGraph. /// </summary> /// <param name="otherScene"> /// The <see cref="SceneGraph"/> to be copied. /// </param> public SceneGraph(SceneGraph otherScene, SceneGraphFlags flags) : this(flags) { if (otherScene == null) { throw new ArgumentNullException("otherScene"); } CurrentView = otherScene.CurrentView; ProjectionMatrix = otherScene.ProjectionMatrix; ViewMatrix = otherScene.ViewMatrix; SceneRoot = otherScene.SceneRoot; }
/// <summary> /// Update shadow map. /// </summary> /// <param name="ctx"> /// A <see cref="GraphicsContext"/> used for allocating resources. /// </param> public virtual void UpdateShadowMap(GraphicsContext ctx, SceneGraph shadowGraph) { }