View Full Version : ARB_vertex_program && NVIDIA && ATI

02-10-2003, 05:28 AM

Assuming the following fog parameters :
glFogf(GL_FOG_START, 0.f);
glFogf(GL_FOG_END, 1000.f);

In the following vertex program, which path should work ?

ATTRIB iPos = vertex.position;
ATTRIB iColor = vertex.color;
PARAM mv[4] = { state.matrix.modelview };
PARAM mvp[4] = { state.matrix.mvp };
PARAM fogParam = state.fog.params;
TEMP ePos, fogTemp;
OUTPUT oPos = result.position;
OUTPUT oColor = result.color;
OUTPUT oFog = result.fogcoord;

# Transform the vertex to clip coordinates.
DP4 oPos.x, mvp[0], iPos;
DP4 oPos.y, mvp[1], iPos;
DP4 oPos.z, mvp[2], iPos;
DP4 oPos.w, mvp[3], iPos;

# Transform the vertex to eye coordinates.
DP4 ePos.x, mv[0], iPos;
DP4 ePos.y, mv[1], iPos;
DP4 ePos.z, mv[2], iPos;
DP4 ePos.w, mv[3], iPos;

# Compute linear fog. (conventions of 'c', 'e' and 's' taken from OpenGL spec)
SUB fogTemp.w, 0, ePos.z; # fogTemp.w = -ePos.z = c
SUB fogTemp.x, fogParam.z, fogTemp.w; # fogTemp.x = (e-c)
MUL fogTemp.z, fogTemp.x, fogs.w; # fogTemp.z = (e-c) * (1/(e-s))

# ATI path : set the fog coordinate in range [0,1]
MOV oFog.x, fogTemp.z;

# NV path : set the fog coordinate from eye Z (don't map to [0,1])
MOV oFog.x, ePos.z;

# Write out color directly
MOV oColor, iColor;


With NVIDIA I have to copy the eye z coordinate to result.fogcoord.x, then linear fog is computed *after* the vertex program.

With ATI I have to compute the linear fog inside the vertex program.

Any ideas ?

Tom Nuydens
02-10-2003, 07:55 AM
From ARB_vertex_program spec:
Modify Section 3.10, Fog (p. 154)

(modify second paragraph) This factor f may be computed according to one of three equations:

f = exp(-d*c),
f = exp(-(d*c)^2),
f = (e-c)/(e-s)

If vertex program mode is enabled or if the fog source (as defined below) is FOG_COORDINATE_EXT, then c is the fragment's fog coordinate. Otherwise, the c is the eye-coordinate distance from the eye, (0,0,0,1) in eye-coordinates, to the fragment center. ...

It explicitly says that the fog coordinate replaces c, and not f, so your ATI path would be the wrong one.

-- Tom

02-10-2003, 08:34 AM
Thanks alot !!

I don't know how I could miss that.