PDA

View Full Version : Fog in vertex program



SeskaPeel
03-03-2004, 08:20 AM
After browsing through the specs, it apperas clearly how to implement fog in fragment program, either using OPTION fog, either copying the code from the spec.

This code use the fragment.fogcoord.x param that has to be written by the vertex program ... but ... couldn't find what is the exact computation to perform ...

Code snippet from ARB_fp spec :


EXP2:
#
# 2nd-order Exponential fog
# f = exp(-(d*z)^2)
#
PARAM p = {DENSITY/SQRT(LN(2)), NOT USED, NOT USED, NOT USED};
PARAM fogColor = state.fog.color;
TEMP fogFactor;
ATTRIB fogCoord = fragment.fogcoord.x;
MUL fogFactor.x, p.x, fogCoord.x;
MUL fogFactor.x, fogFactor.x, fogFactor.x;
EX2_SAT fogFactor.x, -fogFactor.x;
LRP result.color.rgb, fogFactor.x, finalColor, fogColor;
(Note this won't compile because of the ATTRIB line).

How am I supposed to compute the fragment.fogcoord.x ? (I suppose it must differ between radial and plane distance)

Thanks,
SeskaPeel.

[This message has been edited by SeskaPeel (edited 03-03-2004).]

[This message has been edited by SeskaPeel (edited 03-03-2004).]

jra101
03-03-2004, 09:28 AM
This is the computation you need to do in the vertex program:



TEMP eye;
DP4 eye.z, state.matrix.modelview[0].row[2], vertex.position;
ABS result.fogcoord.x, eye.z;

See this thread:
http://www.opengl.org/discussion_boards/ubb/Forum3/HTML/011643.html

for more details.