fragment program: projective texture mapping

hi folks, i’d like to do a projective texture fetch within an ARB fragment program to enable a kind of shadow mapping. the texture i’m currently using is a shadow map of type GL_TEXTURE_2D. i want to compute the texture coordinates based on the fragment.position.

!!ARBfp1.0
TEMP texcoord, texcol, res;
MOV texcoord, fragment.position;

set texcoord.w to screendim.x

MOV texcoord.w, program.local[0].x;
TXP texcol, texcoord, texture[0], 2D;
SGE res, texcol, fragment.position;

res.z should be 1.0 if fragment is in light

MUL result.color, fragment.color, res.zzzz;
END

The local parameter program.local[0] contains the dimensions of the squared screen in its x coordinate which is a power of two.
the fragment program works fine, except for some scattered pixels which are lit when they shouldn’t and vice versa.
since i’m new to shader programming i believe i do a misstake somewhere but i couldn’t find out. any hints are welcome.

thanx, pinsky.