Exemplo n.º 1
0
        private void Init(AdvancedParticleSystemSettings Settings, ContentManager Content, GraphicsDevice GraphicsDevice)
        {
            this.Settings = Settings;
            UseAlphaBlend = false;

            // Allocate the particle array, and fill in the corner fields (which never change).
            ArrayParticles = new AdvancedParticleVertex[Settings.MaxParticles * 4];
            for (int i = 0; i < Settings.MaxParticles; i++)
            {
                ArrayParticles[i * 4 + 0].UV = new Vector2(0, 0);
                ArrayParticles[i * 4 + 1].UV = new Vector2(1, 0);
                ArrayParticles[i * 4 + 2].UV = new Vector2(1, 1);
                ArrayParticles[i * 4 + 3].UV = new Vector2(0, 1);
            }
            Effect effect = Content.Load <Effect>("Shaders/Advanced Particle shader 3D");

            // If we have several particle systems, the content manager will return
            // a single shared effect instance to them all. But we want to preconfigure
            // the effect with parameters that are specific to this particular
            // particle system. By cloning the effect, we prevent one particle system
            // from stomping over the parameter settings of another.
            ParticleEffect = effect.Clone();
            Parameters     = ParticleEffect.Parameters;
            // Look up shortcuts for parameters that change every frame.
            EffectViewParameter          = Parameters["View"];
            EffectProjectionParameter    = Parameters["Projection"];
            EffectViewportScaleParameter = Parameters["ViewportScale"];
            EffectTimeParameter          = Parameters["CurrentTime"];
            // Set the values of parameters that do not change.
            Parameters["NumberOfImages"].SetValue(Settings.NumberOfImages);
            // Load the particle texture, and set it onto the effect.
            Texture2D sprBackground = Content.Load <Texture2D>(Settings.TextureName);

            this.ParticleSize = new Vector2((sprBackground.Width / Settings.NumberOfImages) * 0.5f, sprBackground.Height * 0.5f);
            Parameters["Size"].SetValue(ParticleSize);
            Parameters["t0"].SetValue(sprBackground);
            Parameters["t1"].SetValue(Settings.GetTexture(GraphicsDevice));

            // Create a dynamic vertex buffer.
            VertexBuffer = new DynamicVertexBuffer(GraphicsDevice, ParticleVertex.VertexDeclaration,
                                                   Settings.MaxParticles * 4, BufferUsage.WriteOnly);
            // Create and populate the index buffer.
            ushort[] ArrayIndex = new ushort[Settings.MaxParticles * 6];
            for (int i = 0; i < Settings.MaxParticles; i++)
            {
                ArrayIndex[i * 6 + 0] = (ushort)(i * 4 + 0);
                ArrayIndex[i * 6 + 1] = (ushort)(i * 4 + 1);
                ArrayIndex[i * 6 + 2] = (ushort)(i * 4 + 2);
                ArrayIndex[i * 6 + 3] = (ushort)(i * 4 + 0);
                ArrayIndex[i * 6 + 4] = (ushort)(i * 4 + 2);
                ArrayIndex[i * 6 + 5] = (ushort)(i * 4 + 3);
            }

            IndexBuffer = new IndexBuffer(GraphicsDevice, typeof(ushort), ArrayIndex.Length, BufferUsage.WriteOnly);
            IndexBuffer.SetData(ArrayIndex);
        }
Exemplo n.º 2
0
        public AdvancedParticleSystem(string TextureName, int MaxParticles, int NumberOfImages, BlendState BlendState, bool RotateTowardCamera, ContentManager Content, GraphicsDevice GraphicsDevice)
        {
            AdvancedParticleSystemSettings NewParticleSystemSettings = new AdvancedParticleSystemSettings(TextureName, MaxParticles, NumberOfImages, BlendState, RotateTowardCamera);

            Init(NewParticleSystemSettings, Content, GraphicsDevice);
        }