State.light[0].*?

any one have assembly code so i can understands how light work in ARB_fragment_program??
thanks in advance
:slight_smile:

This is a old ARB_vertex_program. You can do the same math in a fp.

!!ARBvp1.0

#This vp is used in Very Basic vp demo

#This emulates the fixed pipeline and handles 2 point lights

PARAM m[4]={state.matrix.modelview};
PARAM mvp[4]={state.matrix.mvp};
PARAM mvinv[4]={state.matrix.modelview.invtrans};
PARAM MA=state.material.ambient;
PARAM MD=state.material.diffuse;
PARAM ME=state.material.emission;
PARAM MS=state.material.specular;
PARAM MSh=state.material.shininess;
PARAM AmbientColor0=state.lightprod[0].ambient;
PARAM DiffuseColor0=state.lightprod[0].diffuse;
PARAM SpecularColor0=state.lightprod[0].specular;
PARAM AmbientColor1=state.lightprod[1].ambient;
PARAM DiffuseColor1=state.lightprod[1].diffuse;
PARAM SpecularColor1=state.lightprod[1].specular;
PARAM LP0=state.light[0].position;
PARAM LP1=state.light[1].position;
PARAM ViewVector={0.0, 0.0, 1.0, 0.0};
PARAM AllHalves={0.5, 0.5, 0.5, 0.5};

ATTRIB iPos=vertex.position;
ATTRIB iNormal=vertex.normal;
ATTRIB iTex0=vertex.texcoord[0];

OUTPUT oPos=result.position;
OUTPUT oColor=result.color;
OUTPUT oTex0=result.texcoord[0];

TEMP r0, r1, r2, r3, EyeVertex, sum;

#Transform the vertex to clip space.
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 vertex to eye space.
DP4 EyeVertex.x, m[0], iPos;
DP4 EyeVertex.y, m[1], iPos;
DP4 EyeVertex.z, m[2], iPos;

#Transform the normal to eye space.
DP3 r0.x, mvinv[0], iNormal;
DP3 r0.y, mvinv[1], iNormal;
DP3 r0.z, mvinv[2], iNormal;

#Compute lighting by light 0
#NOTE: The LIT instruction accelerates per-vertex lighting by computing lighting

coefficients for ambient, diffuse, and specular light contributions.

SUB r1, LP0, EyeVertex;
DP3 r1.w, r1, r1;
RSQ r1.w, r1.w;
MUL r1, r1, r1.w;
DP3 r2.x, r0, r1;
ADD r3, r1, ViewVector;
MUL r3, r3, AllHalves;
DP3 r3.w, r3, r3;
RSQ r3.w, r3.w;
MUL r3, r3, r3.w;
DP3 r2.y, r0, r3;
MOV r2.w, MSh.x;
LIT r2, r2;
MAD sum.xyz, DiffuseColor0, r2.y, AmbientColor0;
MAD sum.xyz, SpecularColor0, r2.z, sum;

#Compute lighting by light 1
SUB r1, LP1, EyeVertex;
DP3 r1.w, r1, r1;
RSQ r1.w, r1.w;
MUL r1, r1, r1.w;
DP3 r2.x, r0, r1;
ADD r3, r1, ViewVector;
MUL r3, r3, AllHalves;
DP3 r3.w, r3, r3;
RSQ r3.w, r3.w;
MUL r3, r3, r3.w;
DP3 r2.y, r0, r3;
MOV r2.w, MSh.x;
LIT r2, r2;
MAD r0.xyz, DiffuseColor0, r2.y, AmbientColor0;
MAD r0.xyz, SpecularColor0, r2.z, r0;

ADD oColor.xyz, sum, r0;
MOV oColor.w, MD.w;

#Tex coord0
MOV oTex0, iTex0;

END

thanks for code

and one more thing i want to ask
by putting code just as vp
and set .c/cpp file for vp extension instead of fp
the object color is white.
so for the light
do i need to feed some more related to light code in .c/cpp file
please help cause i am novice in case of vertex/fragment program

you can get the full source code from here
http://www.geocities.com/vmelkon/verybasicvp.html

thank you very much
(now no one can stop me in case of understanding codes :mad: )

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.