I have a question about environment bump mapping.

Nutty, I followed your instructions about calculating the tangent and binormal vectors for every surface. If I draw the normal, binormal and tangent as lines a vertex I should get 3 lines all perpendicular to each other, shouldn’t I? Defining a coordinate frame? This is what I’m getting anyway.

I’m not using a vertex program for now.

Instead, I construct a surface-space matrix myself from the normal/binormal/tangent, multiply this matrix by the inverse-transpose-modelview matrix, and pass this matrix to the texture shader spreading it across 4 dimensional texture coordinates for units 2,3,and 4 (like it says to do in the nvidia demo).

Now, I’m getting some kind of nice bumpmapping affect - but it isn’t correct. If I supply a normal map that consists of nothing but positive-Z normals, I don’t get a correct view of the cube map - I should be seeing the cube rotating around me as I rotate the object around me…instead I’m getting the cube map sort of distorting over the mesh.

Here’s my texture shader:-

!!TS1.0

texture_2d();

dot_product_reflect_cube_map_eye_from_qs_1of3(expand(tex0));

dot_product_reflect_cube_map_eye_from_qs_2of3(expand(tex0));

dot_product_reflect_cube_map_eye_from_qs_3of3(expand(tex0));

Here’s the code I use to construct and pass the surface-matrix (I’m normalising the viewpoint->vertex vector, purely out of desperation - it shouldn’t be normalised should it?):-

surfacematrix.m(0,0) = *(tangent+X);

surfacematrix.m(0,1) = *(tangent+Y);

surfacematrix.m(0,2) = *(tangent+Z);

```
surfacematrix.m(1,0) = *(binorm+X);
surfacematrix.m(1,1) = *(binorm+Y);
surfacematrix.m(1,2) = *(binorm+Z);
surfacematrix.m(2,0) = *(norm+X);
surfacematrix.m(2,1) = *(norm+Y);
surfacematrix.m(2,2) = *(norm+Z);
// multiply the surface matrix by the (inverse transpose)modelview matrix
surfacematrix.MultMatrix(modelviewmatrix);
viewpos[0] = *(vert+X) - vpos[X];
viewpos[1] = *(vert+Y) - vpos[Y];
viewpos[2] = *(vert+Z) - vpos[Z];
NORMALISE(viewpos);
// load the surface matrix and eye-to-vertex vector into
// texture unit 1-3's texture coordinates
*(tex2+0) = surfacematrix.m(0,0); // tangent_x
*(tex2+1) = surfacematrix.m(0,1); // binormal_x
*(tex2+2) = surfacematrix.m(0,2); // normal_x
*(tex2+3) = viewpos[0];
*(tex3+0) = surfacematrix.m(1,0); // tangent_y
*(tex3+1) = surfacematrix.m(1,1); // binormal_y
*(tex3+2) = surfacematrix.m(1,2); // normal_y
*(tex3+3) = viewpos[1];
*(tex4+0) = surfacematrix.m(2,0); // tangent_z
*(tex4+1) = surfacematrix.m(2,1); // binormal_z
*(tex4+2) = surfacematrix.m(2,2); // normal_z
*(tex4+3) = viewpos[2];
```

Can anyone shed any light on what I’m doing wrong?