示例#1
0
        public override void Draw(Camera3D camera)
        {
            if (firstFreeParticle == 0)
            {
                return;
            }

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

            Deferred3DEffect effect3D = ParticleHolder;

            effect3D.SetFromCamera(camera);

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

            Game1.graphicsDevice.SetVertexBuffer(vertexBuffer);
            Game1.graphicsDevice.Indices = indexBuffer;

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


                Game1.graphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0,
                                                           0, firstFreeParticle * 4,
                                                           0, firstFreeParticle * 2);
            }
        }
示例#2
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++;
        }
        public LineParticleSystem(int MaxParticles, float ParticleDuration)
        {
            self = this;
            this.MaxParticles     = MaxParticles;
            this.ParticleDuration = ParticleDuration;

            this.ParticleEffect = AssetManager.LoadEffect("Effects/ShipGame/LineParticles");
            ParticleHolder      = (Deferred3DEffect) new Deferred3DEffect().Create(ParticleEffect);

            CreateArray();
        }
示例#4
0
        public RingSystem(int MaxParticles, string TexturePath)
        {
            RingEffect   = AssetManager.LoadEffect("Effects/ShipGame/ShipRings");
            TeamParam    = RingEffect.Parameters["Team"];
            FactionParam = RingEffect.Parameters["Faction"];

            RingEffect.Parameters["Colors"].SetValue(TeamInfo.Colors3);

            ParticleHolder    = (Deferred3DEffect) new Deferred3DEffect().Create(RingEffect);
            this.MaxParticles = MaxParticles;
            CreateArray();
        }
示例#5
0
        public ShipParticleSystem(int MaxParticles, float ParticleDuration, float RotateSpeed, string TexturePath, float StartSize, float EndSize)
        {
            this.TexturePath      = TexturePath;
            this.MaxParticles     = MaxParticles;
            this.ParticleDuration = ParticleDuration;
            this.RotateSpeed      = RotateSpeed;
            this.StartSize        = StartSize;
            this.EndSize          = EndSize;

            LoadTexture();
            this.ParticleEffect = ParticleManager.ParticleEffect.Clone();
            ParticleHolder      = (Deferred3DEffect) new Deferred3DEffect().Create(ParticleEffect);

            CreateArray();
        }
示例#6
0
        public FlareSystem(int MaxParticles, int MaxPoints, string TexturePath)
        {
            this.MaxPoints = MaxPoints;
            Points         = new LightningPoint[MaxPoints];
            for (int i = 0; i < MaxPoints; i++)
            {
                Points[i] = new LightningPoint();
            }

            self              = this;
            FlareEffect       = AssetManager.LoadEffect("Effects/ShipGame/ShipFlares");
            ParticleHolder    = (Deferred3DEffect) new Deferred3DEffect().Create(FlareEffect);
            FlareTexture      = AssetManager.Load <Texture2D>("Textures/ShipGame/Particles/" + TexturePath + ParticleManager.Quality.ToString());
            this.MaxParticles = MaxParticles;
            CreateArray();
        }
示例#7
0
        public override void Draw3D(Camera3D camera, GameObjectTag DrawTag)
        {
            if (MyModel.get() != null && MyEffect.get() != null)
            {
                Deferred3DEffect effect3D = (Deferred3DEffect)MyEffect.Holder;
                switch (DrawTag)
                {
                case GameObjectTag._3DDeferredGBuffer:
                {
                    effect3D.SetWorldViewIT(camera, this);
                    effect3D.SetFromObject(this);
                    effect3D.SetFromCamera(camera);
                    effect3D.SetDeferredTechnique();
                    break;
                }

                case GameObjectTag._3DShadow:
                {
                    effect3D.SetFromObject(this);
                    effect3D.SetFromCamera(camera);
                    effect3D.SetShadowTechnique();
                    effect3D.SetLight(Transfer.LightPosition, Transfer.LightDistance);
                    break;
                }

                default:
                {
                    effect3D.SetFromCamera(camera);
                    effect3D.SetUV(camera);

                    if (!UseDeferred.get())
                    {
                        effect3D.SetFromObject(this);
                    }

                    effect3D.SetForwardTechnique();
                    break;
                }
                }

                Render.DrawModel(MyModel.get(), MyEffect.get());
            }
            base.Draw3D(camera, DrawTag);
        }
        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);
        }