# Spotlights texture calculations in vertex programs

Hi guys!
I use this example to simulate per-pixel lights http://users.ox.ac.uk/~univ1234/opengl/ppatten/ppatten.htm
Works fine but it use fixed functions to calculate texture coordinates that passed to vertex program:
glMatrixMode(GL_TEXTURE);
glTranslatef(0.5f, 0.5f, 0.5f);
glScalef(0.5f, 0.5f, 0.5f);
glTranslatef(-lightPosition.x, -lightPosition.y, -lightPosition.z);
glMatrixMode(GL_MODELVIEW);
And after that in vertex shader we simply do
#transform position by texture matrix 0 to get 3d tex coords for attenuation
#put (s,t,r) -> (s1, t1, s2) for texture atten and (s,t,r)->(s1, t1, r1) for pass through atten
DP4 o[TEX1].x, c[4], v[OPOS];
DP4 o[TEX1].y, c[5], v[OPOS];
DP4 o[TEX2].x, c[6], v[OPOS];
DP4 o[TEX1].z, c[6], v[OPOS];
How can be fixed functions translated to vertex program?
Bye

!!ARBvp1.0
PARAM mvp[4]={ state.matrix.mvp };
PARAM LightPosition=program.env[0]; # Light Position

TEMP Temp;

DP4 result.position.x, mvp[0], vertex.position;
DP4 result.position.y, mvp[1], vertex.position;
DP4 result.position.z, mvp[2], vertex.position;
DP4 result.position.w, mvp[3], vertex.position;

SUB Temp, LightPosition, vertex.position;

MOV result.texcoord[0].xy, Temp;
MOV result.texcoord[1].x, Temp.z;

END

That should work.

Edit:
Unless I misunderstood the question, and you just want to do a texture matrix multiply in a vertex programâ€¦

[This message has been edited by NitroGL (edited 04-22-2003).]

Thanx
But I can understand why you done
DP4 result.position.x, mvp[0], vertex.position; and donâ€™t use it