Fog with GL_ARB_fragment_program

I’m just full of questions today

I’m trying to get linear fog to work in a fragment program on the 9700.

In the spec, it recommends doing something like this:

    #
    # Linear fog
    # f = (end-z)/(end-start)
    #
    PARAM p = {-1/(END-START), END/(END-START), NOT USED, NOT USED};
    PARAM fogColor = state.fog.color;
    TEMP fogFactor;
    ATTRIB fogCoord = fragment.fogcoord.x;
    MAD fogFactor.x, p.x, fogCoord.x, p.y;
    LRP result.color, fogFactor.x, finalColor, fogColor;

Unfortunately, of course, this won’t work because of the illegal way that they define p. I changed it to something like this:

  "TEMP p;"
  "TEMP fogFactor;"
  "PARAM fogParms = state.fog.params;"
  "PARAM fogColor = state.fog.color;"
  "ATTRIB fogCoord = fragment.fogcoord;"

  "MOV p, -fogParms.w;"
  "MUL p.y, p, -fogParms.z"
  "MAD fogFactor.x, p.x, fogCoord.x, p.y;"
  "LRP result.color, fogFactor.x, temp, fogColor;"

But this program won’t compile. It gives an “Invalid component” error at fogParms.z. I don’t get it. state.fog.params is defined like this:

state.fog.params (d,s,e,r) fog density, linear start
and end, and 1/(end-start)
(section 3.11)

so it seems to me that the z component should be ok. Any ideas?

Thanks again,
– Zeno

  "TEMP p;"
  "TEMP fogFactor;"
  "PARAM fogParms = state.fog.params;"
  "PARAM fogColor = state.fog.color;"
  "ATTRIB fogCoord = fragment.fogcoord;"

  "MOV p, -fogParms.w;"
  "MUL p.y, p, -fogParms.z"
  "MAD fogFactor.x, p.x, fogCoord.x, p.y;"
  "LRP result.color, fogFactor.x, temp, fogColor;"

Is the missing semicolon after “-fogParms.z” an typing error copying your code to your post?

If not, that’s probably it…

– Ben

[edit: formatting]

[This message has been edited by bashbaug (edited 01-16-2003).]

Yep, that was it. I’m embarrased to say how long I spent looking for this problem. Worked perfect as soon as I added the semi-colon.

Thanks a bunch.
– Zeno

P.S. Is there any way to cut down the instructions on this?

[This message has been edited by Zeno (edited 01-16-2003).]