View Full Version : Fog in programs

09-04-2003, 11:20 AM
Is there a place where one can find fixed function for fog, both for fragment and vertex program ?


09-04-2003, 02:38 PM
The specification for ARB_vertex_program and ARB_fragment_program contain samples for this in the pre-amble/discussion/issues section.

09-04-2003, 02:48 PM
Yes I found it meanwhile by myself ... sorry for this question.

09-05-2003, 06:07 AM
Well, actually, I can't get myself out of the mess ...

In the fragment spec, it talks about an option that does everything for you, namely ARB_fog_exp2, as I intend to use exp˛ fog.
I correctly set fog with standard gl functions (works well in the fixed function), but no fog through the fragment program.

Am I supposed to implement something in the vertex program ?


09-09-2003, 04:25 AM
I'm still stuck with this fog problem.
Could anyone help out a bit ?


09-09-2003, 09:03 AM
How about posting your program? Can't really help you if you don't give us more info.

09-09-2003, 09:05 AM
PK, actually it's not program specific ...

I simply want to do exp˛ fog in all my pairs of vertex/fragment programs. I must have missed something.


09-09-2003, 10:08 AM
Anyway ... here it comes :


OPTION ARB_fog_exp2 ;

MOV result.color.xyz, fragment.color ;


And nothing specific to the fog in the vertex program ...


09-09-2003, 10:45 AM
I think in the vertex program you have to calculate and output the fogcoord (result.fogcoord). I'm not entirely sure on this, though. . . I do all my fog calculations manually.

The way I do it is I calculate the distance of the vertex from the viewpoint and toss it into result.fogcoord. I read that in the fragment shader and use it as the distance input for whatever for system I'm using.

09-10-2003, 07:40 AM
You don't need a vertex program for fog coords. I use EXT_fog_coord to pass fog weights per vertex (w/o VP) and it works just fine http://www.opengl.org/discussion_boards/ubb/smile.gif
Fog must be enabled, too.

I haven't tried using these fog options, but the correct fog coord gets into the fragment program, where you can use a lrp (prescale to fog range if desired) to get linear fog.

09-10-2003, 08:06 AM
The problem is I already have a pair of program running.
So I want to *add* to those programs classic gl fog.

Did not have time to try to set result.fogcoord in vertex program, I'll prolly try this tonight.


09-10-2003, 03:30 PM
I don`t think you need to make use of EXT_fog_coord.
Just using standard GL fogging and including ARB_fog_exp2 like you did should do it.

09-11-2003, 01:20 AM
Made it work ...
I had to compute eye - vertex distance in the vertex program, and output it to result.fogcoord.x.
I did it this way :

ATTRIB inPosition = vertex.position ;
PARAM mv[4] = { state.matrix.modelview } ;
DP4 result.fogcoord.x, mv[2], inPosition ;

Using "OPTION ARB_fog_exp2 ;" in fragment program correctly interpolates fragment color without having to implement anything.