/// <summary> /// Update per frame data /// </summary> /// <param name="world">World</param> /// <param name="viewProjection">View * projection</param> /// <param name="eyePositionWorld">Eye position in world coordinates</param> /// <param name="lights">Scene ligths</param> /// <param name="shadowMapDirectional">Low definition shadow map</param> /// <param name="shadowMapPoint">Point light shadow map</param> /// <param name="shadowMapSpot">Spot light shadow map</param> private void UpdatePerFrame( Matrix world, Matrix viewProjection, Vector3 eyePositionWorld, SceneLights lights, IShadowMap shadowMapDirectional, IShadowMap shadowMapPoint, IShadowMap shadowMapSpot) { this.World = world; this.WorldViewProjection = world * viewProjection; if (lights != null) { this.EyePositionWorld = eyePositionWorld; this.HemiLight = BufferLightHemispheric.Build(lights.GetVisibleHemisphericLight()); this.DirLights = BufferLightDirectional.Build(lights.GetVisibleDirectionalLights(), out int dirLength); this.PointLights = BufferLightPoint.Build(lights.GetVisiblePointLights(), out int pointLength); this.SpotLights = BufferLightSpot.Build(lights.GetVisibleSpotLights(), out int spotLength); this.LightCount = new[] { dirLength, pointLength, spotLength }; this.FogStart = lights.FogStart; this.FogRange = lights.FogRange; this.FogColor = lights.FogColor; this.ShadowMapDirectional = shadowMapDirectional?.Texture; this.ShadowMapPoint = shadowMapPoint?.Texture; this.ShadowMapSpot = shadowMapSpot?.Texture; } else { this.EyePositionWorld = Vector3.Zero; this.HemiLight = BufferLightHemispheric.Default; this.DirLights = BufferLightDirectional.Default; this.PointLights = BufferLightPoint.Default; this.SpotLights = BufferLightSpot.Default; this.LightCount = new[] { 0, 0, 0 }; this.FogStart = 0; this.FogRange = 0; this.FogColor = Color.Transparent; this.ShadowMapDirectional = null; this.ShadowMapPoint = null; this.ShadowMapSpot = null; } }
private void LoadLights(XElement xmlScene = null) { if (xmlScene != null && xmlScene.Elements("light_list").Any()) { XElement xmlLights = xmlScene.Elements("light_list").First(); foreach (XElement xmlLight in xmlLights.Elements("light")) { Vector position = LoadXYZDouble(xmlLight.Elements("position").First()); Vector color = LoadColor(xmlLight.Elements("color").First()); XElement attenuation = xmlLight.Elements("attenuation").First(); float quadratic = LoadFloat(attenuation, "quadratic"); float linear = LoadFloat(attenuation, "linear"); float constant = LoadFloat(attenuation, "constant"); if (SceneLights.Count <= lightLimit) { Light light = new Light(position, diffuse: color, constantAttenuation: new Vector(constant, constant, constant), linearAttenuation: new Vector(linear, linear, linear), quadraticAttenuation: new Vector(quadratic, quadratic, quadratic)); SceneLights.Add(light); } } } else { Vector position = new Vector(0, 5, 0); Vector color = new Vector(1, 1, 1); float quadratic = 0; float linear = 0; float constant = 1; Light light = new Light(position, diffuse: color, constantAttenuation: new Vector(constant, constant, constant), linearAttenuation: new Vector(linear, linear, linear), quadraticAttenuation: new Vector(quadratic, quadratic, quadratic)); SceneLights.Add(light); } }
/// <summary> /// Update per frame data /// </summary> /// <param name="world">World</param> /// <param name="viewProjection">View * projection</param> /// <param name="eyePosition">Eye position</param> /// <param name="lights">State</param> public void UpdatePerFrame( Matrix viewProjection, Vector3 eyePosition, SceneLights lights, EffectWaterState state) { this.World = Matrix.Identity; this.WorldViewProjection = viewProjection; this.EyePositionWorld = eyePosition; this.BaseColor = state.BaseColor.RGB(); this.WaterColor = state.WaterColor.RGB(); this.WaveParams = new Vector4(state.WaveHeight, state.WaveChoppy, state.WaveSpeed, state.WaveFrequency); this.TotalTime = state.TotalTime; this.IterParams = new Int3(state.Steps, state.GeometryIterations, state.ColorIterations); if (lights != null) { this.DirLights = BufferLightDirectional.Build(lights.GetVisibleDirectionalLights(), out int dirLength); this.LightCount = dirLength; this.Ambient = lights.Intensity; this.FogStart = lights.FogStart; this.FogRange = lights.FogRange; this.FogColor = lights.FogColor.RGB(); } else { this.DirLights = BufferLightDirectional.Default; this.LightCount = 0; this.Ambient = 1; this.FogStart = 0; this.FogRange = 0; this.FogColor = Color.Transparent.RGB(); } }
private void Start() { //Might be a more effiecent way to do this so look back here later sceneLights = GameObject.Find("LightManager").GetComponent <SceneLights>(); }