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);
        }
Beispiel #2
0
        public static void DrawEnd()
        {
            if (GPUEmitters.Count > 0)
            {
                var emitters = new MyGPUEmitter[GPUEmitters.Count];
                for (int i = 0; i < GPUEmitters.Count; i++)
                {
                    emitters[i] = GPUEmitters[i];
                }

                MyRenderProxy.UpdateGPUEmitters(emitters);

                GPUEmitters.Clear();
            }

            if (GPUEmitterTransforms.Count > 0)
            {
                var emitterUids       = new uint[GPUEmitterTransforms.Count];
                var emitterTransforms = new MatrixD[GPUEmitterTransforms.Count];
                for (int i = 0; i < GPUEmitterTransforms.Count; i++)
                {
                    emitterUids[i]       = GPUEmitterTransforms[i].GID;
                    emitterTransforms[i] = GPUEmitterTransforms[i].Transform;
                }

                MyRenderProxy.UpdateGPUEmittersTransform(emitterUids, emitterTransforms);

                GPUEmitterTransforms.Clear();
            }
        }
Beispiel #3
0
        public static void UpdateEnd()
        {
            if (GPUEmitters.Count > 0)
            {
                var emitters = new MyGPUEmitter[GPUEmitters.Count];
                for (int i = 0; i < GPUEmitters.Count; i++)
                {
                    emitters[i] = GPUEmitters[i];
                }

                MyRenderProxy.UpdateGPUEmitters(emitters);

                GPUEmitters.Clear();
            }

            if (GPUEmitterPositions.Count > 0)
            {
                var emitterUids = new uint[GPUEmitterPositions.Count];
                var emitterPos  = new Vector3D[GPUEmitterPositions.Count];
                for (int i = 0; i < GPUEmitterPositions.Count; i++)
                {
                    emitterUids[i] = GPUEmitterPositions[i].GID;
                    emitterPos[i]  = GPUEmitterPositions[i].WorldPosition;
                }

                MyRenderProxy.UpdateGPUEmittersPosition(emitterUids, emitterPos);

                GPUEmitterPositions.Clear();
            }
        }
        public void Draw(List <VRageRender.MyBillboard> collectedBillboards)
        {
            if (m_renderId == MyRenderProxy.RENDER_ID_UNASSIGNED)
            {
                m_renderId = MyRenderProxy.CreateGPUEmitter();
            }
            if (IsDirty)
            {
                MyGPUEmitter emitter = new MyGPUEmitter();
                FillData(ref emitter);
                MyParticlesManager.GPUEmitters.Add(emitter);

                m_dirty = false;
            }
            else if (m_effect.IsPositionDirty)
            {
                var transform = new MyGPUEmitterTransformUpdate()
                {
                    GID       = m_renderId,
                    Transform = CalculateWorldMatrix()
                };
                MyParticlesManager.GPUEmitterTransforms.Add(transform);

                m_positionDirty = false;
            }
        }
Beispiel #5
0
        void FillData(ref MyGPUEmitter emitter)
        {
            float time;
            MyAnimatedPropertyVector4 color;
            MyAnimatedPropertyFloat   radius;

            Color.GetKey(0, out time, out color);
            Radius.GetKey(0, out time, out radius);

            // sparks
            emitter.GID = m_renderId;
            emitter.ParticlesPerSecond = (Enabled.GetValue <bool>() && !m_effect.IsStopped) ? ParticlesPerSecond : 0;
            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);

            emitter.Data.AlphaKey1 = emitter.Data.ColorKey1;
            emitter.Data.AlphaKey2 = emitter.Data.ColorKey2;

            emitter.Data.Bounciness = Bounciness;

            emitter.Data.Velocity         = Velocity;
            emitter.Data.VelocityVariance = VelocityVar;

            emitter.Data.NumParticlesToEmitThisFrame = 0;

            emitter.Data.ParticleLifeSpan = Life;

            radius.GetKey(0, out time, out emitter.Data.Size0);
            radius.GetKey(1, out emitter.Data.SizeKeys1, out emitter.Data.Size1);
            radius.GetKey(2, out emitter.Data.SizeKeys2, out emitter.Data.Size2);
            radius.GetKey(3, out time, out emitter.Data.Size3);

            emitter.Data.PositionVariance = PositionVar;
            emitter.Data.RotationVelocity = RotationVelocity;
            emitter.Data.Acceleration     = Acceleration;
            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;

            emitter.Data.Flags = flags;

            emitter.Data.SoftParticleDistanceScale = SoftParticleDistanceScale;
            emitter.Data.AnimationFrameTime        = AnimationFrameTime;
            emitter.Data.OITWeightFactor           = OITWeightFactor;

            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    = m_effect.WorldMatrix.Translation;
        }
