I thought I nailed down the few bugs that were prohibiting me from getting per-pixel lighting to work properly, but I can’t help but notice that I failed miserably as per times, lighting changes direction all of a sudden (well when the light source goes outside the quad limits) and that for sure bugs the hell outta me. >:(
So can you please help me out?
Here’s the source
http://www.realityflux.com/abba/PPL.zip
PS: I’ll only post how I find out the space tangent per vertex seeing that make_room.java alone exceeds 300 lines of code
public static class plane{
jcd_math.matrix4f tangent_matrix[];
float vertices[][] = new float[4][5],
normal[] = new float[3],
texture_w,
texture_h;
int texture_dot3,
texture_base,
counter_clock_map[] = {0,1,2,
1,2,0,
2,0,1,
3,2,1};
plane(jcd_math.tuple3f[] points,jcd_math.tuple3f vector,
float w, float h, int texture_base,int texture_dot3){
this.texture_dot3 = texture_dot3;
this.texture_base = texture_base;
normal[0] = vector.x;
normal[1] = vector.y;
normal[2] = vector.z;
texture_w = w;
texture_h = h;
float texture_s_t[] = { 0, 0,
texture_w, 0,
0,texture_h,
texture_w,texture_h};
for(int i =0, a = 0; i<4; i++, a+=2){
vertices[i][0] = points[i].x;
vertices[i][1] = points[i].y;
vertices[i][2] = points[i].z;
vertices[i][3] = texture_s_t[ a];
vertices[i][4] = texture_s_t[a+1];
}
create_tagent_matrices();
}
/**********************************************************************************************/
/* */
/* http://members.rogers.com/deseric/tangentspace.htm.. . */
/* */
/**********************************************************************************************/
void create_tagent_matrices(){
tangent_matrix = new jcd_math.matrix4f[4];
jcd_math.tuple3f p_0 = new jcd_math.tuple3f(),
p_1 = new jcd_math.tuple3f(),
p_2 = new jcd_math.tuple3f(),
v_1 = new jcd_math.tuple3f(),
v_2 = new jcd_math.tuple3f(),
nor[] = new jcd_math.tuple3f[3];
for(int i=0, index =0; i<tangent_matrix.length; i++, index+=3){
tangent_matrix[i] = new jcd_math.matrix4f();
tangent_matrix[i].load_identity();
for(int n= 0; n<3; n++){
p_0.set(vertices[counter_clock_map[index+0]][n],vertices[counter_clock_map[index+0]][3],vertices[counter_clock_map[index+0]][4]);
p_1.set(vertices[counter_clock_map[index+1]][n],vertices[counter_clock_map[index+1]][3],vertices[counter_clock_map[index+1]][4]);
p_2.set(vertices[counter_clock_map[index+2]][n],vertices[counter_clock_map[index+2]][3],vertices[counter_clock_map[index+2]][4]);
v_1.sub(p_1,p_0);
v_2.sub(p_2,p_0);
nor[n] = new jcd_math.tuple3f();
nor[n].cross(v_1,v_2);
nor[n].normalize();
}
tangent_matrix[i].elements[0] = -nor[0].y/nor[0].x;
tangent_matrix[i].elements[4] = -nor[1].y/nor[1].x;
tangent_matrix[i].elements[8] = -nor[2].y/nor[2].x;
tangent_matrix[i].elements[1] = -nor[0].z/nor[0].x;
tangent_matrix[i].elements[5] = -nor[1].z/nor[1].x;
tangent_matrix[i].elements[9] = -nor[2].z/nor[2].x;
tangent_matrix[i].elements[ 2] = normal[0];
tangent_matrix[i].elements[ 6] = normal[1];
tangent_matrix[i].elements[10] = normal[2];
}
}
}