PDA

View Full Version : GLSL 1.5, inverse() and transpose() functions....



heinz85
01-30-2012, 09:26 AM
Hi everybody.

Does anybody know why when I use those functions on a 4x4 matrix the shader fails to compile (I use it in the vertex shader, if it matters anything...), stating that there is no overloaded version matching the arguments?

Thanks,
Heinrich

Alfonse Reinheart
01-30-2012, 10:20 AM
First, what version of GLSL are you using? You should have a #version declaration at the top of your shader, and it probably needs to be at least 1.20 to access those functions if not later.

Second, let's see your shader code to make sure you're using them correctly.

heinz85
01-30-2012, 11:21 AM
as I wrote.... GLSL 1.5...


#version 150

.
.
.

uniform mat4 modelingMatrix;

void main() {

mat4 myMatrix = transpose(inverse(modelingMatrix));
.
.
.
}

Thanks,
Heinrich

menzel
01-30-2012, 01:31 PM
If you want the normal matrix, do the inverse transpose of the upper 3*3 part of the modelmatrix and do it on the CPU side instead of once per vertex, doing it in the vertex shader can be quite slow - unbelievable slow on a GeForce 9600M on MacOSX btw...

But: It should work, transpose and inverse are defined for 4x4 matrices and the shader should compile fine. What OS/driver are you using?

heinz85
01-30-2012, 03:36 PM
It is windows... I think the problem is in the machine - I'm using intels hd3000...
Well. I already decided to do it on the CPU, and already got a bug:
Took the upper left corner of the matrix resulting after inverting and transposing.
I guess I should have made the inversion and transposition on the 3*3 corner... right?

Heinrich

Kopelrativ
01-31-2012, 02:54 AM
If you don't have non-uniform scaling as part of your model view matrix, the upper 3x3 of the model-view matrix is just as good as the "normal matrix" (which is the transpose of the inverse of the model view matrix) for transforming normals.

Copied from http://hacksoflife.blogspot.com/2009/02/who-needs-inverse-transpose.html

heinz85
01-31-2012, 03:09 AM
Yes, I know it.
The problem is: I have non-uniform scaling, but never really tested it, and so far I used the modeling matrix very well...
Once I did test the non-uniform scaling: SURPRISE!!!

Heinrich

menzel
01-31-2012, 03:22 AM
Last time i checked Intel did not provide OpenGL 3.2 drivers for the HD 3000, so a shader with #version 150 should not compile. The chip should support 3.2 (and Apple supplies 3.2 drivers for the HD 3000) but Intels drivers are behind.
What OpenGL version does your drivers clain to support?