Beispiel #6
0
        public void Update()
        {
            if (IsDirty)
            {
                MyGPUEmitter emitter = new MyGPUEmitter();
                FillData(ref emitter);
                MyParticlesManager.GPUEmitters.Add(emitter);

                m_dirty = false;
            }
        }
        public void Draw(List <VRageRender.MyBillboard> collectedBillboards)
        {
            VRage.Profiler.ProfilerShort.Begin("GPU_Draw");
            if (m_renderId == MyRenderProxy.RENDER_ID_UNASSIGNED)
            {
                m_renderId = MyRenderProxy.CreateGPUEmitter();
            }

            if (IsDirty)
            {
                ProfilerShort.Begin("GPU_FillDataComplete");
                m_emitter = new MyGPUEmitter();
                FillDataComplete(ref m_emitter);
                MyParticlesManager.GPUEmitters.Add(m_emitter);
                ProfilerShort.End();
                m_dirty = m_animDirty = m_positionDirty = false;
            }
            else if (m_animatedTimeValues || m_animDirty)
            {
                ProfilerShort.Begin("GPU_FillData");
                FillData(ref m_emitter);
                MyParticlesManager.GPUEmitters.Add(m_emitter);
                ProfilerShort.End();
                m_animDirty = false;
            }
            else if (IsPositionDirty)
            {
                ProfilerShort.Begin("GPU_FillPosition");
                var transform = new MyGPUEmitterTransformUpdate()
                {
                    GID                = m_renderId,
                    Transform          = CalculateWorldMatrix(),
                    Scale              = m_effect.GetEmitterScale(),
                    Gravity            = m_effect.Gravity * Gravity,
                    ParticlesPerSecond = GetParticlesPerSecond()
                };
                MyParticlesManager.GPUEmitterTransforms.Add(transform);
                ProfilerShort.End();

                m_positionDirty = false;
            }
            else if (ParticlesPerSecond.GetKeysCount() > 1)
            {
                ProfilerShort.Begin("GPU_FillLight");
                MyParticlesManager.GPUEmittersLight.Add(new MyGPUEmitterLight()
                {
                    GID = m_renderId,
                    ParticlesPerSecond = GetParticlesPerSecond()
                });
                ProfilerShort.End();
            }
            ProfilerShort.End();
        }
Beispiel #8
0
        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);
        }
Beispiel #9
0
        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 FillDataComplete(ref MyGPUEmitter emitter)
        {
            float time;

            m_animatedTimeValues = Velocity.GetKeysCount() > 1 ||
                                   VelocityVar.GetKeysCount() > 1 ||
                                   DirectionCone.GetKeysCount() > 1 ||
                                   DirectionConeVar.GetKeysCount() > 1 ||
                                   EmitterSize.GetKeysCount() > 1 ||
                                   EmitterSizeMin.GetKeysCount() > 1;

            MyAnimatedPropertyVector4 color;

            Color.GetKey(0, out time, out color);
            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);

            m_currentParticlesPerSecond = GetParticlesPerSecond();
            emitter.ParticlesPerSecond  = m_show ? m_currentParticlesPerSecond : 0;

            // unmultiply colors and factor by intensity
            MyAnimatedPropertyFloat colorIntensity;
            float intensity;

            ColorIntensity.GetKey(0, out time, out colorIntensity);
            colorIntensity.GetInterpolatedValue <float>(0, out intensity);
            emitter.Data.Color0.X *= intensity;
            emitter.Data.Color0.Y *= intensity;
            emitter.Data.Color0.Z *= intensity;
            colorIntensity.GetInterpolatedValue <float>(emitter.Data.ColorKey1, out intensity);
            emitter.Data.Color1.X *= intensity;
            emitter.Data.Color1.Y *= intensity;
            emitter.Data.Color1.Z *= intensity;
            colorIntensity.GetInterpolatedValue <float>(emitter.Data.ColorKey2, out intensity);
            emitter.Data.Color2.X *= intensity;
            emitter.Data.Color2.Y *= intensity;
            emitter.Data.Color2.Z *= intensity;
            colorIntensity.GetInterpolatedValue <float>(1.0f, out intensity);
            emitter.Data.Color3.X *= intensity;
            emitter.Data.Color3.Y *= intensity;
            emitter.Data.Color3.Z *= intensity;

            emitter.Data.Color0 *= m_effect.UserColorMultiplier;
            emitter.Data.Color1 *= m_effect.UserColorMultiplier;
            emitter.Data.Color2 *= m_effect.UserColorMultiplier;
            emitter.Data.Color3 *= m_effect.UserColorMultiplier;

            MyAnimatedPropertyFloat radius;

            Radius.GetKey(0, out time, out radius);
            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;

            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;

            emitter.Data.ParticleLifeSpan = Life;

            emitter.Data.Direction = Direction;

            emitter.Data.RotationVelocity    = RotationVelocity;
            emitter.Data.RotationVelocityVar = RotationVelocityVar;

            emitter.Data.Acceleration     = Acceleration;
            emitter.Data.StreakMultiplier = StreakMultiplier;

            emitter.Data.SoftParticleDistanceScale = SoftParticleDistanceScale;
            emitter.Data.AnimationFrameTime        = AnimationFrameTime;
            emitter.Data.OITWeightFactor           = OITWeightFactor;

            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;

            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 || MyParticlesManager.Paused ? GPUEmitterFlags.FreezeSimulate : 0;
            flags |= MyParticlesManager.Paused ? GPUEmitterFlags.FreezeEmit : 0;

            emitter.Data.Flags = flags;

            emitter.GID = m_renderId;

            FillData(ref emitter);
        }
