protected override void LoadGraphicsContent(bool loadAllContent)
        {
            if (loadAllContent)
            {
                ContentManager cm = PrimalDevistation.Instance.CM;
                GraphicsDevice gd = GraphicsDevice;

                _renderEffect    = cm.Load <Effect>(@"Shaders/PointSpriteRender360");
                _updateEffect    = cm.Load <Effect>(@"Shaders/ParticleUpdate360");
                _particleTexture = cm.Load <Texture2D>(@"Sprites/particle2x2");

                PresentationParameters pp = GraphicsDevice.PresentationParameters;
                _bbResolveTarget = new ResolveTexture2D(GraphicsDevice, pp.BackBufferWidth, pp.BackBufferHeight, 1, pp.BackBufferFormat);

                // Create the sprite batch for render to textures
                _batch = new cSpriteBatch(gd);

                // Setting up some shader vars that will never change now
                _renderEffect.Parameters["View"].SetValue(Matrix.Identity);
                _renderEffect.Parameters["World"].SetValue(Matrix.Identity);

                _colors = new Texture2D(gd, _textureWidth, _textureHeight, 1, TextureUsage.None, SurfaceFormat.Color);

                _velocities    = new RenderTarget2D[2];
                _positions     = new RenderTarget2D[2];
                _ages          = new RenderTarget2D[2];
                _positions[0]  = new RenderTarget2D(gd, _textureWidth, _textureHeight, 1, SurfaceFormat.Vector2);
                _positions[1]  = new RenderTarget2D(gd, _textureWidth, _textureHeight, 1, SurfaceFormat.Vector2);
                _velocities[0] = new RenderTarget2D(gd, _textureWidth, _textureHeight, 1, SurfaceFormat.Vector2);
                _velocities[1] = new RenderTarget2D(gd, _textureWidth, _textureHeight, 1, SurfaceFormat.Vector2);
                _ages[0]       = new RenderTarget2D(gd, _textureWidth, _textureHeight, 1, SurfaceFormat.Single);
                _ages[1]       = new RenderTarget2D(gd, _textureWidth, _textureHeight, 1, SurfaceFormat.Single);

                gd.SetRenderTarget(0, _positions[0]);
                gd.Clear(ClearOptions.Target, new Color(0, 0, 0, 0), 1.0f, 0);
                gd.SetRenderTarget(0, _positions[1]);
                gd.Clear(ClearOptions.Target, new Color(0, 0, 0, 0), 1.0f, 0);
                gd.SetRenderTarget(0, _velocities[0]);
                gd.Clear(ClearOptions.Target, Color.Black, 1.0f, 0);
                gd.SetRenderTarget(0, _velocities[1]);
                gd.Clear(ClearOptions.Target, Color.Black, 1.0f, 0);
                gd.SetRenderTarget(0, _ages[0]);
                gd.Clear(ClearOptions.Target, Color.Black, 1.0f, 0);
                gd.SetRenderTarget(0, _ages[1]);
                gd.Clear(ClearOptions.Target, Color.Black, 1.0f, 0);
                gd.SetRenderTarget(0, null);


                //Vector2[] data = new Vector2[_maxParticles];
                //_positions[0].GetTexture().GetData<Vector2>(data);
                //Vector2 s = LieroXNA.Instance.Level.Size;
                //for (int i = 0; i < data.Length; i++) { data[i] = new Vector2(cMath.Rand(0, s.X / 2), cMath.Rand(0, s.Y / 2)); }
                //_positions[0].GetTexture().SetData<Vector2>(data);
                //_positions[1].GetTexture().SetData<Vector2>(data);

                Texture2D[] particleTextures = new Texture2D[10];

                string part = @"Sprites/particles/part04";

                //particleTextures[0] = cm.Load<Texture2D>(part);
                //particleTextures[1] = cm.Load<Texture2D>(part);
                //particleTextures[2] = cm.Load<Texture2D>(part);
                //particleTextures[3] = cm.Load<Texture2D>(part);
                //particleTextures[4] = cm.Load<Texture2D>(part);
                //particleTextures[5] = cm.Load<Texture2D>(part);
                //particleTextures[6] = cm.Load<Texture2D>(part);
                //particleTextures[7] = cm.Load<Texture2D>(part);
                //particleTextures[8] = cm.Load<Texture2D>(part);
                //particleTextures[9] = cm.Load<Texture2D>(part);

                particleTextures[0] = cm.Load <Texture2D>(@"Sprites/particles/part01");
                particleTextures[1] = cm.Load <Texture2D>(@"Sprites/particles/part02");
                particleTextures[2] = cm.Load <Texture2D>(@"Sprites/particles/part03");
                particleTextures[3] = cm.Load <Texture2D>(@"Sprites/particles/part04");
                particleTextures[4] = cm.Load <Texture2D>(@"Sprites/particles/part05");
                particleTextures[5] = cm.Load <Texture2D>(@"Sprites/particles/part06");
                particleTextures[6] = cm.Load <Texture2D>(@"Sprites/particles/part07");
                particleTextures[7] = cm.Load <Texture2D>(@"Sprites/particles/part08");
                particleTextures[8] = cm.Load <Texture2D>(@"Sprites/particles/part09");
                particleTextures[9] = cm.Load <Texture2D>(@"Sprites/particles/part10");

                for (int i = 0; i < particleTextures.Length; i++)
                {
                    _renderEffect.Parameters["ParticleTex" + i].SetValue(particleTextures[i]);
                }


                _verts = new sVTPointVertex[_maxParticles];
                _dec   = new VertexDeclaration(gd, sVTPointVertex.Elements);

                float ratioW = 1f / (_textureWidth - 1);
                float ratioH = 1f / (_textureHeight - 1);

                int icounter = 0;
                for (int i = 0; i < _textureWidth; i++)
                {
                    for (int j = 0; j < _textureHeight; j++)
                    {
                        _verts[icounter]           = new sVTPointVertex();
                        _verts[icounter].texture   = new Vector2(i * ratioW, j * ratioH);
                        _verts[icounter].texIndex  = cMath.Rand(0, particleTextures.Length - 1);
                        _verts[icounter].pointSize = particleTextures[(int)_verts[icounter].texIndex].Width;
                        icounter++;
                    }
                }

                _vertexBuffer = new VertexBuffer(gd, sVTPointVertex.Size * _maxParticles, BufferUsage.Points);
                _vertexBuffer.SetData(_verts);
            }
        }
