7
\$\begingroup\$

I implemented 2d fluid simulator. Solver runs entirely on GPU. All works fine... on my work PC. But on home PC I have some awful glitches, and I can`t understand how to fix them. Empirically I discovered that problem is localized somewhere in advect program. This is very strange cause at work I have integrated video, and at home — NVIDIA GeForce 9800 GT. Here is the GLSL source of advect program (some lines were dropped for clearness):

#version 130

out vec3 value;

uniform sampler2D q;
uniform sampler2D velocity;
uniform float dt;
uniform float inverseSize;

void main()
{   
  vec2 p = gl_FragCoord.xy * inverseSize; 

  vec2 np = p - dt * texture(velocity, p).xy;

  value = texture(q, np).xyz;
}

And some screenshots.

Work PC:

view of swirling colors like two or more fluids mixing

Home PC:

distorted view of similar colors, clearly in error

\$\endgroup\$
9
  • \$\begingroup\$ It looks like the visualization of a vector field and it seems ok, conceptually. Are any buffers swapped somewhere, or is this just a single simulation step? Interesting question from an interesting field, hopefully someone will answer this. To debug it, I would check if my uniforms are passed correctly: use constants/floats instead of uniforms and see the difference. \$\endgroup\$
    – teodron
    Commented Apr 21, 2012 at 9:13
  • \$\begingroup\$ This is just a single simulation step. I have a C++ function Advect(). It takes target texture, quantity texture (q) and a velocity texture. I followed your advice and tried to use consts instead of uniforms, but result is the same. \$\endgroup\$
    – iodiot
    Commented Apr 21, 2012 at 9:52
  • 2
    \$\begingroup\$ Difficult problem u got there, P = NP (joke) \$\endgroup\$ Commented Apr 24, 2012 at 6:03
  • 2
    \$\begingroup\$ @iodiot You might have invoked something bad. Integrated drivers can be more permissive than NVidia. \$\endgroup\$ Commented Feb 15, 2013 at 15:08
  • 2
    \$\begingroup\$ Could you answer the question with a before and after? I think it would be highly useful to anyone who meets this challenge in the future. \$\endgroup\$
    – AturSams
    Commented Jan 29, 2014 at 17:14

1 Answer 1

1
\$\begingroup\$

Per the OP's response, substituting

vec2 np = p - dt * texture(velocity, p).xy;

for

vec2 np = p - dt * vec2(0.01);

solved the problem. The field and density moves smoothly in the (0.01, 0.01) direction.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .