I’ve been recently working on ARB_fragment_program and experimented a phong shading code.
It worked fine but I found a strange thing.
When I turn on ambient color it does not lighten up whole scene.
Just take a look at.
Phong shading + ambient color (0.5, 0.5, 0.5, 1.0)
http://blog.naver.com/main/imageZoom.jsp…6/phongamb1.jpg
http://blog.naver.com/main/imageZoom.jsp…3/phongamb2.jpg
vertex lighting + ambient color (0.5, 0.5, 0.5, 1.0)
http://blog.naver.com/main/imageZoom.jsp…ertexlight1.jpg
http://blog.naver.com/main/imageZoom.jsp…ertexlight2.jpg
What did I do wrong? Here is my code.
!!ARBfp1.0
#hint
#OPTION ARB_precision_hint_nicest;
#declarations
ATTRIB tc0 = fragment.texcoord[0];
ATTRIB tc1 = fragment.texcoord[1];
ATTRIB inrm = fragment.texcoord[2];
ATTRIB ildir = fragment.texcoord[3];
ATTRIB ivdir = fragment.texcoord[4];
ATTRIB col0 = fragment.color;
PARAM exp = state.material.shininess;
#PARAM amb = state.lightprod[0].ambient;
PARAM amb = state.lightmodel.ambient;
PARAM diff = state.lightprod[0].diffuse;
PARAM spec = state.lightprod[0].specular;
OUTPUT out = result.color;
TEMP tex, nrm, ldir, vdir, lit, temp;
#instructions
#normalize normal
DP3 nrm.w, inrm, inrm;
RSQ nrm.w, nrm.w;
MUL nrm, inrm, nrm.w;
#normalize light vector
DP3 ldir.w, ildir, ildir;
RSQ ldir.w, ldir.w;
MUL ldir, ildir, ldir.w;
#normalize view vector
DP3 vdir.w, ivdir, ivdir;
RSQ vdir.w, vdir.w;
MUL vdir, ivdir, vdir.w;
#half angle vector
ADD temp, vdir, ldir;
DP3 temp.w, temp, temp;
RSQ temp.w, temp.w;
MUL temp, temp, temp.w;
#light
DP3 lit.y, nrm, ldir; # diffuse
DP3 lit.z, nrm, temp; # specular
LG2 lit.z, lit.z;
MUL lit.z, lit.z, exp.x;
EX2 lit.z, lit.z;
#sum
MAD temp, lit.y, diff, amb;
MAD temp, lit.z, spec, temp;
MUL temp, temp, col0;
TEX tex, tc0, texture[0], 2D;
MUL temp, temp, tex;
TEX tex, tc1, texture[1], 2D;
MUL out, temp, tex;
END
I also tried
MUL temp, lit.y, diff;
MAD temp, lit.z, spec, temp;
ADD temp, temp, amb;
but still got same result.
A strange thing is when I tried this code
#MAD temp, lit.y, diff, amb;
#MAD temp, lit.z, spec, temp;
MOV temp, amb;
it shows exactly what it should produce.
http://blog.naver.com/main/imageZoom.jsp…3/phongamb3.jpg
So I guess nothing wrong with amb data.
I’m using WinXP + Radeon9700 + cat4.6.