/// <summary> /// Update per frame data /// </summary> /// <param name="context">Drawing context</param> /// <param name="state">State</param> public void UpdatePerFrame( DrawContext context, EffectBillboardState state) { this.World = Matrix.Identity; this.WorldViewProjection = context.ViewProjection; this.EyePositionWorld = context.EyePosition; this.StartRadius = state.StartRadius; this.EndRadius = state.EndRadius; this.TextureCount = state.TextureCount; this.NormalMapCount = state.NormalMapCount; this.Textures = state.Texture; this.NormalMaps = state.NormalMaps; this.MaterialIndex = state.MaterialIndex; var lights = context.Lights; if (lights != null) { 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 = context.ShadowMapDirectional?.Texture; this.ShadowMapPoint = context.ShadowMapPoint?.Texture; this.ShadowMapSpot = context.ShadowMapSpot?.Texture; } else { 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; } this.TextureRandom = state.RandomTexture; }
/// <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; } }
/// <summary> /// Update per frame data /// </summary> /// <param name="textureResolution">Texture resolution</param> /// <param name="context">Drawing context</param> public void UpdatePerFrame( float textureResolution, DrawContext context) { this.World = Matrix.Identity; this.WorldViewProjection = context.ViewProjection; this.TextureResolution = textureResolution; var lights = context.Lights; if (lights != null) { this.EyePositionWorld = context.EyePosition; 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 = context.ShadowMapDirectional?.Texture; this.ShadowMapPoint = context.ShadowMapPoint?.Texture; this.ShadowMapSpot = context.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; } }
/// <summary> /// Builds a light buffer collection /// </summary> /// <param name="lights">Light list</param> /// <param name="lightCount">Returns the assigned light count</param> /// <returns>Returns a light buffer collection</returns> public static BufferLightPoint[] Build(IEnumerable <SceneLightPoint> lights, out int lightCount) { if (!lights.Any()) { lightCount = 0; return(Default); } var bPointLights = Default; var point = lights.ToArray(); for (int i = 0; i < Math.Min(point.Length, MAX); i++) { bPointLights[i] = new BufferLightPoint(point[i]); } lightCount = Math.Min(point.Length, MAX); return(bPointLights); }