Beispiel #1
0
 public void RemoveLight(PointLight light)
 {
     pointLights.Remove(light);
 }
Beispiel #2
0
 public void AddLight(PointLight light)
 {
     pointLights.Add(light);
 }
Beispiel #3
0
        public void CreateShadowMap(PointLight light, List<GameObject> Models, Effect depthWriter, Terrain terrain)
        {
            Matrix[] views = new Matrix[6];

            //Creating view matrices
            views[0] = Matrix.CreateLookAt(light.position, light.position + Vector3.Forward, Vector3.Up);
            views[1] = Matrix.CreateLookAt(light.position, light.position + Vector3.Backward, Vector3.Up);
            views[2] = Matrix.CreateLookAt(light.position, light.position + Vector3.Left, Vector3.Up);
            views[3] = Matrix.CreateLookAt(light.position, light.position + Vector3.Right, Vector3.Up);
            views[4] = Matrix.CreateLookAt(light.position, light.position + Vector3.Down, Vector3.Forward);
            views[5] = Matrix.CreateLookAt(light.position, light.position + Vector3.Up, Vector3.Backward);

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

            depthWriter.Parameters["Projection"].SetValue(projection);
            depthWriter.Parameters["LightPosition"].SetValue(position);
            depthWriter.Parameters["DepthPrecision"].SetValue(radius);

            //Forward
            device.SetRenderTarget(shadowMap, CubeMapFace.PositiveZ);
            device.Clear(Color.Transparent);
            depthWriter.Parameters["View"].SetValue(views[0]);
            DrawModels(Models, depthWriter);

            //Backward
            device.SetRenderTarget(shadowMap, CubeMapFace.NegativeZ);
            device.Clear(Color.Transparent);
            depthWriter.Parameters["View"].SetValue(views[1]);
            DrawModels(Models, depthWriter);

            //Left
            device.SetRenderTarget(shadowMap, CubeMapFace.NegativeX);
            device.Clear(Color.Transparent);
            depthWriter.Parameters["View"].SetValue(views[2]);
            DrawModels(Models, depthWriter);

            //Right
            device.SetRenderTarget(shadowMap, CubeMapFace.PositiveX);
            device.Clear(Color.Transparent);
            depthWriter.Parameters["View"].SetValue(views[3]);
            DrawModels(Models, depthWriter);

            //Down
            device.SetRenderTarget(shadowMap, CubeMapFace.NegativeY);
            device.Clear(Color.Transparent);
            depthWriter.Parameters["View"].SetValue(views[4]);
            DrawModels(Models, depthWriter);

            //Up
            device.SetRenderTarget(shadowMap, CubeMapFace.PositiveY);
            device.Clear(Color.Transparent);
            depthWriter.Parameters["View"].SetValue(views[5]);
            DrawModels(Models, depthWriter);
        }