Jump to content
  • Advertisement
Sign in to follow this  

Rendering smoke grid

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

Hello, I have implemented the stable fluids method by Stam and would now like to render the density field/grid. What I am currently doing is a simple raymarcher using some of the formulas by Nguyen for participating media. The raymarcher gives good results but needs small step sizes to do so and is therefore very slow (this is in a raytracer!). :( Does anybody know of any other techniques how to visualize the density of a fluid grid instead of raymarching? (on CPU using C++, raytracer) I am open for ANY techniques. Thank you Katachi

Share this post


Link to post
Share on other sites
Advertisement
I also have another question concerning the smoke grid. I would like to texture it, with a 2D shader, but also during raytracing. I am already using hypertextures but is there a way to feasibly derive texture coordinates for sampling 2D textures on the smoke? I am not sure, if it´s possible at all, but I would love to hear some ideas.

Thanks

Share this post


Link to post
Share on other sites
I tried to read the paper from Stam for "stable fluids". I've also digged on your Nguyen (i'm assuming its from "Physically Based Modeling and Animation of Fire").

However, it's a little over my head... too much maths :). I don't think i can help much.

Try to give a bit more of detail.
When you talk about step sizes on the raymarcher, you are talking about the steps the rays take inside the grid, or you are talking about time steps for the grids... for what i've seen, you have several grids generated, right? The problem is while visualizing the entire set of grids or while visualizing just one grid?

Share this post


Link to post
Share on other sites
Hi,

yep those are the papers I was referring too. I also haven´t fully implemented the fire formulas, I used some constants and some formulas for the temperature grid.

But for rendering I only use the density grid and march thru it. And yes, with step size, I mean stepped size within the density grid.

The problems I have is how to assign "colors". Should I simply assign them to the density or should it be done otherwise? I would like to simulate an explosion but don´t know how to assign colors for the raytraced densities the ray is passing.

Or should I rather use particles instead of the density? (though I´d love to get that density rendering working smoothly)

Any ideas? :)

Thanks so far!
Katachi

Share this post


Link to post
Share on other sites
So... you're casting rays through the grid and getting values inside the grid at each ray step, right? For actually getting the value at a given grid location you're using some sort of intepolation rule? Maybe trilinear interpolation or something close to it?

The usual way to get colors out of this is to define a "transfer function". The idea is that you give certain color values for certain possible values you can get on the grid. Whenever you get a value in a ray that doesn't fit in the values you originally gaved, you just do a simple linear interpolation to get the color for that value (so, the transfer function is piecewise linear). For this, you'll problably assign 2 or 3 colors to grid values representing fire and, based on this values, you linear interpolate the other possible values. Transfer functions usually come in pairs: one for colors and another for opacities. The one for opacities works the same way as for colors, but allows you to skipp values that you're not interested in.

Hope it helps.

Share this post


Link to post
Share on other sites
Hello Katachi

maybe it is worth for you looking at the paper "A Simple, Efficient Method for Realistic Animation of Clouds", by Dobashi et al.

They precompute the overall cloud distribution (~ might be interpreted as a density map, although it isnt, strictly speaking) and then use particles to render the clouds.

Maybe you can do a similiar thing for your smoke with the alpha value of each particle set to the density at that point in the grid. Using this technique you still have the possibility to texture your particles and to choose colors for them. Finding a good color setting for explosions might be hard, though.

I hope this was at least inspiring :-)

Best regards

Callidus

Share this post


Link to post
Share on other sites
Quote:
Original post by wolverine
So... you're casting rays through the grid and getting values inside the grid at each ray step, right? For actually getting the value at a given grid location you're using some sort of intepolation rule? Maybe trilinear interpolation or something close to it?


exactly. I am using trilinear interpolation.

Quote:
The usual way to get colors out of this is to define a "transfer function". The idea is that you give certain color values for certain possible values you can get on the grid.


yep, that´s what I am currently doing. I have a color gradient function and whenever I get a density value [0...1] I get the corresponding value from the color gradient.

