OpenGL/GLSL: What is the best algorithm to render clouds/smoke out of volumetric data?

StackOverflow https://stackoverflow.com/questions/2591956

  •  25-09-2019
  •  | 
  •  

Question

I would like to render the 3D volume data: Density(can be mapped to Alpha channel), Temperature(can be mapped to RGB). Currently I am simulationg maximum intensity projection, eg: rendering the most dense/opaque pixel in the end.But this method looses the depth perception.

I would like to imitate the effect like a fire inside the smoke.

So my question is what is the techniques in OpenGL to generate images based on available data?

Any idea is welcome.

Thanks Arman.

Was it helpful?

Solution

I would try a volume ray caster first.

You can google "Volume Visualization With Ray Casting" and that should give you most of what you need. NVidia has a great sample (using openg) of ray casting through a 3D texture.

On your specific implementation, you would just need to keep stepping through the volume accumlating the temperature until you reach the wanted density.

If your volume doesn't fit in video memory, you can do the ray casting in pieces and then do a composition step.

A quick description of ray casting:

CPU: 1) Render a six sided cube in world space as the drawing primitive make sure to use depth culling.

Vertex shader: 2) In the vertex shader store off the world position of the vertices (this will interpolate per fragmet)

Fragment shader: 3) Use the interpolated position minus the camera position to get the vector of traversal through the volume. 4) Use a while loop to step through the volume from the point on the cube through the other side. 3 ways to know when to end. A) at each step test if the point is still in the cube. B) do a ray intersection with cube and calculate the distance between the intersections. C) do a prerender of the cube with forward face culling and store the depths into a second texture map then just sampe at the screen pixel to get the distance.

5) accumulate while you loop and set the pixel color.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top