Exemple #2
0
        //private void SetPSize(string[] args)
        //{
        //    if (args.Length <= 0) { LieroXNA.Instance.LieroConsole.AddLine("USAGE: 'psize [size]'"); return; }
        //    int res;
        //    if (!int.TryParse(args[0], out res)) { LieroXNA.Instance.LieroConsole.AddLine("Size is not a valid integer"); return; }
        //    _particleSize = res;
        //}

        protected override void LoadGraphicsContent(bool loadAllContent)
        {
            if (loadAllContent)
            {
                ContentManager cm = PrimalDevistation.Instance.CM;
                GraphicsDevice gd = GraphicsDevice;

                _renderEffect = cm.Load <Effect>(@"Shaders/PointSpriteRenderVT");
                if (_useMRT)
                {
                    _updateEffect = cm.Load <Effect>(@"Shaders/ParticleUpdateMRT");
                }
                else
                {
                    _updateEffect = cm.Load <Effect>(@"Shaders/ParticleUpdate");
                }
                _particleTexture = cm.Load <Texture2D>(@"Sprites/particle2x2");

                PresentationParameters pp = GraphicsDevice.PresentationParameters;
                _bbResolveTarget = new ResolveTexture2D(GraphicsDevice, pp.BackBufferWidth, pp.BackBufferHeight, 1, pp.BackBufferFormat);

                // Create the sprite batch for render to textures
                _batch = new cSpriteBatch(gd);

                // Setting up some shader vars that will never change now
                _renderEffect.Parameters["View"].SetValue(Matrix.Identity);
                _renderEffect.Parameters["World"].SetValue(Matrix.Identity);

                _velocities = new RenderTarget2D[2];
                _positions  = new RenderTarget2D[2];

                if (_useHV4)
                {
                    _positions[0]  = new RenderTarget2D(gd, _textureWidth, _textureHeight, 1, SurfaceFormat.HalfVector4);
                    _positions[1]  = new RenderTarget2D(gd, _textureWidth, _textureHeight, 1, SurfaceFormat.HalfVector4);
                    _velocities[0] = new RenderTarget2D(gd, _textureWidth, _textureHeight, 1, SurfaceFormat.HalfVector4);
                    _velocities[1] = new RenderTarget2D(gd, _textureWidth, _textureHeight, 1, SurfaceFormat.HalfVector4);
                }
                else
                {
                    _positions[0]  = new RenderTarget2D(gd, _textureWidth, _textureHeight, 1, SurfaceFormat.Vector4);
                    _positions[1]  = new RenderTarget2D(gd, _textureWidth, _textureHeight, 1, SurfaceFormat.Vector4);
                    _velocities[0] = new RenderTarget2D(gd, _textureWidth, _textureHeight, 1, SurfaceFormat.Vector4);
                    _velocities[1] = new RenderTarget2D(gd, _textureWidth, _textureHeight, 1, SurfaceFormat.Vector4);
                }

                gd.SetRenderTarget(0, _positions[0]);
                gd.Clear(ClearOptions.Target, Color.Black, 1.0f, 0);

                gd.SetRenderTarget(0, _positions[1]);
                gd.Clear(ClearOptions.Target, Color.Black, 1.0f, 0);

                gd.SetRenderTarget(0, _velocities[0]);
                gd.Clear(ClearOptions.Target, Color.Black, 1.0f, 0);

                gd.SetRenderTarget(0, _velocities[1]);
                gd.Clear(ClearOptions.Target, Color.Black, 1.0f, 0);
                gd.SetRenderTarget(0, null);

                if (_useHV4)
                {
                    HalfVector4[] data = new HalfVector4[_maxParticles];
                    _positions[0].GetTexture().GetData <HalfVector4>(data);
                    Vector2 s = PrimalDevistation.Instance.Level.Size;
#if XBOX
                    for (int i = 0; i < data.Length; i++)
                    {
                        data[i] = new HalfVector4(0, 0, cMath.Rand(0, s.Y / 2), cMath.Rand(0, s.X / 2));
                    }
#else
                    for (int i = 0; i < data.Length; i++)
                    {
                        data[i] = new HalfVector4(cMath.Rand(0, s.X / 2), cMath.Rand(0, s.Y / 2), 0, 0);
                    }
#endif

                    _positions[0].GetTexture().SetData <HalfVector4>(data);
                    _positions[1].GetTexture().SetData <HalfVector4>(data);
                }
                else
                {
                    Vector4[] data = new Vector4[_maxParticles];
                    _positions[0].GetTexture().GetData <Vector4>(data);
                    for (int i = 0; i < data.Length; i++)
                    {
                        data[i] = new Vector4(0, 0, 0, 0);
                    }
                    _positions[0].GetTexture().SetData <Vector4>(data);
                    _positions[1].GetTexture().SetData <Vector4>(data);
                }

                _verts = new sVTPointVertex[_maxParticles];
                _dec   = new VertexDeclaration(gd, sVTPointVertex.Elements);

                float ratioW = 1f / (_textureWidth - 1);
                float ratioH = 1f / (_textureHeight - 1);

                int icounter = 0;
                for (int i = 0; i < _textureWidth; i++)
                {
                    for (int j = 0; j < _textureHeight; j++)
                    {
                        _verts[icounter]           = new sVTPointVertex();
                        _verts[icounter].texture   = new Vector2(i * ratioW, j * ratioH);
                        _verts[icounter].pointSize = cMath.Rand(1, 3);
                        icounter++;
                    }
                }

                // Create a dynamic vertex buffer.
                ResourceUsage usage = ResourceUsage.Dynamic | ResourceUsage.WriteOnly | ResourceUsage.Points;

                _vertexBuffer = new VertexBuffer(gd, sVTPointVertex.Size * _maxParticles, usage, ResourceManagementMode.Manual);
                _vertexBuffer.SetData(_verts);
            }
        }