Quote:
Whenever you get a value in a ray that doesn't fit in the values you originally gaved, you just do a simple linear interpolation to get the color for that value (so, the transfer function is piecewise linear). For this, you'll problably assign 2 or 3 colors to grid values representing fire and, based on this values, you linear interpolate the other possible values. Transfer functions usually come in pairs: one for colors and another for opacities. The one for opacities works the same way as for colors, but allows you to skipp values that you're not interested in.

Hope it helps.


hmm, could you specify a bit further what you mean by this? I think the transfer function is my color gradient and for opacity I have greyscale gradient. Is that what you mean?

example:

ray at pos X, density = 0.3;
Now I get the corresponding color in the color gradient and the according opacity from the greyscale gradient.

I then use this as initial radiance for the transmittance/decay calculations.
I do this for each ray step, but the result looks...*cough*...unsatisfying. :)

Thanks!
Samir

Share this post


Link to post
Share on other sites
Quote:
Original post by Callidus
Hello Katachi

maybe it is worth for you looking at the paper "A Simple, Efficient Method for Realistic Animation of Clouds", by Dobashi et al.

They precompute the overall cloud distribution (~ might be interpreted as a density map, although it isnt, strictly speaking) and then use particles to render the clouds.

Maybe you can do a similiar thing for your smoke with the alpha value of each particle set to the density at that point in the grid. Using this technique you still have the possibility to texture your particles and to choose colors for them. Finding a good color setting for explosions might be hard, though.

I hope this was at least inspiring :-)

Best regards

Callidus


Hey thanks Callidus! I will have a look at that paper. I honestly haven´t thought about using particles and use the densities for them! Will investigate. :)

Thanks
Katachi

Share this post


Link to post
Share on other sites
Quote:
Original post by Katachi

Quote:
Whenever you get a value in a ray that doesn't fit in the values you originally gaved, you just do a simple linear interpolation to get the color for that value (so, the transfer function is piecewise linear). For this, you'll problably assign 2 or 3 colors to grid values representing fire and, based on this values, you linear interpolate the other possible values. Transfer functions usually come in pairs: one for colors and another for opacities. The one for opacities works the same way as for colors, but allows you to skipp values that you're not interested in.

Hope it helps.


hmm, could you specify a bit further what you mean by this? I think the transfer function is my color gradient and for opacity I have greyscale gradient. Is that what you mean?

example:

ray at pos X, density = 0.3;
Now I get the corresponding color in the color gradient and the according opacity from the greyscale gradient.

I then use this as initial radiance for the transmittance/decay calculations.
I do this for each ray step, but the result looks...*cough*...unsatisfying. :)

Thanks!
Samir


Ok, you have a ray at position X and it gives you a value V. Usually, you take V and feed it to the transfer functions:
V_Color = transfer_function_color(V)
V_Opacity = transfer_function_opacity(V)

If, for example, you only know the color values at values V0 and V1 and if V0<V<V1 you can linearly interpolate the value for V based on the values of V0 and V1.

Perhaps you're already doing this with your gradients...

Now, V_Color and V_Opacity represent the samples' color and opacity. If you want to visualize the grid with raycasting, you'll then use front-to-back compositing:

C_out = C_in + C(x)*O(x)*(1 - O_in)
O_out = O_in + O(x)*(1 - O_in)

Where c_out and O_out are the final color and opacities for the rays' length until that particular sample. C_in and O_in are the accumulated color and opacity so far (initially, these will be 0s). C(x) and O(x) are results of the transfer functions. Applying to the example, it'll be like:

C_out = C_in + V_Color*V_Opacity*(1 - O_in)
O_out = O_in + V_Opacity*(1 - O_in)

If you ever get an accumulated opacity close to 100%, no more work needs to be done for that ray (early ray termination).

In fact, in some cases, it's very complicated to get the colors right because the final image is strongly dependent of how the data is distributed in the grid (lot's of trial and error with transfer functions).

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!