Esempio n. 1
0
        public override void Draw(Camera3D camera)
        {
            if (vertexBuffer.IsContentLost)
            {
                vertexBuffer.SetData(particles);
            }

            if (firstNewParticle != firstFreeParticle)
            {
                AddNewParticlesToVertexBuffer();
            }

            if (firstActiveParticle != firstFreeParticle)
            {
                Deferred3DEffect effect3D = ParticleHolder;
                effect3D.SetFromCamera(camera);

                Game1.graphicsDevice.BlendState        = BlendState.Additive;
                Game1.graphicsDevice.DepthStencilState = DepthStencilState.DepthRead;

                effect3D.SetTextureSize(new Vector2(0.5f / Game1.graphicsDevice.Viewport.AspectRatio, -0.5f));
                effect3D.SetTime(Level.Time);
                Game1.graphicsDevice.SetVertexBuffer(vertexBuffer);
                Game1.graphicsDevice.Indices = indexBuffer;

                // Activate the particle effect.
                foreach (EffectPass pass in ParticleEffect.CurrentTechnique.Passes)
                {
                    pass.Apply();

                    if (firstActiveParticle < firstFreeParticle)
                    {
                        // If the active particles are all in one consecutive range,
                        // we can draw them all in a single call.
                        Game1.graphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0,
                                                                   firstActiveParticle * 4, (firstFreeParticle - firstActiveParticle) * 4,
                                                                   firstActiveParticle * 6, (firstFreeParticle - firstActiveParticle) * 2);
                    }
                    else
                    {
                        // If the active particle range wraps past the end of the queue
                        // back to the start, we must split them over two draw calls.
                        Game1.graphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0,
                                                                   firstActiveParticle * 4, (MaxParticles - firstActiveParticle) * 4,
                                                                   firstActiveParticle * 6, (MaxParticles - firstActiveParticle) * 2);

                        if (firstFreeParticle > 0)
                        {
                            Game1.graphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0,
                                                                       0, firstFreeParticle * 4,
                                                                       0, firstFreeParticle * 2);
                        }
                    }
                }
            }

            drawCounter++;
        }
Esempio n. 2
0
        public override void Draw(Camera3D camera)
        {
            if (firstFreeParticle == 0)
            {
                return;
            }

            if (vertexBuffer.IsContentLost || !BufferReady)
            {
                BufferReady = true;
                vertexBuffer.SetData(0, particles, 0, firstFreeParticle * 4, FlareVertex.SizeInBytes, SetDataOptions.Discard);
            }

            Deferred3DEffect effect3D = ParticleHolder;

            effect3D.SetFromCamera(camera);

            Game1.graphicsDevice.BlendState        = BlendState.Additive;
            Game1.graphicsDevice.DepthStencilState = DepthStencilState.DepthRead;

            effect3D.SetTextureSize(new Vector2(0.5f / Game1.graphicsDevice.Viewport.AspectRatio, -0.5f));
            effect3D.SetTime(Level.Time);
            Game1.graphicsDevice.SetVertexBuffer(vertexBuffer);
            Game1.graphicsDevice.Indices = indexBuffer;

            // Activate the particle effect.
            foreach (EffectPass pass in FlareEffect.CurrentTechnique.Passes)
            {
                pass.Apply();


                Game1.graphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0,
                                                           0, firstFreeParticle * 4,
                                                           0, firstFreeParticle * 2);
            }
        }
        public override void  Draw3D(Camera3D camera, GameObjectTag DrawTag)
        {
            if (MyEffect.get() == null)
                return;
            GraphicsDevice device = Game1.graphicsDevice;

            // Restore the vertex buffer contents if the graphics device was lost.
            if (vertexBuffer.IsContentLost)
            {
                vertexBuffer.SetData(particles);
            }

            if (NeedDurationChange && DurationParameter != null && ParticleDuration != null)
            {
                DurationParameter.SetValue(ParticleDuration.get());
                NeedDurationChange = false;
            }

            // If there are any particles waiting in the newly added queue,
            // we'd better upload them to the GPU ready for drawing.
            if (firstNewParticle != firstFreeParticle)
            {
                AddNewParticlesToVertexBuffer();
            }

            // If there are any active particles, draw them now!
            if (firstActiveParticle != firstFreeParticle)
            {
                Deferred3DEffect effect3D = (Deferred3DEffect)MyEffect.Holder;
                effect3D.SetFromCamera(camera);

                device.BlendState = Additive.get() ? BlendState.Additive : BlendState.AlphaBlend;
                device.DepthStencilState = UseDepth.get() ? DepthStencilState.DepthRead : DepthStencilState.None;

                effect3D.SetTextureSize(new Vector2(0.5f / device.Viewport.AspectRatio, -0.5f));
                effect3D.SetTime(Level.Time);
                device.SetVertexBuffer(vertexBuffer);
                device.Indices = indexBuffer;

                // Activate the particle effect.
                foreach (EffectPass pass in MyEffect.get().CurrentTechnique.Passes)
                {
                    pass.Apply();

                    if (firstActiveParticle < firstFreeParticle)
                    {
                        // If the active particles are all in one consecutive range,
                        // we can draw them all in a single call.
                        device.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0,
                                                     firstActiveParticle * 4, (firstFreeParticle - firstActiveParticle) * 4,
                                                     firstActiveParticle * 6, (firstFreeParticle - firstActiveParticle) * 2);
                    }
                    else
                    {
                        // If the active particle range wraps past the end of the queue
                        // back to the start, we must split them over two draw calls.
                        device.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0,
                                                     firstActiveParticle * 4, ((int)MaxParticles.get() - firstActiveParticle) * 4,
                                                     firstActiveParticle * 6, ((int)MaxParticles.get() - firstActiveParticle) * 2);

                        if (firstFreeParticle > 0)
                        {
                            device.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0,
                                                         0, firstFreeParticle * 4,
                                                         0, firstFreeParticle * 2);
                        }
                    }
                }
            }

            drawCounter++;
            base.Draw3D(camera, DrawTag);
        }