Yeah if the diffrence between the light vectors of two interpolated vertices is diffrent it will be unbalanced, forgot about that.
The irrlicht shader should like you said normlize the filtered result, which should be ok since there isnt any specular(sometimes the extra normlaize math causes banding).
btw i just saw this when looking over the code, seems irrlicht is moving the light vectors into the positive range before transporting through the tcoords. Which is a waste of operations and will also interfere with the code i posted.
to remove the waste oprations and have per vertex and per pixel and nr txtr normalize use this code inside the vs
remove this from vs
Code: Select all
"MAD OutLightVector1, TempTransLightV1, {0.5,0.5,0.5,0.5}, {0.5,0.5,0.5,0.5}; \n"\
"MAD OutLightVector2, TempTransLightV2, {0.5,0.5,0.5,0.5}, {0.5,0.5,0.5,0.5}; \n"\*/
and here
Code: Select all
"# normalize light vector 1 \n"\
"DP3 TempTransLightV1.w, TempTransLightV1, TempTransLightV1; \n"\
"RSQ TempTransLightV1.w, TempTransLightV1.w; \n"\
"MUL TempTransLightV1, TempTransLightV1, TempTransLightV1.w;\n"\
"\n"\
"# normalize light vector 2 \n"\
"DP3 TempTransLightV2.w, TempTransLightV2, TempTransLightV2; \n"\
"RSQ TempTransLightV2.w, TempTransLightV2.w; \n"\
"MUL TempTransLightV2, TempTransLightV2, TempTransLightV2.w;\n"\
do this
Code: Select all
"# normalize light vector 1 \n"\
"DP3 TempTransLightV1.w, TempTransLightV1, TempTransLightV1; \n"\
"RSQ TempTransLightV1.w, TempTransLightV1.w; \n"\
"MUL OutLightVector1 TempTransLightV1, TempTransLightV1.w;\n"\
"\n"\
"# normalize light vector 2 \n"\
"DP3 TempTransLightV2.w, TempTransLightV2, TempTransLightV2; \n"\
"RSQ TempTransLightV2.w, TempTransLightV2.w; \n"\
"MUL OutLightVector2, TempTransLightV2, TempTransLightV2.w;\n"\
and here is the full ps
Code: Select all
const char OPENGL_NORMAL_MAP_PSH[] =
"!!ARBfp1.0\n"\
"\n"\
"#Input\n"\
"ATTRIB inTexCoord = fragment.texcoord[0]; \n"\
"ATTRIB light1Vector = fragment.texcoord[1]; \n"\
"ATTRIB light2Vector = fragment.texcoord[2]; \n"\
"ATTRIB light1Color = fragment.color.primary; \n"\
"ATTRIB light2Color = fragment.color.secondary; \n"\
"\n"\
"#Output\n"\
"OUTPUT outColor = result.color;\n"\
"TEMP temp;\n"\
"TEMP temp2;\n"\
"TEMP colorMapColor;\n"\
"TEMP normalMapColor;\n"\
"\n"\
"# fetch color and normal map; \n"\
"TXP colorMapColor, inTexCoord, texture[0], 2D; \n"\
"TXP normalMapColor, inTexCoord, texture[1], 2D; \n"\
"\n"\
"# calculate color of light1; \n"\
"MAD normalMapColor, normalMapColor, {2,2,2,2}, {-1,-1,-1,-1}; \n"\
"DP3 normalMapColor.w, normalMapColor, normalMapColor; \n"\
"RSQ normalMapColor.w, normalMapColor.w; \n"\
"MUL normalMapColor, normalMapColor, normalMapColor.w;\n"\
//"MAD temp, light1Vector, {2,2,2,2}, {-1,-1,-1,-1}; \n"\
"# normalize light vector 1 \n"\
"DP3 light1Vector.w, light1Vector, light1Vector; \n"\
"RSQ light1Vector.w, light1Vector.w; \n"\
"MUL temp, light1Vector, light1Vector.w;\n"\
"\n"\
"DP3_SAT temp, normalMapColor, temp; \n"\
"MUL temp, light1Color, temp; \n"\
"\n"\
"# calculate color of light2; \n"\
//"MAD temp2, light2Vector, {2,2,2,2}, {-1,-1,-1,-1}; \n"\
"# normalize light vector 2 \n"\
"DP3 light2Vector.w, light2Vector, light2Vector; \n"\
"RSQ light2Vector.w, light2Vector.w; \n"\
"MUL temp2, light2Vector, light2Vector.w;\n"\
"DP3_SAT temp2, normalMapColor, light2Vector; \n"\
"MAD temp, light2Color, temp2, temp; \n"\
"\n"\
"# luminance * base color; \n"\
"MUL outColor, temp, colorMapColor; \n"\
"MOV outColor.a, light1Color.a; #write interpolated vertex alpha value\n"\
"\n"\
"END\n";
this gets rid of uneeded packing and normlizes light vectors and normals