PDA

View Full Version : shaders - opposite side is dark



vladd
02-28-2005, 06:45 AM
I use ARB_vertex_program & ARB_fragment_program for shaders.One side looks fine with lights on it but opposite is dark.
I would like to know what is my problem?
My shaders:
vertex shader:
!!ARBvp1.0

#Declarations
ATTRIB in = vertex.position;
ATTRIB nrm = vertex.normal;
ATTRIB tex = vertex.texcoord[0];
ATTRIB inCol = vertex.color;

PARAM mvp[4] = { state.matrix.mvp };
PARAM mv[4] = { state.matrix.modelview };
PARAM light = { 0.57735, 0.57735, 0.57735, 0.0};
PARAM const = {0.0, 0.0, 0.0, 0.2};

OUTPUT out = result.position;
OUTPUT oTex = result.texcoord[0];
OUTPUT oNrm = result.texcoord[1];
OUTPUT lVec = result.texcoord[2];
OUTPUT vDir = result.texcoord[3];
OUTPUT OutColor = result.color;

TEMP tmp;

#Code

#transform the positions
DP4 out.x, in, mvp[0];
DP4 out.y, in, mvp[1];
DP4 out.z, in, mvp[2];
DP4 out.w, in, mvp[3];

#transform the position to eye-space
DP4 tmp.x, in, mv[0];
DP4 tmp.y, in, mv[1];
DP4 tmp.z, in, mv[2];
DP4 tmp.w, in, mv[3];

#view direction
MOV vDir, -tmp;

#transfrom the normal to eye-space
DP3 oNrm.x, mv[0], nrm;
DP3 oNrm.y, mv[1], nrm;
DP3 oNrm.z, mv[2], nrm;

#output the light vector
MOV OutColor,inCol;
MOV lVec, light;
#ADD OutColor.xyz,lVec,OutColor.xyz;

#output the texcoords
MOV oTex, tex;
#MOV OutColor, inCol;

END

fragment shader:
!!ARBfp1.0

#simple phong lighting shader

#Declarations
TEMP tmp;
TEMP dif;
TEMP spec;
TEMP view;
TEMP color;

ATTRIB tex = fragment.texcoord[0];
ATTRIB nrm = fragment.texcoord[1];
ATTRIB lVec = fragment.texcoord[2];
ATTRIB vDir = fragment.texcoord[3];
ATTRIB inColor = fragment.color.primary;

#PARAM color = {0.2, 0.3, 1.0, 1.0};
PARAM const = {0.2, 0.2, 0.2, 32.0};

OUTPUT out = result.color;

#Normalize the normal
DP3 tmp.a, nrm, nrm;
RSQ tmp.a, tmp.a;
MUL tmp.rgb, nrm, tmp.a;

#normalize the view direction
DP3 view.a, vDir, vDir;
RSQ view.a, view.a;
MUL view.rgb, vDir, view.a;

#compute half angle vector
ADD spec.rgb, view, lVec;
DP3 spec.a, spec, spec;
RSQ spec.a, spec.a;
MUL spec.rgb, spec, spec.a;

#compute specular intensisty
DP3_SAT spec.a, spec, tmp;
LG2 spec.a, spec.a;
MUL spec.a, spec.a, const.w;
EX2 spec.a, spec.a;

#compute diffuse illum
DP3_SAT dif, tmp, lVec;
ADD_SAT dif.rgb, dif, const;

#sum
MOV color,inColor;
MAD_SAT dif.rgb, color, dif, spec.a;
MOV dif.a, color.a;
#ADD out.xyz, dif, spec;

MOV out, dif;

END