Original Post
Hello all.
I''ve managed to get bump mapping working using GL_ARB_texture_program and GL_ARB_texture_combine and I think I''m experiencing a bug. Below is a screenshot of 4 renders of my bump mapped sphere thing im testing with. Top left is the bump mapped sphere with the light behind the camera. Top right is the OGL lighted sphere with the light behind the camera. Bottom Left is the bump mapped sphere from a side on persective to the sphere with the light coming from the right. The Bottom right is the OGL lighted sphere side on with the light coming from the right. It seems that as I look at it from the side.. it gets much darker, far to dark to be working correctly. Is this supposed to happen?
The vertex progam I am using is:
The vertex progam I am using is:
!!ARBvp1.0
#******************************************
# This program computes Bump map stuff
#******************************************
#umm...to transform back to object space, I need to pass in a separate matrix
#that is the inverse of the viewing transform alone (so it excludes the model
#specific part).Inverse = transpose of 3x3, negate pos.
# Original Input...
ATTRIB iPos = vertex.position;
ATTRIB iTangent = vertex.color;
ATTRIB iNormal = vertex.normal;
ATTRIB iTexCoord0 = vertex.texcoord[0];
ATTRIB iTexCoord1 = vertex.texcoord[1];
# Vertex Output...
OUTPUT oPos = result.position;
OUTPUT oColor = result.color;
OUTPUT oTexCoord0 = result.texcoord[0];
OUTPUT oTexCoord1 = result.texcoord[1];
# Constant variables...
PARAM mvp[4] = { state.matrix.mvp };
PARAM mvinv[4] = { state.matrix.modelview.invtrans };
PARAM mv[4] = { state.matrix.modelview };
PARAM invviewmat[4] = { state.matrix.program[0].inverse };
PARAM lightPos = state.light[0].position;
PARAM lightAmb = state.light[0].ambient;
PARAM red = {1, 0, 0, 1};
TEMP temp, temp2, Binormal;
#**************************************************
# TRANSFORM (CLIP SPACE GENERATION)
#**************************************************
# Transform each axis into clip space
DP4 oPos.x, mvp[0], iPos;
DP4 oPos.y, mvp[1], iPos;
DP4 oPos.z, mvp[2], iPos;
DP4 oPos.w, mvp[3], iPos;
#**************************************************
# LIGHTING (OUTPUT COLOUR)
#**************************************************
#NOTE DP3 rotates vectors, DP4 rotates points
#We need to output tangent space light vector in color
#Get binormal as cross product of tangent and normal
XPD Binormal, iTangent, iNormal;
#transform to view space
DP4 temp2.x, mv[0], iPos;
DP4 temp2.y, mv[1], iPos;
DP4 temp2.z, mv[2], iPos;
DP4 temp2.w, mv[3], iPos;
#Get dir vector from light to vertex and normalize
SUB temp, lightPos, temp2;
DP3 temp.w, temp, temp; # result.w = nx^2+ny^2+nz^2
RSQ temp.w, temp.w; # result.w = 1/sqrt(nx^2+ny^2+nz^2)
MUL temp.xyz, temp.w, temp;
#Transform back to object space (by inverse VIEW matrix.. not modelview)
DP3 temp2.x, invviewmat[0], temp;
DP3 temp2.y, invviewmat[1], temp;
DP3 temp2.z, invviewmat[2], temp;
#Transform to texture space
DP3 temp.x, temp2, iTangent;
DP3 temp.y, temp2, Binormal;
DP3 temp.z, temp2, iNormal;
MOV oTexCoord1, temp;
#**************************************************
# TEXTURING (OUTPUT ST)
#**************************************************
MOV oTexCoord0, iTexCoord0;
END
Any ideas on how to make this look better?
- James