PDA

View Full Version : Using matrices to represent tangent space...



daydreamer
02-10-2005, 02:37 PM
Hello,
I am trying to optimise my environment cube-map rendering shader for refraction/rendering.

I have a working vertex/fragment program pair
which interpolate tangent space between vertices using the following lines of code:

// Vertex shader

varying vec3 NewTangent;
varying vec3 NewBinormal;
varying vec3 NewNormal;

// Fragment shader

varying vec3 NewTangent;
varying vec3 NewBinormal;
varying vec3 NewNormal;

...

mat3 temp;

temp[0] = NewTangent;
temp[1] = NewBinormal;
temp[2] = NewNormal;

SurfNormal = Texture2d( bumpmap, texcoord.xy);
localnormal = SurfNormal * temp;
localnormal = normalize(localnormal);

This works. But when I attempt to replace these three varying vec3's with a single mat3 matrix, interpolation doesn't work ie...

// Vertex shader

varying mat3 TangentSpaceMatrix;

// Fragment shader

varying mat3 TangentSpaceMatrix;

...

SurfNormal = Texture2d( bumpmap, texcoord.xy);
localnormal = SurfNormal * TangentSpaceMatrix;
localnormal = normalize(localnormal);

This doesn't work. Is this a bug?
I thought a mat3x3 should interpolate?

V-man
02-12-2005, 08:43 AM
SurfNormal = Texture2d( bumpmap, texcoord.xy); That should be texture2D.
If SurfNormal is a vec4 then,

vec3 localnormal = vec3(SurfNormal) * TangentSpaceMatrix;

else it should give compile errors.