コード例 #1
0
 public void RemoveLight(PointLight light)
 {
     pointLights.Remove(light);
 }
コード例 #2
0
 public void AddLight(PointLight light)
 {
     pointLights.Add(light);
 }
コード例 #3
0
        public void DrawShadowMap(PointLight pointLight)
        {
            Matrix[] views = new Matrix[6];
            views[0] = Matrix.CreateLookAt(pointLight.Position, pointLight.Position + Vector3.Forward, Vector3.Up);
            views[1] = Matrix.CreateLookAt(pointLight.Position, pointLight.Position + Vector3.Backward, Vector3.Up);
            views[2] = Matrix.CreateLookAt(pointLight.Position, pointLight.Position + Vector3.Left, Vector3.Up);
            views[3] = Matrix.CreateLookAt(pointLight.Position, pointLight.Position + Vector3.Right, Vector3.Up);
            views[4] = Matrix.CreateLookAt(pointLight.Position, pointLight.Position + Vector3.Down, Vector3.Forward);
            views[5] = Matrix.CreateLookAt(pointLight.Position, pointLight.Position + Vector3.Up, Vector3.Backward);

            Matrix projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(90.0f), 1.0f, 1.0f, pointLight.Radius);

            depthWriter.Parameters["Projection"].SetValue(projection);
            depthWriter.Parameters["LightPosition"].SetValue(pointLight.Position);
            depthWriter.Parameters["DepthPrecision"].SetValue(pointLight.Radius);

            #region Forward
            DeferredRenderer.Instance.GraphicsDevice.SetRenderTarget(pointLight.ShadowMap, CubeMapFace.PositiveZ);

            //Clear Target
            DeferredRenderer.Instance.GraphicsDevice.Clear(Color.Transparent);

            //Set global Effect parameters
            depthWriter.Parameters["View"].SetValue(views[0]);

            //Draw Models
            DrawModels();
            #endregion

            #region Backward
            DeferredRenderer.Instance.GraphicsDevice.SetRenderTarget(pointLight.ShadowMap, CubeMapFace.NegativeZ);

            //Clear Target
            DeferredRenderer.Instance.GraphicsDevice.Clear(Color.Transparent);

            //Set global Effect parameters
            depthWriter.Parameters["View"].SetValue(views[1]);

            //Draw Models
            DrawModels();
            #endregion

            #region Left
            DeferredRenderer.Instance.GraphicsDevice.SetRenderTarget(pointLight.ShadowMap, CubeMapFace.NegativeX);

            //Clear Target
            DeferredRenderer.Instance.GraphicsDevice.Clear(Color.Transparent);

            //Set global Effect parameters
            depthWriter.Parameters["View"].SetValue(views[2]);

            //Draw Models
            DrawModels();
            #endregion

            #region Right
            DeferredRenderer.Instance.GraphicsDevice.SetRenderTarget(pointLight.ShadowMap, CubeMapFace.PositiveX);

            //Clear Target
            DeferredRenderer.Instance.GraphicsDevice.Clear(Color.Transparent);

            //Set global Effect parameters
            depthWriter.Parameters["View"].SetValue(views[3]);

            //Draw Models
            DrawModels();
            #endregion

            #region Down
            DeferredRenderer.Instance.GraphicsDevice.SetRenderTarget(pointLight.ShadowMap, CubeMapFace.NegativeY);

            //Clear Target
            DeferredRenderer.Instance.GraphicsDevice.Clear(Color.Transparent);

            //Set global Effect parameters
            depthWriter.Parameters["View"].SetValue(views[4]);

            //Draw Models
            DrawModels();
            #endregion

            #region Up
            DeferredRenderer.Instance.GraphicsDevice.SetRenderTarget(pointLight.ShadowMap, CubeMapFace.PositiveY);

            //Clear Target
            DeferredRenderer.Instance.GraphicsDevice.Clear(Color.Transparent);

            //Set global Effect parameters
            depthWriter.Parameters["View"].SetValue(views[5]);

            //Draw Models
            DrawModels();
            #endregion
        }