Sign in to follow this  

[GLSL] Update velocity/density maps

Recommended Posts

I have two 512x512 fields where one stores velocity vector and second stores denisty

 

now i want to update each frame based on velocity vecttor on each cell in the field.

 

problem is its for ogl 2.0

and i cant write to multiple textures in one shader. moreover i would like to somehow be able to write into different pixel (defined by some x,y), because i need somehow to update velocity field and what when i need to move one position two pixels right but i cant coz im using pixel shader. 

 

i hope someone understands me

Share this post


Link to post
Share on other sites
Posted (edited)

1. What format are your textures. Is it possible to pack them together into different channels? (off the top of my head velocity + density is only 3 for 2D, and 4 for 4D?)

2. Don't think in terms of where you're writing, think of where you're reading (gather vs scatter). If you want to write 2 pixels to the right, then sample two pixels to the left (oversimplified but I hope that gets the point across). Pixel shaders are always in "local space", i.e. they define the write position, so you need to work backwards from that.

3. If you can't directly store the data in a single texture, you can try various packing techniques. You can attempt to squeeze data down so that it does fit into channels, you can try atlasing the textures, or you can do it in multiple passes if it's a fast enough computation.

 

It would also help if we knew what you were using these for (particle physics? fluid sims?) as we can suggest a few things within context of what you're doing.

Edited by Styves

Share this post


Link to post
Share on other sites

Use one texture with R and G channels as your XY velocity, and the B channel as the density?

 

As for writing to a specific place on the texture, you're going to want to render-to-texture, and in the pixel shader generate what you want for each pixel of that new texture. In this case I would double-buffer, where one texture I am reading from in the shader to generate my output from, and then the output is to a texture of the same size. At the end of the frame, I just swap their roles, so that the texture I was just writing (drawing) to is now the input texture and the other texture I was reading from is now the destination.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this