private void FillData(ref MyGPUEmitter emitter) { MatrixD mat = CalculateWorldMatrix(); emitter.Data.RotationMatrix = mat; emitter.WorldPosition = mat.Translation; emitter.Data.Scale = m_effect.GetEmitterScale(); emitter.Data.Gravity = m_effect.Gravity * Gravity; var rotMat = CalculateParticleRotation(mat); emitter.Data.ParticleRotationRow0 = rotMat.Right; emitter.Data.ParticleRotationRow1 = rotMat.Up; emitter.Data.ParticleRotationRow2 = rotMat.Backward; emitter.ParticlesPerSecond = m_currentParticlesPerSecond = GetParticlesPerSecond(); if (ParticlesPerFrame.GetKeysCount() > 0) { float keyTime, diff; ParticlesPerFrame.GetNextValue(m_effect.GetElapsedTime() - VRage.Game.MyEngineConstants.UPDATE_STEP_SIZE_IN_SECONDS, out emitter.ParticlesPerFrame, out keyTime, out diff); if (keyTime < (m_effect.GetElapsedTime() - VRage.Game.MyEngineConstants.UPDATE_STEP_SIZE_IN_SECONDS) || keyTime >= m_effect.GetElapsedTime()) { emitter.ParticlesPerFrame = 0; } else { emitter.ParticlesPerFrame *= m_effect.UserBirthMultiplier; } } Velocity.GetInterpolatedValue <float>(m_effect.GetElapsedTime(), out emitter.Data.Velocity); VelocityVar.GetInterpolatedValue <float>(m_effect.GetElapsedTime(), out emitter.Data.VelocityVar); float cone; DirectionInnerCone.GetInterpolatedValue <float>(m_effect.GetElapsedTime(), out cone); emitter.Data.DirectionInnerCone = cone;// MathHelper.ToRadians(cone); DirectionConeVar.GetInterpolatedValue <float>(m_effect.GetElapsedTime(), out cone); emitter.Data.DirectionConeVar = MathHelper.ToRadians(cone); EmitterSize.GetInterpolatedValue <Vector3>(m_effect.GetElapsedTime(), out emitter.Data.EmitterSize); EmitterSizeMin.GetInterpolatedValue <float>(m_effect.GetElapsedTime(), out emitter.Data.EmitterSizeMin); }
void FillData(ref MyGPUEmitter emitter) { MatrixD mat = CalculateWorldMatrix(); emitter.Data.RotationMatrix = mat; emitter.WorldPosition = mat.Translation; emitter.Data.Scale = m_effect.GetEmitterScale(); emitter.Data.Gravity = m_effect.Gravity * Gravity; emitter.ParticlesPerSecond = GetParticlesPerSecond(); Velocity.GetInterpolatedValue <float>(m_effect.GetElapsedTime(), out emitter.Data.Velocity); VelocityVar.GetInterpolatedValue <float>(m_effect.GetElapsedTime(), out emitter.Data.VelocityVar); float cone; DirectionCone.GetInterpolatedValue <float>(m_effect.GetElapsedTime(), out cone); emitter.Data.DirectionCone = MathHelper.ToRadians(cone); DirectionConeVar.GetInterpolatedValue <float>(m_effect.GetElapsedTime(), out cone); emitter.Data.DirectionConeVar = MathHelper.ToRadians(cone); EmitterSize.GetInterpolatedValue <Vector3>(m_effect.GetElapsedTime(), out emitter.Data.EmitterSize); EmitterSizeMin.GetInterpolatedValue <float>(m_effect.GetElapsedTime(), out emitter.Data.EmitterSizeMin); }
public void Update() { VRageRender.MyRenderProxy.GetRenderProfiler().StartProfilingBlock("ParticleSound-Update"); if (Enabled) { Range.GetInterpolatedValue(m_effect.GetElapsedTime() / m_effect.Length, out m_range); Volume.GetInterpolatedValue(m_effect.GetElapsedTime() / m_effect.Length, out m_volume); m_position = (Vector3)m_effect.WorldMatrix.Translation; } if (!Enabled) { VRageRender.MyRenderProxy.GetRenderProfiler().EndProfilingBlock(); return; } VRageRender.MyRenderProxy.GetRenderProfiler().EndProfilingBlock(); }
private void FillData(ref MyGPUEmitter emitter) { MatrixD mat = CalculateWorldMatrix(); emitter.Data.RotationMatrix = mat; emitter.WorldPosition = mat.Translation; emitter.Data.Scale = m_effect.GetEmitterScale(); emitter.Data.Gravity = m_effect.Gravity * Gravity; Vector3 angle = Angle; Vector3 angleVar = AngleVar; if (angleVar.LengthSquared() > 0) { angle = new Vector3( MyUtils.GetRandomFloat(angle.X - angleVar.X, angle.X + angleVar.X), MyUtils.GetRandomFloat(angle.Y - angleVar.Y, angle.Y + angleVar.Y), MyUtils.GetRandomFloat(angle.Z - angleVar.Z, angle.Z + angleVar.Z)); } Matrix rot; if (angle.LengthSquared() > 0) { rot = Matrix.CreateFromAxisAngle(mat.Right, MathHelper.ToRadians(angle.X)) * Matrix.CreateFromAxisAngle(mat.Up, MathHelper.ToRadians(angle.Y)) * Matrix.CreateFromAxisAngle(mat.Forward, MathHelper.ToRadians(angle.Z)); } else { rot = mat; } emitter.Data.ParticleRotationRow0 = rot.Right; emitter.Data.ParticleRotationRow1 = rot.Up; emitter.Data.ParticleRotationRow2 = rot.Backward; emitter.ParticlesPerSecond = m_currentParticlesPerSecond = GetParticlesPerSecond(); Velocity.GetInterpolatedValue <float>(m_effect.GetElapsedTime(), out emitter.Data.Velocity); VelocityVar.GetInterpolatedValue <float>(m_effect.GetElapsedTime(), out emitter.Data.VelocityVar); float cone; DirectionInnerCone.GetInterpolatedValue <float>(m_effect.GetElapsedTime(), out cone); emitter.Data.DirectionInnerCone = cone;// MathHelper.ToRadians(cone); DirectionConeVar.GetInterpolatedValue <float>(m_effect.GetElapsedTime(), out cone); emitter.Data.DirectionConeVar = MathHelper.ToRadians(cone); EmitterSize.GetInterpolatedValue <Vector3>(m_effect.GetElapsedTime(), out emitter.Data.EmitterSize); EmitterSizeMin.GetInterpolatedValue <float>(m_effect.GetElapsedTime(), out emitter.Data.EmitterSizeMin); }
private void UpdateParticlesLife() { int counter = 0; VRageRender.MyRenderProxy.GetRenderProfiler().StartProfilingBlock("ParticleGeneration-UpdateParticlesLife"); MyParticleGeneration inheritedGeneration = null; Vector3D previousParticlePosition = m_effect.WorldMatrix.Translation; float particlesToCreate = 0; m_AABB = BoundingBoxD.CreateInvalid(); m_AABB = m_AABB.Include(ref previousParticlePosition); if (OnDie.GetValue <int>() != -1) { inheritedGeneration = GetInheritedGeneration(OnDie.GetValue <int>()); if (inheritedGeneration == null) { OnDie.SetValue(-1); } else { inheritedGeneration.IsInherited = true; particlesToCreate = inheritedGeneration.m_particlesToCreate; } } VRageRender.MyRenderProxy.GetRenderProfiler().EndProfilingBlock(); VRageRender.MyRenderProxy.GetRenderProfiler().StartProfilingBlock("ParticleGeneration-Update01"); Vector3D previousTrail0 = previousParticlePosition; Vector3D previousTrail1 = previousParticlePosition; using (ParticlesLock.AcquireExclusiveUsing()) { while (counter < m_particles.Count) { float motionInheritance; MotionInheritance.GetInterpolatedValue(m_effect.GetElapsedTime(), out motionInheritance); MyAnimatedParticle particle = m_particles[counter]; if (motionInheritance > 0) { m_effect.CalculateDeltaMatrix = true; } if (particle.Update()) { if (motionInheritance > 0) { var delta = m_effect.GetDeltaMatrix(); particle.AddMotionInheritance(ref motionInheritance, ref delta); } if (counter == 0) { previousParticlePosition = particle.ActualPosition; previousTrail0 = particle.Quad.Point1; previousTrail1 = particle.Quad.Point2; particle.Quad.Point0 = particle.ActualPosition; particle.Quad.Point2 = particle.ActualPosition; } counter++; if (particle.Type == MyParticleTypeEnum.Trail) { if (particle.ActualPosition == previousParticlePosition) { particle.Quad.Point0 = particle.ActualPosition; particle.Quad.Point1 = particle.ActualPosition; particle.Quad.Point2 = particle.ActualPosition; particle.Quad.Point3 = particle.ActualPosition; } else { MyPolyLineD polyLine = new MyPolyLineD(); polyLine.Thickness = particle.Thickness; polyLine.Point0 = particle.ActualPosition; polyLine.Point1 = previousParticlePosition; Vector3D direction = polyLine.Point1 - polyLine.Point0; Vector3D normalizedDirection = MyUtils.Normalize(polyLine.Point1 - polyLine.Point0); polyLine.LineDirectionNormalized = normalizedDirection; var camPos = MyTransparentGeometry.Camera.Translation; MyUtils.GetPolyLineQuad(out particle.Quad, ref polyLine, camPos); particle.Quad.Point0 = previousTrail0 + direction * 0.15f; particle.Quad.Point3 = previousTrail1 + direction * 0.15f; previousTrail0 = particle.Quad.Point1; previousTrail1 = particle.Quad.Point2; } } previousParticlePosition = particle.ActualPosition; m_AABB = m_AABB.Include(ref previousParticlePosition); continue; } if (inheritedGeneration != null) { inheritedGeneration.m_particlesToCreate = particlesToCreate; inheritedGeneration.EffectMatrix = MatrixD.CreateWorld(particle.ActualPosition, Vector3D.Normalize(particle.Velocity), Vector3D.Cross(Vector3D.Left, particle.Velocity)); inheritedGeneration.UpdateParticlesCreation(); } m_particles.Remove(particle); MyTransparentGeometry.DeallocateAnimatedParticle(particle); } } VRageRender.MyRenderProxy.GetRenderProfiler().EndProfilingBlock(); }
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(); }
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(); }
void FillData(ref MyGPUEmitter emitter) { float time; MyAnimatedPropertyVector4 color; MyAnimatedPropertyFloat radius; MyAnimatedPropertyFloat colorIntensity; Color.GetKey(0, out time, out color); Radius.GetKey(0, out time, out radius); ColorIntensity.GetKey(0, out time, out colorIntensity); emitter.GID = m_renderId; if (Enabled.GetValue <bool>() && !m_effect.IsEmittingStopped) { ParticlesPerSecond.GetInterpolatedValue <float>(m_effect.GetElapsedTime(), out emitter.ParticlesPerSecond); emitter.ParticlesPerSecond *= m_effect.UserBirthMultiplier; } else { emitter.ParticlesPerSecond = 0; } float intensity; color.GetKey(0, out time, out emitter.Data.Color0); color.GetKey(1, out emitter.Data.ColorKey1, out emitter.Data.Color1); color.GetKey(2, out emitter.Data.ColorKey2, out emitter.Data.Color2); color.GetKey(3, out time, out emitter.Data.Color3); // unmultiply colors and factor by intensity colorIntensity.GetInterpolatedValue <float>(0, out intensity); emitter.Data.Color0.X *= intensity; emitter.Data.Color0.Y *= intensity; emitter.Data.Color0.Z *= intensity; emitter.Data.Color0 *= m_effect.UserColorMultiplier; colorIntensity.GetInterpolatedValue <float>(emitter.Data.ColorKey1, out intensity); emitter.Data.Color1.X *= intensity; emitter.Data.Color1.Y *= intensity; emitter.Data.Color1.Z *= intensity; emitter.Data.Color1 *= m_effect.UserColorMultiplier; colorIntensity.GetInterpolatedValue <float>(emitter.Data.ColorKey2, out intensity); emitter.Data.Color2.X *= intensity; emitter.Data.Color2.Y *= intensity; emitter.Data.Color2.Z *= intensity; emitter.Data.Color2 *= m_effect.UserColorMultiplier; colorIntensity.GetInterpolatedValue <float>(1.0f, out intensity); emitter.Data.Color3.X *= intensity; emitter.Data.Color3.Y *= intensity; emitter.Data.Color3.Z *= intensity; emitter.Data.Color3 *= m_effect.UserColorMultiplier; emitter.Data.ColorVar = ColorVar; if (emitter.Data.ColorVar > 1.0f) { emitter.Data.ColorVar = 1.0f; } else if (emitter.Data.ColorVar < 0) { emitter.Data.ColorVar = 0; } emitter.Data.HueVar = HueVar; if (emitter.Data.HueVar > 1.0f) { emitter.Data.HueVar = 1.0f; } else if (emitter.Data.HueVar < 0) { emitter.Data.HueVar = 0; } emitter.Data.Bounciness = Bounciness; MatrixD mat = CalculateWorldMatrix(); emitter.Data.RotationMatrix = mat; emitter.Data.Direction = Direction; Velocity.GetInterpolatedValue <float>(m_effect.GetElapsedTime(), out emitter.Data.Velocity); VelocityVar.GetInterpolatedValue <float>(m_effect.GetElapsedTime(), out emitter.Data.VelocityVar); float cone; DirectionCone.GetInterpolatedValue <float>(m_effect.GetElapsedTime(), out cone); emitter.Data.DirectionCone = MathHelper.ToRadians(cone); DirectionConeVar.GetInterpolatedValue <float>(m_effect.GetElapsedTime(), out cone); emitter.Data.DirectionConeVar = MathHelper.ToRadians(cone); emitter.Data.NumParticlesToEmitThisFrame = 0; emitter.Data.ParticleLifeSpan = Life; radius.GetKey(0, out time, out emitter.Data.ParticleSize0); radius.GetKey(1, out emitter.Data.ParticleSizeKeys1, out emitter.Data.ParticleSize1); radius.GetKey(2, out emitter.Data.ParticleSizeKeys2, out emitter.Data.ParticleSize2); radius.GetKey(3, out time, out emitter.Data.ParticleSize3); emitter.Data.ParticleSize0 *= m_effect.UserRadiusMultiplier; emitter.Data.ParticleSize1 *= m_effect.UserRadiusMultiplier; emitter.Data.ParticleSize2 *= m_effect.UserRadiusMultiplier; emitter.Data.ParticleSize3 *= m_effect.UserRadiusMultiplier; EmitterSize.GetInterpolatedValue <Vector3>(m_effect.GetElapsedTime(), out emitter.Data.EmitterSize); EmitterSizeMin.GetInterpolatedValue <float>(m_effect.GetElapsedTime(), out emitter.Data.EmitterSizeMin); emitter.Data.RotationVelocity = RotationVelocity; emitter.Data.RotationVelocityVar = RotationVelocityVar; emitter.Data.Acceleration = Acceleration; emitter.Data.Gravity = m_effect.Gravity * Gravity; emitter.Data.StreakMultiplier = StreakMultiplier; GPUEmitterFlags flags = 0; flags |= Streaks ? GPUEmitterFlags.Streaks : 0; flags |= Collide ? GPUEmitterFlags.Collide : 0; flags |= SleepState ? GPUEmitterFlags.SleepState : 0; flags |= Light ? GPUEmitterFlags.Light : 0; flags |= VolumetricLight ? GPUEmitterFlags.VolumetricLight : 0; flags |= m_effect.IsSimulationPaused ? GPUEmitterFlags.FreezeSimulate : 0; emitter.Data.Flags = flags; emitter.Data.SoftParticleDistanceScale = SoftParticleDistanceScale; emitter.Data.AnimationFrameTime = AnimationFrameTime; emitter.Data.OITWeightFactor = OITWeightFactor; emitter.Data.Scale = m_effect.GetEmitterScale(); emitter.AtlasTexture = (Material.GetValue <MyTransparentMaterial>()).Texture; emitter.AtlasDimension = new Vector2I((int)ArraySize.GetValue <Vector3>().X, (int)ArraySize.GetValue <Vector3>().Y); emitter.AtlasFrameOffset = ArrayOffset; emitter.AtlasFrameModulo = ArrayModulo; emitter.WorldPosition = mat.Translation; }