<p>Clouds are a good fit for this but good quality cloud(s) rendering isn't usually simple. Searching for cloud rendering should give a few hits good hits. Here is neat <a href="https://www.shadertoy.com/view/3l23Rh" rel="nofollow noreferrer">shader toy rendering a cloud like tunnel</a>. But take a look at your GPU stats, ray marched clouds can be very expensive. If you search shader toy for clouds you'll find several really good examples.  Search shader toy for nebula as well. Sometimes the effects on shader toy can be adapted to rasterization.</p>
<p>Atmospheric shadowing/Volumetric lights/many other names... can be extended by sending a ray through a 3D volume to accumulate fog along that ray, combined with flow fields these techniques can create outstanding effects but it is fairly difficult to implement. (each texel of the 3D volume tends to represent large areas and aliasing becomes an important issue that has to be dealt with)</p>
<p>Next, it is possible to combine multiple effects such as halo's, planar fog, etc., to get an effect for particular scenarios.</p>
<p>If the &quot;nebula&quot; is always off in the distance (cannot be approached) then a simple quad with a partially transparent texture mapped to it can provide a nice effect.</p>
<p>There are dozens of other approach's I listed some of the most current.</p>
<p>Edit:
Searching for &quot;volumetric fog&quot; gives a lot of hits. This <a href="https://bartwronski.files.wordpress.com/2014/08/bwronski_volumetric_fog_siggraph2014.pdf" rel="nofollow noreferrer">presentation by Wronski for siggraph 2014</a> is very good. Wronski has a <a href="https://bartwronski.com/articles-blog-posts-index/#graphics" rel="nofollow noreferrer">blog</a> that is generally pretty good to read.  Techniques like this work best when all the buffers that are needed to create the effect are used by as many techniques as possible because it amortizes the cost of creating them. Cascade shadow maps in particular go with this technique well.</p>
<p><a href="https://www.evl.uic.edu/sjames/cs525/shader.html#:%7E:text=Volumetric%20fog%20enables%20the%20fog%20only%20within%20desired,here%20only%20works%20for%20static%20lighting%20and%20fogging." rel="nofollow noreferrer">Here is a link</a> to a fairly straight forward approach to generating volumetric fog. It has shaders included but is light on the math/explanation.</p>

CC BY-SA 4.0
2021-10-22T07:45:48.547Z
Thank you so much for the detailed answer. I am searching this a long time now and the only thing I have achieved is adapting shadertoy examples to quads, but I don't know in opengl how to make them take 3D space so that you can approach them and fly through them. As for the volumetric fog I've seen presentations using 3D textures which I don't understand (GPU pro6 - chapter 3)... My problem is how to render volume fog in 3D space and not in a quad with a shader?
Mike F
CC BY-SA 4.0
2021-10-22T12:27:36.060Z
I added an edit with a couple links that might be of help.
pmw1234
CC BY-SA 4.0
2021-10-21T22:00:33.480Z
2021-10-22T12:25:01.273Z
2021-10-22T12:25:01.273Z
pmw1234
<p>I have a simple question just because I can’t find any good example in the internet. How to create fog without using particles? How to make for with different density on different locations and in general how to make gaseous objects (like a nebula)? Any pointers? Thanks for reading</p>

CC BY-SA 4.0
2021-10-21T16:18:50.110Z
You use Raymarching.
joojaa
CC BY-SA 4.0
2021-10-21T16:24:46.157Z
@joojaa On a screen quad?
Mike F
<opengl><glsl>
How to render fog in OpenGL
Mike F
# How to render fog in OpenGL

(Asked by: username_0 on 2021-10-21)

I have a simple question just because I can’t find any good example in the internet. How to create fog without using particles? How to make for with different density on different locations and in general how to make gaseous objects (like a nebula)? Any pointers? Thanks for reading

**Tags:** opengl, glsl

> **Comments:**
> **username_1**: You use Raymarching.  
> **username_0**: @username_1 On a screen quad?  

---

## 1 answers

### Answer by username_2 on 2021-10-21. Score: 1 | Accepted answer

Clouds are a good fit for this but good quality cloud(s) rendering isn't usually simple. Searching for cloud rendering should give a few hits good hits. Here is neat [shader toy rendering a cloud like tunnel](https://www.shadertoy.com/view/3l23Rh). But take a look at your GPU stats, ray marched clouds can be very expensive. If you search shader toy for clouds you'll find several really good examples. Search shader toy for nebula as well. Sometimes the effects on shader toy can be adapted to rasterization.

Atmospheric shadowing/Volumetric lights/many other names... can be extended by sending a ray through a 3D volume to accumulate fog along that ray, combined with flow fields these techniques can create outstanding effects but it is fairly difficult to implement. (each texel of the 3D volume tends to represent large areas and aliasing becomes an important issue that has to be dealt with)

Next, it is possible to combine multiple effects such as halo's, planar fog, etc., to get an effect for particular scenarios.

If the "nebula" is always off in the distance (cannot be approached) then a simple quad with a partially transparent texture mapped to it can provide a nice effect.

There are dozens of other approach's I listed some of the most current.

Edit:
Searching for "volumetric fog" gives a lot of hits. This [presentation by Wronski for siggraph 2014](https://bartwronski.files.wordpress.com/2014/08/bwronski_volumetric_fog_siggraph2014.pdf) is very good. Wronski has a [blog](https://bartwronski.com/articles-blog-posts-index/#graphics) that is generally pretty good to read. Techniques like this work best when all the buffers that are needed to create the effect are used by as many techniques as possible because it amortizes the cost of creating them. Cascade shadow maps in particular go with this technique well.

[Here is a link](https://www.evl.uic.edu/sjames/cs525/shader.html#:%7E:text=Volumetric%20fog%20enables%20the%20fog%20only%20within%20desired,here%20only%20works%20for%20static%20lighting%20and%20fogging.) to a fairly straight forward approach to generating volumetric fog. It has shaders included but is light on the math/explanation.

> **Comments:**
> **username_0**: Thank you so much for the detailed answer. I am searching this a long time now and the only thing I have achieved is adapting shadertoy examples to quads, but I don't know in opengl how to make them take 3D space so that you can approach them and fly through them. As for the volumetric fog I've seen presentations using 3D textures which I don't understand (GPU pro6 - chapter 3)... My problem is how to render volume fog in 3D space and not in a quad with a shader?  
> **username_2**: I added an edit with a couple links that might be of help.  

---

