I’m trying to replace the fixed function pipeline in my demo with vp/fp , and after several weeks of tinkering with it, it started to work but it seems that something is not right and I can’t put my hand on it,
The problem is with the lighting(diffuse, specualr), it looks wrong as if only one vertex is affected by lighting, and the lighting acts funny when moving the camera, and i'm putting the lightsource in the center of the cube.
here's a screenshot http://www.myfilestash.com/userfiles/L0rdDiabl0/Normal.JPG
so i thought some of the expert guys can spot where the problem is.
Thanks in advance.
here's the vertex program:
!!ARBvp1.0
#Per-vertex inputs
ATTRIB Position = vertex.position;
ATTRIB Color = vertex.color;
ATTRIB Normal = vertex.attrib[1];
ATTRIB Tangent = vertex.attrib[2];
ATTRIB DecalTex = vertex.texcoord[0];
ATTRIB NormalTex = vertex.texcoord[1];
#Constant Parameters
PARAM mvp[4] = {state.matrix.mvp};
PARAM mvinv[4] = {state.matrix.modelview.invtrans};
PARAM EyeLightPos = state.light[0].position;
PARAM EyeCameraPos = program.local[5];
TEMP LightPos, CameraPos, LightVector, ViewVector, HalfVector, Binormal, TS_LightVector, TS_HalfVector, mag;
#Per-vertex outputs
OUTPUT oPosition = result.position;
OUTPUT oColor = result.color;
OUTPUT oDecalTex = result.texcoord[0];
OUTPUT oNormalTex = result.texcoord[1];
OUTPUT LV_TexCoord = result.texcoord[2];
OUTPUT HV_TexCoord = result.texcoord[3];
#Transform the Vertex to Clip Space
DP4 oPosition.x, mvp[0], Position;
DP4 oPosition.y, mvp[1], Position;
DP4 oPosition.z, mvp[2], Position;
DP4 oPosition.w, mvp[3], Position;
#Transform Light Position from Eye Space to Object Space (Using Inverse Model-View Matrix)
DP4 LightPos.x, mvinv[0], EyeLightPos;
DP4 LightPos.y, mvinv[1], EyeLightPos;
DP4 LightPos.z, mvinv[2], EyeLightPos;
#Transform Camera Position from Eye Space to Object Space (Using Inverse Model-View Matrix)
DP4 CameraPos.x, mvinv[0], EyeCameraPos;
DP4 CameraPos.y, mvinv[1], EyeCameraPos;
DP4 CameraPos.z, mvinv[2], EyeCameraPos;
#Create Light Vector
ADD LightVector, -Position, LightPos;
#Create View Vector
ADD ViewVector, -Position, CameraPos;
#Create Half Vector
ADD HalfVector, LightVector, ViewVector;
#Normalize Light Vector
DP3 mag.w, LightVector, LightVector;
RSQ mag.w, mag.w;
MUL LightVector.xyz, mag.w, LightVector;
#Normalize Half Vector
DP3 mag.w, HalfVector, HalfVector;
RSQ mag.w, mag.w;
MUL HalfVector.xyz, mag.w, HalfVector;
#Calculate Binormal
XPD Binormal, Normal, Tangent;
#Transform Light Vector to Tangent Space
DP3 TS_LightVector.x, LightVector, Tangent;
DP3 TS_LightVector.y, LightVector, Binormal;
DP3 TS_LightVector.z, LightVector, Normal;
#Transform View Vector to Tangent Space
DP3 TS_HalfVector.x, HalfVector, Tangent;
DP3 TS_HalfVector.y, HalfVector, Binormal;
DP3 TS_HalfVector.z, HalfVector, Normal;
MOV oColor, Color;
MOV oDecalTex , DecalTex;
MOV oNormalTex, NormalTex;
MOV LV_TexCoord , TS_LightVector;
MOV HV_TexCoord , TS_HalfVector;
END
and here's the fragment program:
!!ARBfp1.0
#Fragment inputs
ATTRIB DecalTexCoord = fragment.texcoord[0];
ATTRIB NormalTexCoord = fragment.texcoord[1];
ATTRIB LVTexCoord = fragment.texcoord[2];
ATTRIB HVTexCoord = fragment.texcoord[3];
#Fragment outputs
OUTPUT outColor = result.color;
TEMP texelColor, texelNormal, NdotL, NdotH, NormalizedLight, NormalizedHalf, Color;
#Texture Fetch
TEX texelColor, DecalTexCoord, texture[0], 2D;
TEX texelNormal, NormalTexCoord, texture[1], 2D;
#Normalize Light Vector, no need for it if LV is normalized with the cube map
DP3 NormalizedLight.w, LVTexCoord, LVTexCoord;
RSQ NormalizedLight.w, NormalizedLight.w;
MUL NormalizedLight.xyz, NormalizedLight.w, LVTexCoord;
#Normalize Half Vector, no need for it if HV is normalized with the cube map
DP3 NormalizedHalf.w, HVTexCoord, HVTexCoord;
RSQ NormalizedHalf.w, NormalizedHalf.w;
MUL NormalizedHalf.xyz, NormalizedHalf.w, HVTexCoord;
#This Computes N.L
DP3 NdotL, texelNormal, NormalizedLight;
#This Computes N.H
DP3 NdotH, texelNormal, NormalizedHalf;
MUL Color, NdotL, NdotH;
#Modulate texel color with vertex color
MUL outColor, texelColor, Color;
END