Why is OpenGL fog just not showing up?

Here's how I can enable fog in OpenGL:

float fog_colour[4] = {1,1,1,1}; glEnable(GL_FOG); glFogf(GL_FOG_MODE,GL_EXP2); glFogfv(GL_FOG_COLOR,fog_colour); glFogf(GL_FOG_DENSITY,0.5); glHint(GL_FOG_HINT,GL_NICEST); glFogf(GL_FOG_START,0.1); glFogf(GL_FOG_END,100); 

Each object is in the range of 0.1-100, but the fog just does not appear, what happened?

+4
source share
1 answer

The problem is the GL_EXP2 mode.

If you check the formula for the fog mixing coefficient in GL_EXP2 mode:

f = e ^ ((-density * z) ^ 2) (clamped to [0..1])

The fog curve is set exclusively with the density parameter. If your range is 0.1-100, I would recommend a density of around 0.001.

In any case, for fog testing it is best to start first with GL_LINEAR mode. It is just easier to visualize.

+5
source

Source: https://habr.com/ru/post/1369638/


All Articles