Exemple #1
0
        public Sun(ParameterSet parm)
        {
            if (parm.HasParm("SunColor"))
                lightColor = parm.GetVector4("SunColor");
            if (parm.HasParm("AmbientLightColor"))
                ambientLightColor = parm.GetVector4("AmbientLightColor");
            Vector2 sunAngles = Vector2.Zero;
            if (parm.HasParm("SunAngles"))
                sunAngles = parm.GetVector2("SunAngles");

            if ( shadowMap == null )
                shadowMap = new RenderTarget2D(Renderer.Instance.GraphicsDevice, SHADOW_MAP_WIDTH_HEIGHT * NUM_CASCADES, SHADOW_MAP_WIDTH_HEIGHT, false, SurfaceFormat.Single, DepthFormat.Depth24);
            SetSunDirectionFromSphericalCoords(sunAngles.X, sunAngles.Y);
        }
        public override void PostLoadInit(ParameterSet Parm)
        {
            int index = 0;

            while (Parm.HasParm("Light" + index))
            {
                string keyString = "Light" + index;
                string lightType = Parm.GetString(keyString);

                switch (lightType)
                {
                    case "Directional":
                        {
                            // read directional light parameters and create light
                            Vector3 direction = Parm.GetVector3(keyString + "Direction");
                            Vector4 color = Parm.GetVector4(keyString + "Color");
                            float intensity = Parm.GetFloat(keyString + "Intensity");
                            directionalLights.Add(new DirectionalLight(direction, color, intensity));
                        }
                        break;
                    case "Spot":
                        {
                            Vector3 position = Parm.GetVector3(keyString + "Position");
                            Vector3 direction = Parm.GetVector3(keyString + "Direction");
                            Vector4 color = Parm.GetVector4(keyString + "Color");
                            float intensity = Parm.GetFloat(keyString + "Intensity");
                            spotLights.Add(new SpotLight(DeferredRenderer.Instance.GraphicsDevice, position, direction, color, intensity, true, 1024, spotCookie));
                        }
                        break;
                    case "Point":
                        {
                            Vector3 position = Parm.GetVector3(keyString + "Position");
                            float radius = Parm.GetFloat(keyString + "Radius");
                            Vector4 color = Parm.GetVector4(keyString + "Color");
                            float intensity = Parm.GetFloat(keyString + "Intensity");
                            pointLights.Add(new PointLight(DeferredRenderer.Instance.GraphicsDevice, position, radius, color, intensity, true, 256));
                        }
                        break;
                }
                index++;
            }
        }