示例#1
0
        public Light getLight()
        {
            Light result = new Light();

            result.setColor( Color.LightGoldenrodYellow);
            result.setPower(210);
            result.setLightRadius(280);

            result.setVector(new Vector3(vector.X, vector.Y, .56f));

            return result;
        }
示例#2
0
        /// <summary>
        /// Generate a Shadow Map.
        /// </summary>
        /// <returns></returns>
        private Texture2D GenerateShadowMap()
        {
            GraphicsDevice.SetRenderTarget(_shadowMapRenderTarget);

            GraphicsDevice.Clear(ClearOptions.Target | ClearOptions.DepthBuffer, Color.Black, 1, 0);

            GraphicsDevice.BlendState = BlendState.AlphaBlend;

            //Project a light onto the player.
            List<Light> lights = new List<Light>();

            Light light1 = new Light();
            light1.setPower(60);
            light1.setLightRadius(new Random().Next(289, 300));
            light1.setColor(Color.LightGoldenrodYellow);

            light1.setVector(new Vector3(graphics.PreferredBackBufferWidth/2, graphics.PreferredBackBufferHeight/2, .56f));

            lights.Add(light1);
            lights.AddRange(Light.getLights());

            foreach(Light light in lights)
            {
                _lightEffect1.CurrentTechnique = _lightEffect1.Techniques["DeferredPointLight"];

                if(light != light1)
                {
                    if (light.getWorldPos().X + (Light.getStartVector().X) + graphics.PreferredBackBufferWidth + light.getLightRadius() < InputManager.getInstance().getCurrentPlayer().getX()) continue;
                    if (light.getWorldPos().X + (Light.getStartVector().X) - graphics.PreferredBackBufferWidth - light.getLightRadius() > InputManager.getInstance().getCurrentPlayer().getX()) continue;

                    _lightEffect1.Parameters["lightPosition"].SetValue(new Vector3(light.getWorldPos().X + (Light.getStartVector().X - InputManager.getInstance().getCurrentPlayer().getX()), light.getWorldPos().Y + (Light.getStartVector().Y - InputManager.getInstance().getCurrentPlayer().getY()), light.getWorldPos().Z));
                }
                else _lightEffect1.Parameters["lightPosition"].SetValue(light.getWorldPos());

                _lightEffect1.Parameters["lightStrength"].SetValue(light.getPower());

                _lightEffect1.Parameters["lightColor"].SetValue(light.getColor().ToVector3());
                _lightEffect1.Parameters["lightRadius"].SetValue(light.getLightRadius());

                _lightEffect1.Parameters["screenWidth"].SetValue(GraphicsDevice.Viewport.Width);
                _lightEffect1.Parameters["screenHeight"].SetValue(GraphicsDevice.Viewport.Height);

                _lightEffect1.Parameters["NormalMap"].SetValue(_normalMapTexture);
                _lightEffect1.Parameters["DepthMap"].SetValue(_depthMapTexture);

                spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.Additive);
                foreach (var pass in _lightEffect1.CurrentTechnique.Passes)
                {
                    pass.Apply();
                    GraphicsDevice.DrawUserPrimitives(PrimitiveType.TriangleStrip, _vertices, 0, 2);

                }
                spriteBatch.End();

            }

            GraphicsDevice.BlendState = BlendState.Opaque;
            GraphicsDevice.SetRenderTarget(null);

            //_colorMapTexture = _shadowMapRenderTarget;

            return _shadowMapRenderTarget;
        }