View Full Version : varying mat3 mymatrix

V-man

04-04-2007, 06:50 PM

If I want to send a matrix from the vs to fs, do I have to do anything in particular in the fs?

Do I have to normalize it?

mymatrix[0] = normalize(mymatrix[0]);

mymatrix[1] = normalize(mymatrix[1]);

mymatrix[2] = normalize(mymatrix[2]);

Relic

04-05-2007, 04:15 AM

You mean to normalize individual columns in a matrix which is left multiplied? That most likely changes the equations this matrix expresses. Don't.

What exactly do you want to achieve?

Varyings are interpolated. If the matrix differs at the vertices which generate the primitive's fragments, that will generate all sorts of matrices in between and you probably didn't want that.

V-man

04-05-2007, 07:45 AM

I'm doing bumpmapping but I have a shader that is complicated to do the bumpmapping in tangent space. I want to transform the normal to eye space in the fs.

I built a matrix ,in the vs, by putting in a tangent, binormal and normal in each row

T[0] | T[1] | T[2]

B[0] | B[1] | B[2]

N[0] | N[1] | N[2]

I think I need to normalize each row when the matrix is in the fs

Relic

04-05-2007, 08:13 AM

I want to transform the normal to eye space in the fs.Transforming from screen space to eye space would just need the inverse projection.

I think I need to normalize each row when the matrix is in the fsRight, but matrix[0] is a column!

If you really need the basis trafo descibed by the normal, tangent and binormal, use three varying vec3, let them interpolate in the fragment shader, normalize those and then build you basis trafo matrix in the fragment shader.

Mind that interpolation can result in null vectors if incoming vectors are colinear and of opposite direction.

V-man

04-05-2007, 10:07 AM

"Transforming from screen space to eye space would just need the inverse projection."

Like I said, this is bumpmapping so normals are in tangent space.

Actually, I am putting values in matrix liek this

T[0] | B[0] | N[0]

T[1] | B[1] | N[1]

T[2] | B[2] | N[2]

so normalizing the columns should be possible.

For the moment, I am not normalizing so I guess there would be some error.

Powered by vBulletin® Version 4.2.3 Copyright © 2018 vBulletin Solutions, Inc. All rights reserved.