//Add a Point Light public void AddLight(PointLight Light) { pointLights.Add(Light); }
//Remove a Point Light public void RemoveLight(PointLight Light) { pointLights.Remove(Light); }
//Draw a Shadow Map for a Point Light void DrawShadowMap(GraphicsDevice GraphicsDevice, PointLight Light, List <Model> Models) { //Initialize View Matrices Array Matrix[] views = new Matrix[6]; //Create View Matrices views[0] = Matrix.CreateLookAt(Light.getPosition(), Light.getPosition() + Vector3.Forward, Vector3.Up); views[1] = Matrix.CreateLookAt(Light.getPosition(), Light.getPosition() + Vector3.Backward, Vector3.Up); views[2] = Matrix.CreateLookAt(Light.getPosition(), Light.getPosition() + Vector3.Left, Vector3.Up); views[3] = Matrix.CreateLookAt(Light.getPosition(), Light.getPosition() + Vector3.Right, Vector3.Up); views[4] = Matrix.CreateLookAt(Light.getPosition(), Light.getPosition() + Vector3.Down, Vector3.Forward); views[5] = Matrix.CreateLookAt(Light.getPosition(), Light.getPosition() + Vector3.Up, Vector3.Backward); //Create Projection Matrix Matrix projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(90.0f), 1.0f, 1.0f, Light.getRadius()); //Set Global Effect Values depthWriter.Parameters["Projection"].SetValue(projection); depthWriter.Parameters["LightPosition"].SetValue(Light.getPosition()); depthWriter.Parameters["DepthPrecision"].SetValue(Light.getRadius()); #region Forward GraphicsDevice.SetRenderTarget(Light.getShadowMap(), CubeMapFace.PositiveZ); //Clear Target GraphicsDevice.Clear(Color.Transparent); //Set global Effect parameters depthWriter.Parameters["View"].SetValue(views[0]); //Draw Models DrawModels(GraphicsDevice, Models); #endregion #region Backward GraphicsDevice.SetRenderTarget(Light.getShadowMap(), CubeMapFace.NegativeZ); //Clear Target GraphicsDevice.Clear(Color.Transparent); //Set global Effect parameters depthWriter.Parameters["View"].SetValue(views[1]); //Draw Models DrawModels(GraphicsDevice, Models); #endregion #region Left GraphicsDevice.SetRenderTarget(Light.getShadowMap(), CubeMapFace.NegativeX); //Clear Target GraphicsDevice.Clear(Color.Transparent); //Set global Effect parameters depthWriter.Parameters["View"].SetValue(views[2]); //Draw Models DrawModels(GraphicsDevice, Models); #endregion #region Right GraphicsDevice.SetRenderTarget(Light.getShadowMap(), CubeMapFace.PositiveX); //Clear Target GraphicsDevice.Clear(Color.Transparent); //Set global Effect parameters depthWriter.Parameters["View"].SetValue(views[3]); //Draw Models DrawModels(GraphicsDevice, Models); #endregion #region Down GraphicsDevice.SetRenderTarget(Light.getShadowMap(), CubeMapFace.NegativeY); //Clear Target GraphicsDevice.Clear(Color.Transparent); //Set global Effect parameters depthWriter.Parameters["View"].SetValue(views[4]); //Draw Models DrawModels(GraphicsDevice, Models); #endregion #region Up GraphicsDevice.SetRenderTarget(Light.getShadowMap(), CubeMapFace.PositiveY); //Clear Target GraphicsDevice.Clear(Color.Transparent); //Set global Effect parameters depthWriter.Parameters["View"].SetValue(views[5]); //Draw Models DrawModels(GraphicsDevice, Models); #endregion }