public void Update() { VRageRender.MyRenderProxy.GetRenderProfiler().StartProfilingBlock("ParticleLight-Update"); bool created = false; if (Enabled && m_renderObjectID == MyRenderProxy.RENDER_ID_UNASSIGNED) { InitLight(); created = true; } if (!Enabled && m_renderObjectID != MyRenderProxy.RENDER_ID_UNASSIGNED) { CloseLight(); VRageRender.MyRenderProxy.GetRenderProfiler().EndProfilingBlock(); return; } if (!Enabled) { 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; Vector3D position = Vector3D.Transform(localPosition, m_effect.WorldMatrix); if (m_position != position || created) { m_position = position; MatrixD lightMatrix = MatrixD.CreateTranslation(m_position); VRageRender.MyRenderProxy.UpdateRenderObject( m_renderObjectID, ref lightMatrix, true); } if ((m_color != color) || (m_range != range) || (m_intensity != intensity) || created) { m_color = color; m_intensity = intensity; m_range = range; VRageRender.MyRenderProxy.UpdateRenderLight( m_renderObjectID, VRageRender.LightTypeEnum.PointLight, m_position, -1, 0, m_color, m_color, 1, m_range, m_intensity, true, true, 0, false, Vector3.Zero, Vector3.Zero, 0, Vector4.Zero, 0, 0, null, 0, false, false, VRageRender.Lights.MyGlareTypeEnum.Normal, 0, 0, 0, null, 0); } VRageRender.MyRenderProxy.GetRenderProfiler().EndProfilingBlock(); }
private void CreateParticle(Vector3D interpolatedEffectPosition) { MyAnimatedParticle particle = MyTransparentGeometry.AddAnimatedParticle(); if (particle == null) { return; } particle.Type = (MyParticleTypeEnum)ParticleType.GetValue <int>(); MyUtils.AssertIsValid(m_effect.WorldMatrix); Vector3D startOffset; m_emitter.CalculateStartPosition(m_effect.GetElapsedTime(), MatrixD.CreateWorld(interpolatedEffectPosition, m_effect.WorldMatrix.Forward, m_effect.WorldMatrix.Up), m_effect.UserEmitterScale * m_effect.UserScale, out startOffset, out particle.StartPosition); Vector3D particlePosition = particle.StartPosition; m_AABB = m_AABB.Include(ref particlePosition); Life.GetInterpolatedValue <float>(m_effect.GetElapsedTime(), out particle.Life); float lifeVar = LifeVar; if (lifeVar > 0) { particle.Life = MathHelper.Max(MyUtils.GetRandomFloat(particle.Life - lifeVar, particle.Life + lifeVar), 0.1f); } Vector3 vel; Velocity.GetInterpolatedValue <Vector3>(m_effect.GetElapsedTime(), out vel); vel.X *= m_effect.UserScale; vel.Y *= m_effect.UserScale; vel.Z *= m_effect.UserScale; particle.Velocity = vel; if (VelocityDir == MyVelocityDirEnum.FromEmitterCenter) { if (!MyUtils.IsZero(startOffset - particle.StartPosition)) { float length = particle.Velocity.Length(); particle.Velocity = MyUtils.Normalize(particle.StartPosition - (Vector3D)startOffset) * length; } } particle.Velocity = Vector3D.TransformNormal(particle.Velocity, GetEffect().WorldMatrix); Angle.GetInterpolatedValue <float>(m_effect.GetElapsedTime(), out particle.Angle); float angleVar = AngleVar; if (angleVar > 0) { particle.Angle = MyUtils.GetRandomFloat(particle.Angle - AngleVar, particle.Angle + AngleVar); } RotationSpeed.GetInterpolatedValue <float>(m_effect.GetElapsedTime(), out particle.RotationSpeed); float rotationSpeedVar = RotationSpeedVar; if (rotationSpeedVar > 0) { particle.RotationSpeed = MyUtils.GetRandomFloat(particle.RotationSpeed - RotationSpeedVar, particle.RotationSpeed + RotationSpeedVar); } float radiusVar; RadiusVar.GetInterpolatedValue <float>(m_effect.GetElapsedTime(), out radiusVar); float lodRadius = 1.0f; if (GetEffect().EnableLods) { LODRadius.GetInterpolatedValue <float>(GetEffect().Distance, out lodRadius); } Radius.GetInterpolatedKeys(m_effect.GetElapsedTime(), radiusVar, (EnableCustomRadius.GetValue <bool>() ? m_effect.UserRadiusMultiplier : 1.0f) * lodRadius * GetEffect().UserScale, particle.Radius); if (particle.Type != MyParticleTypeEnum.Point) { Thickness.GetInterpolatedValue <float>(m_effect.GetElapsedTime(), out particle.Thickness); } particle.Thickness *= lodRadius; float colorVar; ColorVar.GetInterpolatedValue <float>(m_effect.GetElapsedTime(), out colorVar); Color.GetInterpolatedKeys(m_effect.GetElapsedTime(), colorVar, 1.0f, particle.Color); Material.GetInterpolatedKeys(m_effect.GetElapsedTime(), 0, 1.0f, particle.Material); particle.Flags = 0; particle.Flags |= BlendTextures.GetValue <bool>() ? MyAnimatedParticle.ParticleFlags.BlendTextures : 0; particle.Flags |= GetEffect().IsInFrustum ? MyAnimatedParticle.ParticleFlags.IsInFrustum : 0; particle.Start(this); m_particles.Add(particle); }
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(); }