开发者

Why OpenGL fog just doesn't appear?

开发者 https://www.devze.com 2023-04-01 12:35 出处:网络
This is how I enable fog in OpenGL: float fog_colour[4] = {1,1,1,1}; glEnable(GL_FOG); glFogf(GL_FOG_MODE,GL_EXP2);

This is how I 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);
gl开发者_如何学运维Hint(GL_FOG_HINT,GL_NICEST);
glFogf(GL_FOG_START,0.1);
glFogf(GL_FOG_END,100);

Every object is in the range 0.1-100, but fog just doesn't appear, what happened?


The problem is the GL_EXP2 mode.

If you check the formula for the fog blending factor in GL_EXP2 mode:

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

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

Anyway, for testing fog is better to begin first with a GL_LINEAR mode. It's just easier to visualize.

0

精彩评论

暂无评论...
验证码 换一张
取 消