Hi all, I’m trying the following ARB vertex program:
!!ARBvp1.0
# Performs transformation and ambient, diffuse
# and specular lighting with a directional light souce
ATTRIB iPos = vertex.position;
ATTRIB iNormal = vertex.normal;
ATTRIB iTxCoord = vertex.texcoord;
PARAM mvinv[4] = { state.matrix.modelview.invtrans };
PARAM mvp[4] = { state.matrix.mvp };
PARAM lightDir = state.light[0].position;
PARAM halfDir = state.light[0].half;
PARAM specExp = state.material.shininess;
PARAM ambCol = state.lightprod[0].ambient;
PARAM diffCol = state.lightprod[0].diffuse;
PARAM specCol = state.lightprod[0].specular;
OUTPUT oPos = result.position;
OUTPUT oColor = result.color;
OUTPUT oTxCoord = result.texcoord;
TEMP eyeNormal, temp, dots;
# Transform the vertex to clip coordinates
DP4 oPos.x, mvp[0], iPos;
DP4 oPos.y, mvp[1], iPos;
DP4 oPos.z, mvp[2], iPos;
DP4 oPos.w, mvp[3], iPos;
# Transform the normal into eye space
DP3 eyeNormal.x, mvinv[0], iNormal;
DP3 eyeNormal.y, mvinv[1], iNormal;
DP3 eyeNormal.z, mvinv[2], iNormal;
# Compute diffuse and specular dot products
# and use LIT to compute lighting coefficients
DP3 dots.x, eyeNormal, lightDir;
DP3 dots.y, eyeNormal, halfDir;
MOV dots.w, specExp.x;
LIT dots, dots;
# Accumulate color contributions and pass alpha
MAD temp, dots.y, diffCol, ambCol;
MAD oColor.xyz, dots.z, specCol, temp;
MOV oColor.w, diffCol.w;
MOV oTxCoord, iTxCoord;
END
But I can only make it work if light[0] is a directional light, and seems to work only on eye coordinates (as if the light were attached to the view).
Please… where can I find examples of how to perform a standard shading with a point light source in world coordinates? How distance falloff should be treated?
Also, how can I do a COS(x) in a vertex program? :eek: