I’ve written an FBO simulation shader to simulate current flows using a vector field (curl noise). For context, if your not familiar with this setup, the logic for the simulation runs in a fragment shader and renders positional values to a texture (essentially using a texture like a data array) then rendering a separate scene with that texture as the render target so it can be fed into a vertex shader that reads the positional values and assigns them to vertex positions so they can be rendered as particles. The advantage of this over just doing the same math in the vertex shader is I can actually feed this texture back into the same simulation shader and get the last frame’s position for each particle, so I can set velocities and increment the position of particles purely based on the last frame’s position.
Everything appears to be working correctly when I use procedural values, however I would also like to do a texture lookup based on the particle position so I can have more flexibility in how I determine the velocity of each particle, and this is where I’m running into issues.
When I pass in another texture as a uniform into the simulation shader and do a texture lookup based on the particle positions, I can’t make any sense of the result I’m getting. I have a simple black texture with a green circle and when I try to set the direction of the particles equal to the value of the texture, I see some particles moving in the y direction like you would expect, but it seems to be almost totally random. There is no clear circular shape and it seems as if the texture is not being read correctly.
I know my positional values are correct, because everything I’ve hard coded seems to work just fine. For example if I say particles with positions within a certain distance of a specific position should move towards that position, all particles within that radius move towards the correct position. The texture also seems to be working fine in other shaders, and I’ve tried many different textures with the same result. There seems to be something wacky going on with the texture lookup for this shader in particular, and after playing around with this for a week or so, I’m pretty stumped. If you have any suggestions, or can see any holes in my setup that might be causing this, I would be grateful for your input. I’ve created a sandbox here illustrating the issue. Also feel free to comment out the texture lookup part to see the working curl noise.