Jump to content
  • Advertisement
Sign in to follow this  
mollier

Double use of diffusion() (Jos Stams paper .... again)

This topic is 2533 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

Hi good people,

it's my first post and it's about Jos Stams' paper "Real Time Fluid Dynamics for Games".
As I have done my share of searching, i know that it has been discussed before, and I would actually like to continue a discussion that was started more than a year ago. The thread I am refering to is:

http://www.gamedev.n...m---gdc03-code/

The discussion was about eliminating the advection step and only use diffusion. If we just comment out the advective step, there is no diffusion even if there is no direct connection between the two. The discussion ended with the following comment from the OP:

" Thanks to the helpful remarks from unbird I managed to get the dyeUpdate work with zero velocity field without the advection step.


[color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif]In the original implementation the dyeUpdate function gets the buffers by value. The double swapBuffer call refreshes the original buffers correctly. But if only just one swapBuffer call is present the data isn't propagated back correctly. Using pass by reference in the dyeUpdate solves the whole misery![/font]


[color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif]It was a pretty lame mistake, thanks for all your comments! "[/font]




[font=helvetica, arial, verdana, tahoma, sans-serif][color=#282828]The comment did not help me though. What I ended up doing was calling the function diffusion() twice as follows:[/font]



[font=helvetica, arial, verdana, tahoma, sans-serif][color=#282828]
void dens_step(int N, float * x, float * x0, float diff, float dt)
{
add_source(N, x, x0, dt);
SWAP(x0, x);
diffuse(N, 0, x, x0, diff, dt);
SWAP(x0, x);
diffuse(N, 0, x, x0, diff, dt);
}
[/font]



[font=helvetica, arial, verdana, tahoma, sans-serif][color=#282828]This turns out to work just fine. I do not however have any idea why it works, and would really appreciate any thoughts on the matter.[/font]



Thanks!

Share this post


Link to post
Share on other sites
Advertisement
One thing I've noticed is that if we only have one diffusion() term, then because of the way SWAP() is used, x is always dens and so the linear solver only updates x.

Here I run through the logic:

In idle_func() we see that get_from_UI() gets dens_prev as argument. get_from_UI() fills up dens_prev according to where we click on the screen.

dens_step() then recieves dens and dens_prev. In dens_step(), add_source() updates dens according to the rule dens=dt*dens_prev.

Swap kicks in here to x=dens_prev and x0=dens. These values go into diffuse which updates x, i.e., dens_prev.

Another swap turns this into x=dens and x0=dens_prev.

If we now do not run diffuse() again, we are going to run into another swap which makes x=dens_prev and x0=dens. This is again going to be sent to diffuse() which will again update x=dens_prev. That is, it will never update x=dens, which consists of the values we draw.

That's at least where I am at today :)

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!