Beispiel #11
0
        public static void TestGPUParticles()
        {
            if (VRage.Input.MyInput.Static.IsAnyShiftKeyPressed())
            {
                if (gid0 == 0)
                {
                    gid0 = MyRenderProxy.CreateGPUEmitter();
                    gid1 = MyRenderProxy.CreateGPUEmitter();
                }
                var Position = MyTransparentGeometry.Camera.Translation;
                var emitters = new MyGPUEmitter[2];
                // sparks
                emitters[0].GID = gid0;
                emitters[0].ParticlesPerSecond = 30000.0f;
                emitters[0].Data.Color0        = new Vector4(1.0f, 1.0f, 0.0f, 1f);
                emitters[0].Data.Color1        = new Vector4(1.0f, 0.0f, 0.0f, 1f);
                emitters[0].Data.Color2        = new Vector4(1.0f, 0.0f, 0.0f, 0.0f);
                emitters[0].Data.ColorKey1     = 0.5f;
                emitters[0].Data.ColorKey2     = 1.0f;
                emitters[0].Data.AlphaKey1     = 0.95f;
                emitters[0].Data.AlphaKey2     = 1.0f;
                emitters[0].Data.Bounciness    = 0.4f;
                emitters[0].Data.Velocity      = new Vector3(0.0f, 0.0f, -1.0f);
                emitters[0].Data.NumParticlesToEmitThisFrame = 0;
                emitters[0].Data.ParticleLifeSpan            = 9.0f;
                emitters[0].Data.Size0                     = 0.02f;
                emitters[0].Data.Size1                     = 0.016f;
                emitters[0].Data.Size2                     = 0.0f;
                emitters[0].Data.SizeKeys1                 = 0.95f;
                emitters[0].Data.SizeKeys2                 = 1.0f;
                emitters[0].Data.PositionVariance          = new Vector3(0.1f, 0.1f, 0.1f);
                emitters[0].Data.VelocityVariance          = 0.4f;
                emitters[0].Data.RotationVelocity          = 0;
                emitters[0].Data.Acceleration              = new Vector3(0, 0, -0.98f);
                emitters[0].Data.StreakMultiplier          = 4.0f;
                emitters[0].Data.Flags                     = GPUEmitterFlags.Streaks | GPUEmitterFlags.Collide | GPUEmitterFlags.SleepState;
                emitters[0].Data.SoftParticleDistanceScale = 5;
                emitters[0].Data.AnimationFrameTime        = 1.0f;
                emitters[0].Data.OITWeightFactor           = 0.3f;
                emitters[0].AtlasTexture                   = "Textures\\Particles\\gpuAtlas0.dds";
                emitters[0].AtlasDimension                 = new Vector2I(2, 1);
                emitters[0].AtlasFrameOffset               = 1;
                emitters[0].AtlasFrameModulo               = 1;
                emitters[0].WorldPosition                  = Position + new Vector3D(8.0f, 0.0f, 8.0f);

                // smoke
                emitters[1].GID = gid1;
                emitters[1].ParticlesPerSecond = 100.0f;
                emitters[1].Data.Color0        = new Vector4(0.5f, 0.5f, 0.5f, 1.0f);
                emitters[1].Data.Color1        = new Vector4(0.6f, 0.6f, 0.65f, 1.0f);
                emitters[1].Data.Color2        = new Vector4(0.6f, 0.6f, 0.65f, 0.0f);
                emitters[1].Data.ColorKey1     = 0.5f;
                emitters[1].Data.ColorKey2     = 1.0f;
                emitters[1].Data.AlphaKey1     = 0.95f;
                emitters[1].Data.AlphaKey2     = 1.0f;
                emitters[1].Data.Velocity      = new Vector3(0, 0, 1.0f);
                emitters[1].Data.NumParticlesToEmitThisFrame = 0;
                emitters[1].Data.ParticleLifeSpan            = 150.0f;
                emitters[1].Data.Size0                     = 0.50f;
                emitters[1].Data.Size1                     = 2.2f;
                emitters[1].Data.SizeKeys1                 = 1.0f;
                emitters[1].Data.SizeKeys2                 = 1.0f;
                emitters[1].Data.PositionVariance          = new Vector3(0.2f, 0.2f, 0.2f);
                emitters[1].Data.VelocityVariance          = 0.3f;
                emitters[1].Data.RotationVelocity          = 100.0f;
                emitters[1].Data.Acceleration              = new Vector3(0.00707f, 0.00707f, -0.00003f * 9.8f);
                emitters[1].Data.Flags                     = GPUEmitterFlags.Light | GPUEmitterFlags.VolumetricLight;
                emitters[1].Data.SoftParticleDistanceScale = 2;
                emitters[1].Data.AnimationFrameTime        = 1.0f;
                emitters[1].Data.OITWeightFactor           = 1.0f;
                emitters[1].AtlasTexture                   = "Textures\\Particles\\gpuAtlas1.dds";
                emitters[1].AtlasDimension                 = new Vector2I(2, 1);
                emitters[1].AtlasFrameOffset               = 0;
                emitters[1].AtlasFrameModulo               = 1;
                emitters[1].WorldPosition                  = Position + new Vector3D(2.0f, 0.0f, 1.0f);
                MyRenderProxy.UpdateGPUEmitters(emitters);
            }
        }
