public void UpdateLight() { UpdateSpotParams(); if (m_propertiesDirty || m_positionDirty) { ProfilerShort.Begin("UpdateRenderLight"); m_propertiesDirty = m_positionDirty = false; MyLightLayout pointLight = new MyLightLayout() { Range = Range, Color = Color, Falloff = Falloff, GlossFactor = GlossFactor, DiffuseFactor = DiffuseFactor, }; MySpotLightLayout spotLight = new MySpotLightLayout() { Light = new MyLightLayout() { Range = ReflectorRange, Color = ReflectorColor, Falloff = ReflectorFalloff, GlossFactor = ReflectorGlossFactor, DiffuseFactor = ReflectorDiffuseFactor, }, Up = ReflectorUp, Direction = ReflectorDirection, }; MyFlareDesc glare = new MyFlareDesc() { Enabled = GlareOn, Direction = ReflectorDirection, Range = Range, Color = Color, Type = GlareType, Size = GlareSize, QuerySize = GlareQuerySize, QueryFreqMinMs = GlareQueryFreqMinMs, QueryFreqRndMs = GlareQueryFreqRndMs, Intensity = GlareIntensity, Material = MyStringId.GetOrCompute(GlareMaterial), MaxDistance = GlareMaxDistance, ParentGID = ParentID, }; UpdateRenderLightData renderLightData = new UpdateRenderLightData() { ID = RenderObjectID, Position = Position, Type = (VRageRender.LightTypeEnum)(int) LightType, ParentID = ParentID, PointPositionOffset = PointLightOffset, SpecularColor = SpecularColor, UseInForwardRender = UseInForwardRender, ReflectorConeMaxAngleCos = ReflectorConeMaxAngleCos, ShadowDistance = ShadowDistance, CastShadows = CastShadows, PointLightOn = LightOn, PointLightIntensity = Intensity, PointLight = pointLight, SpotLightOn = ReflectorOn, SpotLightIntensity = ReflectorIntensity, SpotLight = spotLight, ReflectorTexture = ReflectorTexture, Glare = glare, }; MyRenderProxy.UpdateRenderLight(ref renderLightData); ProfilerShort.End(); } }
public void Update() { VRageRender.MyRenderProxy.GetRenderProfiler().StartProfilingBlock("ParticleLight-Update"); bool created = false; if (Enabled) { if (m_renderObjectID == MyRenderProxy.RENDER_ID_UNASSIGNED) { InitLight(); created = true; } } else { if (m_renderObjectID != MyRenderProxy.RENDER_ID_UNASSIGNED) { CloseLight(); } VRageRender.MyRenderProxy.GetRenderProfiler().EndProfilingBlock(); return; } Vector3 localPosition; Position.GetInterpolatedValue(m_effect.GetElapsedTime(), out localPosition); Vector3 localPositionVar; PositionVar.GetInterpolatedValue(m_effect.GetElapsedTime(), out localPositionVar); Vector3 localPositionVarRnd = new Vector3( MyUtils.GetRandomFloat(-localPositionVar.X, localPositionVar.X), MyUtils.GetRandomFloat(-localPositionVar.Y, localPositionVar.Y), MyUtils.GetRandomFloat(-localPositionVar.Z, localPositionVar.Z)); localPosition += localPositionVarRnd; Vector4 color; Color.GetInterpolatedValue(m_effect.GetElapsedTime(), out color); float colorVar; ColorVar.GetInterpolatedValue(m_effect.GetElapsedTime(), out colorVar); float colorVarRnd = MyUtils.GetRandomFloat(1 - colorVar, 1 + colorVar); color.X = MathHelper.Clamp(color.X * colorVarRnd, 0, 1); color.Y = MathHelper.Clamp(color.Y * colorVarRnd, 0, 1); color.Z = MathHelper.Clamp(color.Z * colorVarRnd, 0, 1); float range; Range.GetInterpolatedValue(m_effect.GetElapsedTime(), out range); float rangeVar; RangeVar.GetInterpolatedValue(m_effect.GetElapsedTime(), out rangeVar); float rangeVarRnd = MyUtils.GetRandomFloat(-rangeVar, rangeVar); range += rangeVarRnd; float intensity; Intensity.GetInterpolatedValue(m_effect.GetElapsedTime(), out intensity); float intensityVar; IntensityVar.GetInterpolatedValue(m_effect.GetElapsedTime(), out intensityVar); float intensityRnd = MyUtils.GetRandomFloat(-intensityVar, intensityVar); intensity += intensityRnd; if (m_effect.IsStopped) { intensity = 0; } Vector3D position = Vector3D.Transform(localPosition * m_effect.GetEmitterScale(), m_effect.WorldMatrix); if ((m_position != position) || (m_color != color) || (m_range != range) || (m_intensity != intensity) || created) { m_color = color; m_intensity = intensity; m_range = range; m_position = position; MyLightLayout light = new MyLightLayout() { Range = m_range * m_effect.GetEmitterScale(), Color = new Vector3(m_color), Falloff = 1, GlossFactor = 1, DiffuseFactor = 1, }; UpdateRenderLightData renderLightData = new UpdateRenderLightData() { ID = m_renderObjectID, Position = m_position, Type = LightTypeEnum.PointLight, ParentID = -1, UseInForwardRender = true, SpecularColor = new Vector3(m_color), PointLightOn = true, PointLightIntensity = m_intensity, PointLight = light, }; MyRenderProxy.UpdateRenderLight(ref renderLightData); } VRageRender.MyRenderProxy.GetRenderProfiler().EndProfilingBlock(); }