예제 #1
0
        /// <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));
        }
예제 #2
0
        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);
        }
예제 #3
0
        public SceneGraphContext(SceneGraph sceneGraph) : this(sceneGraph, null)
        {
            if (sceneGraph == null)
            {
                throw new ArgumentNullException("sceneGraph");
            }

            Scene = sceneGraph;
        }
예제 #4
0
 /// <summary>
 /// Static constructor.
 /// </summary>
 static SceneObject()
 {
     // Static initialization
     SceneGraph.Touch();
     SceneObjectCamera.Touch();
     SceneObjectGeometry.Touch();
     SceneObjectLight.Touch();
     SceneObjectLightZone.Touch();
 }
예제 #5
0
        public SceneGraphContext(SceneGraph sceneGraph)
        {
            if (sceneGraph == null)
            {
                throw new ArgumentNullException("sceneGraph");
            }

            Scene             = sceneGraph;
            ViewFrustumPlanes = Plane.GetFrustumPlanes(Scene.ProjectionMatrix);
        }
예제 #6
0
        public SceneGraphContext(SceneGraph sceneGraph, SceneObjectCamera currentView)
        {
            if (sceneGraph == null)
            {
                throw new ArgumentNullException("sceneGraph");
            }

            Scene       = sceneGraph;
            CurrentView = currentView;
        }
예제 #7
0
        /// <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;
        }
예제 #8
0
 /// <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)
 {
 }