Projective coordinates in a vertex shader

Hi,

I got a projective texture setup with texgen, etc, made in the fixed function pipeline and was using a fragment program to do shadow mapping.
The problem is that i need to add fog to the shader, and to do so i need a vertex shader to get the fogcoords, to pass them to the fragment program.

This is my fragment program, very simple :

uniform sampler2D shadowMap;

void main ()
{

 const float fvalue = 0.5;
 vec4 color = gl_Color;
 vec4 ProjMapColor = texture2D(shadowMap,gl_TexCoord[0].st);
  
 if (ProjMapColor[3] >= 1 ) 
 {
    discard;
 }
 else	
 {
    gl_FragColor = color*fvalue;
 }

}

But in the vertex program, how can i get the texture coords into it, automatically from the texture unit ?
He should be receiving the texture coordinates generated by texgen, but somehow it’s not working, so i must be doing this wrong.
At the moment it looks like this :

void main()
{
  gl_FogFragCoord = gl_FogCoord; 
  vec4 realPos = gl_ModelViewMatrix * gl_Vertex;
  gl_TexCoord[0] = gl_TextureMatrix[0] * realPos;
  gl_Position =  ftransform();
}

I can see the projected texture moving around as i move the camera, but it’s wrongly projected.,
What am i doing wrong ?

thanks,
Bruno

vertex programs doesnt take as an input texture coordinates from texgen calls. They take values directly from the basic glTexCoord functions. You have to compute these values manualy. In GLSL you have access to uniforms gl_EyePlane and gl_ObjectPlane ( look at GLSL spec ) so it should be possible to calc them.