Ejemplo n.º 1
0
        private float partial = 0.0f; // Number of particles that need to be emitted.

        public override void Update()
        {
            if (active)
            {
                // Emit new particles if needed.
                float dt = Time.GameTimeFrameSeconds;
                dt = MathHelper.Clamp(dt, 0.0f, 1.0f);  // Limit to reasonable values.

                partial += dt * emissionRate;

                // Note this is set up so that at most a single particle will be
                // emitted per Update call.  This works for the glow but may
                // not be right for other particle effects.
                if (partial >= 1.0f)
                {
                    GlowParticle particle = NewParticle(color);
                    particleList.Add(particle);

                    partial -= 1.0f;
                }

                // Update any existing particles.  For more heavyweight particles we could
                // have an Update call per particle.  These are lightweight enough that we
                // can just update them directly.
                for (int i = 0; i < particleList.Count;)
                {
                    GlowParticle particle = (GlowParticle)particleList[i];

                    particle.age += dt;

                    Debug.Assert(particle.age >= 0.0f);

                    float t = particle.age / lifetime;
                    if (t > 1.0f)
                    {
                        // Dead particle.
                        ReleaseParticle(i);
                    }
                    else
                    {
                        particle.radius = MyMath.Lerp(startRadius, endRadius, t) * scale;
                        particle.alpha  = MyMath.Lerp(startAlpha, endAlpha, t);
                        particle.alpha *= particle.alpha;

                        i++;
                    }
                }
            } // end of if active
        }     // end of GlowEmitter Update()
Ejemplo n.º 2
0
        }     // end of Emitter Render()

        private GlowParticle NewParticle(Vector4 color)
        {
            GlowParticle part = null;

            if (unused.Count > 0)
            {
                part = unused[unused.Count - 1];
                unused.RemoveAt(unused.Count - 1);
            }
            else
            {
                part = new GlowParticle();
            }
            part.color = color;
            part.age   = 0.0f;
            return(part);
        }
Ejemplo n.º 3
0
        public override void ModifyLight(int i, int j, ref float r, ref float g, ref float b)
        {
            Tile tile = Framing.GetTileSafely(i, j);

            b = 0.3f;
            r = g = (float)Math.Sin(Main.GlobalTime) * 0.2f + 0.8f;

            if (tile.frameY > 54 || Main.dayTime)
            {
                return;
            }

            if (Main.rand.NextBool(180))
            {
                GlowParticle particle = new GlowParticle(
                    new Vector2(i, j).ToWorldCoordinates() + new Vector2(40f * (Main.rand.NextBool() ? 1 : -1), 30f * (Main.rand.NextBool() ? 1 : -1)),
                    Main.rand.NextVector2Unit() * Main.rand.NextFloat(0.1f, 0.4f),
                    new Color(0.7f, 0.7f, 0.15f),
                    Main.rand.NextFloat(1f, 2f),
                    Main.rand.Next(180, 400));

                ParticleHandler.SpawnParticle(particle);
            }
        }
Ejemplo n.º 4
0
        }     // end of GlowEmitter Update()

        public override void Render(Camera camera)
        {
            if (active)
            {
                GraphicsDevice device = BokuGame.bokuGame.GraphicsDevice;
                Sphere         sphere = Sphere.GetInstance();

                // Get the effect we need.
                Effect effect = manager.Effect3d;

                // Set up common rendering values.
                effect.CurrentTechnique = manager.Technique(ParticleSystemManager.EffectTech3d.PremultAlphaGlowColorPass);

                // Set up world matrix.
                Matrix worldMatrix = Matrix.Identity;
                worldMatrix.Translation = position;

                device.Indices = sphere.Ibuf;
                device.SetVertexBuffer(sphere.Vbuf);

                if (showSolidCore)
                {
                    Matrix worldViewProjMatrix = worldMatrix * camera.ViewProjectionMatrix;

                    // Set radius.
                    manager.Parameter(ParticleSystemManager.EffectParams3d.Radius).SetValue(startRadius * scale);
                    manager.Parameter(ParticleSystemManager.EffectParams3d.WorldMatrix).SetValue(worldMatrix);
                    manager.Parameter(ParticleSystemManager.EffectParams3d.WorldViewProjMatrix).SetValue(worldViewProjMatrix);

                    // Set alpha.
                    manager.Parameter(ParticleSystemManager.EffectParams3d.Alpha).SetValue(1.0f);

                    // Set color.
                    manager.Parameter(ParticleSystemManager.EffectParams3d.DiffuseColor).SetValue(color);
                    manager.Parameter(ParticleSystemManager.EffectParams3d.EmissiveColor).SetValue(Vector4.Zero);

                    // Set glow factor.
                    manager.Parameter(ParticleSystemManager.EffectParams3d.GlowFactor).SetValue(0.1f);

                    effect.CurrentTechnique.Passes[0].Apply();

                    sphere.DrawPrim(effect);
                }

                // Set glow factor for shells.
                manager.Parameter(ParticleSystemManager.EffectParams3d.GlowFactor).SetValue(1.5f);

                for (int i = 0; i < particleList.Count; i++)
                {
                    GlowParticle particle = (GlowParticle)particleList[i];

                    Matrix worldViewProjMatrix = worldMatrix * camera.ViewProjectionMatrix;

                    // Set radius.
                    manager.Parameter(ParticleSystemManager.EffectParams3d.Radius).SetValue(particle.radius);
                    manager.Parameter(ParticleSystemManager.EffectParams3d.WorldMatrix).SetValue(worldMatrix);
                    manager.Parameter(ParticleSystemManager.EffectParams3d.WorldViewProjMatrix).SetValue(worldViewProjMatrix);

                    // Set alpha.
                    manager.Parameter(ParticleSystemManager.EffectParams3d.Alpha).SetValue(particle.alpha);

                    // Set color
                    manager.Parameter(ParticleSystemManager.EffectParams3d.DiffuseColor).SetValue(particle.color);
                    manager.Parameter(ParticleSystemManager.EffectParams3d.EmissiveColor).SetValue(Vector4.Zero);

                    effect.CurrentTechnique.Passes[0].Apply();

                    sphere.DrawPrim(effect);
                }
            } // end of if active
        }     // end of Emitter Render()