Fog in programs

Is there a place where one can find fixed function for fog, both for fragment and vertex program ?

Thanks,
SeskaPeel.

The specification for ARB_vertex_program and ARB_fragment_program contain samples for this in the pre-amble/discussion/issues section.

Yes I found it meanwhile by myself … sorry for this question.

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 ?

SeskaPeel.

I’m still stuck with this fog problem.
Could anyone help out a bit ?

SeskaPeel.

How about posting your program? Can’t really help you if you don’t give us more info.

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.

SeskaPeel.

Anyway … here it comes :

!!ARBfp1.0

OPTION ARB_fog_exp2 ;

MOV result.color.xyz, fragment.color ;

END

And nothing specific to the fog in the vertex program …

SeskaPeel.

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.

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
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.

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.

SeskaPeel.

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.

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.

SeskaPeel.