Hi,
Assuming the following fog parameters :
glFogi(GL_FOG_MODE, GL_LINEAR);
glFogf(GL_FOG_START, 0.f);
glFogf(GL_FOG_END, 1000.f);
In the following vertex program, which path should work ?
!!ARBvp1.0
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;
END
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 ?