I am having a small problem with the vertex shader for shadow maps as described in the Orange Book section 13.2.2

```
//attribute float Accessibility;
varying vec4 ShadowCoord;
// Ambient and diffuse scale factors.
const float As = 1.0 / 1.5;
const float Ds = 1.0 / 3.0;
void main()
{
float Accessibility = 0.0;
vec4 ecPosition = gl_ModelViewMatrix * gl_Vertex;
vec3 ecPosition3 = (vec3(ecPosition)) / ecPosition.w;
vec3 VP = vec3(gl_LightSource[0].position) - ecPosition3;
VP = normalize(VP);
vec3 normal = normalize(gl_NormalMatrix * gl_Normal);
float diffuse = max(0.0, dot(normal, VP));
float scale = min(1.0, Accessibility * As + diffuse * Ds);
vec4 texCoord = gl_TextureMatrix[1] * gl_Vertex;
ShadowCoord = texCoord / texCoord.w; //<- here
gl_FrontColor = vec4(scale * gl_Color.rgb, gl_Color.a);
gl_Position = ftransform();
}
```

This is the vertex shader as shown in the book.

It says that is is dividing this:

ShadowCoord = texCoord / texCoord.w; //<- here

to get perspective-correct projective texture coordinates and save having to do the divide on the fragment shader. however with this line left as it is, my shadows show incorrectly where as changing it to

ShadowCoord = texCoord;

makes them display correctly, albeit with plently of artifacts which is to be expected I believe.

The Fragment shader is also just as the book describes. and I construct gl_TextureMatrix[1] as

```
gl_TextureMatrix[1] = bias_matrix * light_modelview_matrix * light_projection_matrix;
```

on the application side.

is there any really obvious mistake I could be making? I checked the deLight demo’s shaders (shadow_prologue.vert/frag i believe)on which this Vertex shader was based, it also doesn’t do the division by w.

thanks for any help or suggestions.