Is fog calculated per pixel, or per vertex?

In my program i use exponential fog for weather effects. I discovered, that linear fog yields to terrible results, if a poly is very big, cause the fog changes everytime one turns around.
Therefore i changed my app to use exponential fog.
I thought, that all fog types are calculated per vertex, but now i read, that it also might be per pixel.
So how is it done now?

And another thing: In my Cg vertex-shader i have to compute the fog for myself, of course. The SuperBible said, that OpenGL computes exponential fog like this:

exp ( -density * distance );

(exp has the basis e).

However i found out, that to get equal results as OpenGL, one has to do this:

exp ( density * distance) * 10;

Or is the formula totally wrong?

It´s only a minor difference, but i like to use the right formula, so that i can be sure there will be no problems in some situations.

Jan.

You should learn to look things up in the specification. It says the implementation is free to choose whether fog is calculated per fragment, or per vertex and interpolated over the primitive.

As for the formula, I don’t know really, but maybe it can be explained with that a distance is always positive, but what you think is the distance is actually the Z-coordinate of the fragment. Since the negative Z-axis is pointing into the screen, you need to multiply it by -1 to get the distance. This -1 will cancel out the minus sign in the original formula. I have no idea why you need to multiply by 10 though.

The exponentiation functionality in the programmable graphics hardware instruction sets and APIs that I am familiar with uses a base of two.

In other words, they compute 2^x instead of e^x. If you are using this functionality in your program, you obviously won’t get the results you are expecting. To compensate, you should be able to scale the density you are using by log_2(e). If you want EXP2 fog, you would want to scale by sqrt(log_2(e)) since I think the fog computation is f(z)=e(-(d*z)^2). (I’m not 100% positive about that…)

You can select an hint for fog.
Once in a while I’ve heard that GL_NICEST was meant to compute per-pixel fog and GL_FASTEST was meant to compute per-vertex fog. Though, because hint implementations are free to choose, some implementations may always compute per-vertex while some other implementations may always compute per-pixel. In other words, you never really know before you try.

Originally posted by vincoof:
You can select an hint for fog.
Once in a while I’ve heard that GL_NICEST was meant to compute per-pixel fog and GL_FASTEST was meant to compute per-vertex fog. Though, because hint implementations are free to choose, some implementations may always compute per-vertex while some other implementations may always compute per-pixel. In other words, you never really know before you try.

Do you know if hint is not implemented in RedHat- does not loook like it is- stuck with vertex fog.

Originally posted by vincoof:
You can select an hint for fog.
Once in a while I’ve heard that GL_NICEST was meant to compute per-pixel fog and GL_FASTEST was meant to compute per-vertex fog. Though, because hint implementations are free to choose, some implementations may always compute per-vertex while some other implementations may always compute per-pixel. In other words, you never really know before you try.

Is there really a RedHat OpenGL specific implementation, or do you mean MESA ?