Beispiel #12
0
 public static void UpdateGPUEmitters(MyGPUEmitter[] emitters)
 {
     var message = MessagePool.Get<MyRenderMessageUpdateGPUEmitters>(MyRenderMessageEnum.UpdateGPUEmitters);
     message.Emitters = emitters;
     EnqueueMessage(message);
 }
Beispiel #13
0
        internal static void UpdateData(MyGPUEmitter[] def)
        {
            for (int i = 0; i < def.Length; i++)
            {
                MyLiveData emitter;
                if (m_emitters.TryGetValue(def[i].GID, out emitter))
                {
                    MarkTextureUnused(emitter.GPUEmitter.AtlasTexture);
                    AddTexture(def[i].AtlasTexture);

                    emitter.GPUEmitter = def[i];
                    emitter.GPUEmitter.Data.TextureIndex1 = GenerateTextureIndex(emitter);
                    emitter.GPUEmitter.Data.TextureIndex2 = (uint)def[i].AtlasFrameModulo;
                    emitter.GPUEmitter.Data.RotationMatrix = Matrix.Transpose(def[i].Data.RotationMatrix);
                    if (emitter.JustAdded)
                        emitter.LastWorldPosition = emitter.GPUEmitter.WorldPosition;
                    emitter.JustAdded = false;
                }
                else MyRenderProxy.Assert(false, "invalid emitter id: " + def[i].GID);
            }
        }
        public static void DrawEnd()
        {
            if (GPUEmitters.Count > 0)
            {
                var emitters = new MyGPUEmitter[GPUEmitters.Count];
                for (int i = 0; i < GPUEmitters.Count; i++)
                {
                    emitters[i] = GPUEmitters[i];
                }

                MyRenderProxy.UpdateGPUEmitters(emitters);

                GPUEmitters.Clear();
            }

            if (GPUEmitterTransforms.Count > 0)
            {
                var emitterUids = new uint[GPUEmitterTransforms.Count];
                var emitterTransforms = new MatrixD[GPUEmitterTransforms.Count];
                for (int i = 0; i < GPUEmitterTransforms.Count; i++)
                {
                    emitterUids[i] = GPUEmitterTransforms[i].GID;
                    emitterTransforms[i] = GPUEmitterTransforms[i].Transform;
                }

                MyRenderProxy.UpdateGPUEmittersTransform(emitterUids, emitterTransforms);

                GPUEmitterTransforms.Clear();
            }
        }
        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;
        }