Jump to content
  • Advertisement
Sign in to follow this  
KKTHXBYE

[GLSL] Update velocity/density maps

This topic is 554 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement

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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!