Example #1
0
        /// <summary>
        /// Updates the field by interpolating between two sampled values over the particle's lifetime
        /// </summary>
        /// <param name="pool">Target <see cref="ParticlePool"/></param>
        private unsafe void UpdateDoubleSampler(ParticlePool pool)
        {
            var colorField = pool.GetField(ParticleFields.Color);
            var lifeField  = pool.GetField(ParticleFields.Life);
            var randField  = pool.GetField(ParticleFields.RandomSeed);

            foreach (var particle in pool)
            {
                var life = 1f - (*((float *)particle[lifeField]));   // The Life field contains remaining life, so for sampling we take (1 - life)

                var randSeed = particle.Get(randField);
                var lerp     = randSeed.GetFloat(RandomOffset.Offset1A + SeedOffset);

                var colorMin = SamplerMain.Evaluate(life);
                var colorMax = SamplerOptional.Evaluate(life);
                var color    = Color4.Lerp(colorMin, colorMax, lerp);

                // Premultiply alpha
                color.R *= color.A;
                color.G *= color.A;
                color.B *= color.A;

                (*((Color4 *)particle[colorField])) = color;
            }
        }
Example #2
0
        /// <summary>
        /// Updates the field by interpolating between two sampled values over the particle's lifetime
        /// </summary>
        /// <param name="pool">Target <see cref="ParticlePool"/></param>
        private unsafe void UpdateDoubleSampler(ParticlePool pool)
        {
            var sizeField = pool.GetField(ParticleFields.Size);
            var lifeField = pool.GetField(ParticleFields.Life);
            var randField = pool.GetField(ParticleFields.RandomSeed);

            int count = pool.NextFreeIndex;

            for (int i = 0; i < count; i++)
            {
                Particle particle = pool.FromIndex(i);

                var life = 1f - (*((float *)particle[lifeField]));   // The Life field contains remaining life, so for sampling we take (1 - life)

                var randSeed = particle.Get(randField);
                var lerp     = randSeed.GetFloat(RandomOffset.Offset1A + SeedOffset);

                var size1 = SamplerMain.Evaluate(life);
                var size2 = SamplerOptional.Evaluate(life);

                if (pool.SpecificSizes != null)
                {
                    (*((float *)particle[sizeField])) = WorldScale.X * (size1 + (size2 - size1) * lerp) * pool.SpecificSizes[i];
                }
                else
                {
                    (*((float *)particle[sizeField])) = WorldScale.X * (size1 + (size2 - size1) * lerp);
                }
            }
        }
Example #3
0
        /// <summary>
        /// Updates the field by interpolating between two sampled values over the particle's lifetime
        /// </summary>
        /// <param name="pool">Target <see cref="ParticlePool"/></param>
        private unsafe void UpdateDoubleSampler(ParticlePool pool)
        {
            var colorField = pool.GetField(ParticleFields.Color);
            var lifeField  = pool.GetField(ParticleFields.Life);
            var randField  = pool.GetField(ParticleFields.RandomSeed);

            int count = pool.NextFreeIndex;

            for (int i = 0; i < count; i++)
            {
                Particle particle = pool.FromIndex(i);

                var life = 1f - (*((float *)particle[lifeField]));   // The Life field contains remaining life, so for sampling we take (1 - life)

                var randSeed = particle.Get(randField);
                var lerp     = randSeed.GetFloat(RandomOffset.Offset1A + SeedOffset);

                var colorMin = SamplerMain.Evaluate(life);
                var colorMax = SamplerOptional.Evaluate(life);
                var color    = Color4.Lerp(colorMin, colorMax, lerp);

                // preserve any colors?
                if (pool.SpecificColors != null)
                {
                    if (color.A < 0f)
                    {
                        color.A = pool.SpecificColors[i].A;
                    }
                    if (color.R < 0f)
                    {
                        color.R = pool.SpecificColors[i].R;
                    }
                    if (color.G < 0f)
                    {
                        color.G = pool.SpecificColors[i].G;
                    }
                    if (color.B < 0f)
                    {
                        color.B = pool.SpecificColors[i].B;
                    }
                }

                // Premultiply alpha
                color.R *= color.A;
                color.G *= color.A;
                color.B *= color.A;

                (*((Color4 *)particle[colorField])) = color;
            }
        }
Example #4
0
        /// <summary>
        /// Updates the field by interpolating between two sampled values over the particle's lifetime
        /// </summary>
        /// <param name="pool">Target <see cref="ParticlePool"/></param>
        private unsafe void UpdateDoubleSampler(ParticlePool pool)
        {
            var sizeField = pool.GetField(ParticleFields.Size);
            var lifeField = pool.GetField(ParticleFields.Life);
            var randField = pool.GetField(ParticleFields.RandomSeed);

            foreach (var particle in pool)
            {
                var life = 1f - (*((float *)particle[lifeField]));   // The Life field contains remaining life, so for sampling we take (1 - life)

                var randSeed = particle.Get(randField);
                var lerp     = randSeed.GetFloat(RandomOffset.Offset1A + SeedOffset);

                var size1 = SamplerMain.Evaluate(life);
                var size2 = SamplerOptional.Evaluate(life);

                (*((float *)particle[sizeField])) = WorldScale.X * (size1 + (size2 - size1) * lerp);
            }
        }
        /// <summary>
        /// Updates the field by interpolating between two sampled values over the particle's lifetime
        /// </summary>
        /// <param name="pool">Target <see cref="ParticlePool"/></param>
        private unsafe void UpdateDoubleSampler(ParticlePool pool)
        {
            var angleField = pool.GetField(ParticleFields.Angle);
            var lifeField  = pool.GetField(ParticleFields.Life);
            var randField  = pool.GetField(ParticleFields.RandomSeed);

            foreach (var particle in pool)
            {
                var life = 1f - (*((float *)particle[lifeField]));   // The Life field contains remaining life, so for sampling we take (1 - life)

                var randSeed = particle.Get(randField);
                var lerp     = randSeed.GetFloat(RandomOffset.Offset1A + SeedOffset);

                var angle1 = SamplerMain.Evaluate(life);
                var angle2 = SamplerOptional.Evaluate(life);

                (*((float *)particle[angleField])) = MathUtil.DegreesToRadians(angle1 + (angle2 - angle1) * lerp);
            }
        }