示例#1
0
 public void Generate(SpriteBatch sp, Texture2D pressure, Texture2D friction)
 {
     velocity.Parameters["FrictionMap"].SetValue(friction);
     velocity.Parameters["HeightMap"].SetValue(pressure);
     rts = new RenderTargetState(graphics, Game1.TextureWidth, Game1.TextureHeight, Game1.TextureWidth, Game1.TextureHeight);
     rts.BeginRenderToTexture();
     sp.Begin(SpriteBlendMode.None, SpriteSortMode.Immediate, SaveStateMode.None);
     velocity.Begin();
     velocity.CurrentTechnique.Passes[0].Begin();
     sp.Draw(pressure, new Vector2(0, 0), Microsoft.Xna.Framework.Graphics.Color.White);
     sp.End();
     velocity.CurrentTechnique.Passes[0].End();
     velocity.End();
     texture = rts.EndRenderGetTexture();
 }
示例#2
0
 public void Load(GraphicsDevice graf, ContentManager cont)
 {
     heatmap = cont.Load<Effect>("Shaders\\Heatmap");
     rts = new RenderTargetState(graf, Game1.TextureWidth, Game1.TextureHeight, Game1.TextureWidth, Game1.TextureHeight);
 }
示例#3
0
文件: Flow.cs 项目: pentiumx/HLSLTest
        public void Load(GraphicsDevice graf, ContentManager cont)
        {
            mover = cont.Load<Effect>("Shaders\\FluidFlow");
            rts = new RenderTargetState(graf, Game1.TextureWidth, Game1.TextureHeight, Game1.TextureWidth, Game1.TextureHeight);
            rts2 = new RenderTargetState(graf, Game1.TextureWidth, Game1.TextureHeight, Game1.TextureWidth, Game1.TextureHeight);
            rts3 = new RenderTargetState(graf, Game1.TextureWidth, Game1.TextureHeight, Game1.TextureWidth, Game1.TextureHeight);
            rts4 = new RenderTargetState(graf, Game1.TextureWidth, Game1.TextureHeight, Game1.TextureWidth, Game1.TextureHeight);
            rts5 = new RenderTargetState(graf, Game1.TextureWidth, Game1.TextureHeight, Game1.TextureWidth, Game1.TextureHeight);

            mover.Parameters["timestep"].SetValue(0.2f);
            mover.Parameters["dissipation"].SetValue(1);
            mover.Parameters["rdx"].SetValue(1.0f / Game1.TextureWidth);
            mover.Parameters["halfrdx"].SetValue(0.5f / Game1.TextureWidth);

            Color[] map = new Color[Game1.TextureHeight * Game1.TextureWidth];
            Velocity = new Texture2D(graf, Game1.TextureWidth, Game1.TextureHeight, 1, TextureUsage.None, SurfaceFormat.Color);
            Velocity.SetData<Color>(map);
            Vorticity = new Texture2D(graf, Game1.TextureWidth, Game1.TextureHeight, 1, TextureUsage.None, SurfaceFormat.Color);
            Vorticity.SetData<Color>(map);
            Divergence = new Texture2D(graf, Game1.TextureWidth, Game1.TextureHeight, 1, TextureUsage.None, SurfaceFormat.Color);
            Divergence.SetData<Color>(map);

            for (int i = 0; i < Game1.TextureHeight; i++)
            {
                for (int j = 0; j < Game1.TextureWidth; j++)
                {
                    map[i + (j * Game1.TextureWidth)] = new Color(128, 128, 128, 1);
                }
            }
            PressureOffsets = new Texture2D(graf, Game1.TextureWidth, Game1.TextureHeight, 1, TextureUsage.None, SurfaceFormat.Color);
            PressureOffsets.SetData<Color>(map);
            Density = new Texture2D(graf, Game1.TextureWidth, Game1.TextureHeight, 1, TextureUsage.None, SurfaceFormat.Color);
            Density.SetData<Color>(map);
        }
示例#4
0
        public RenderTargetState SetToDevice(int renderTargetIndex)
        {
            oldState = new RenderTargetState(GraphicsDevice,
                                             renderTargetIndex);

            //GraphicsDevice.SetRenderTarget(renderTargetIndex,  RenderTarget);
            GraphicsDevice.SetRenderTarget(RenderTarget);
            //GraphicsDevice.DepthStencilBuffer = DepthBuffer;

            return oldState;
        }
示例#5
0
        public RenderTargetState EndRenderToTexture(int renderTargetIndex)
        {
            RenderTargetState renderBuffer =
                    oldState.SetToDevice(renderTargetIndex);

            oldState = null;

            return renderBuffer;
        }
示例#6
0
        public Texture2D EndRenderGetTexture(int renderTargetIndex)
        {
            RenderTargetState renderBuffer =
                    oldState.SetToDevice(renderTargetIndex);

            oldState = null;

            //return renderBuffer.RenderTarget.GetTexture();
            return renderBuffer.RenderTarget;
        }
示例#7
0
        public void DestroyBuffers()
        {
            oldState = null;

            if (CreatedBuffers) {
                if (RenderTarget != null) {
                    RenderTarget.Dispose();
                    RenderTarget = null;
                }
                /*if (DepthBuffer != null) {
                    DepthBuffer.Dispose();
                    DepthBuffer = null;
                }*/
            }
        }
示例#8
0
        public RenderTargetState BeginRenderToTexture(int renderTargetIndex)
        {
            oldState = SetToDevice(renderTargetIndex);

            return oldState;
        }
示例#9
0
        public RenderTargetState BeginRenderToTexture()
        {
            oldState = SetToDevice();

            return oldState;
        }