PDA

View Full Version : Passing a mat3 attribute to a Vertex Shader



Sergejack
03-02-2012, 06:38 AM
Hello.

I'd like to pass a mat3 attribute to a Vertex Shader.
I know how to pass vectors but despite I tried almost everythng I don't manage to pass a ma3.
I know I could just pass 3 vec3 and combine them into a mat3 inside the shader but I'd rather use something more straightforward.

Maybe that's just not possible but I think I saw it once.

I need to know, anyway.

Sergejack
03-12-2012, 06:53 AM
Does nobody know? :(

Sergejack
03-14-2012, 03:29 AM
I guess "attribute mat3" is just a mecanism that cannot be used yet.

Thus, it should just not compile when present in the shaders' code.

gliniak
03-20-2012, 01:05 AM
You need to pass typed (Float32Array) 1-dimension (in this case 9-elements) array.
See example of passing 4x4 mat: http://learningwebgl.com/blog/?p=28 search for "mvMatrix"

gardin
04-20-2012, 11:52 AM
You need to pass typed (Float32Array) 1-dimension (in this case 9-elements) array.
See example of passing 4x4 mat: http://learningwebgl.com/blog/?p=28 search for "mvMatrix"No that is not the way, he's talking about an attribute, not a uniform.

Yes, it is possible to use mat4 and mat3 as attributes. But remember though that the number of attributes that can be used is limited, are you sure you want to send down a whole matrix for every vertex?

What you do, is you define your


attribute mat3 myAttrib;

Then, when querying for the attribute location x, you will get the location for a vec3, the subsequent location x+1 will also be a vec3, and the x+2 the last column (note column oriented matrices in OpenGL).

It is mentioned in the GLSL for ES specification: http://www.khronos.org/registry/gles/sp ... 1.0.17.pdf (http://www.khronos.org/registry/gles/specs/2.0/GLSL_ES_Specification_1.0.17.pdf) at '4.3.3 Attribute'.

And the mechanism i explained is also explained in the OpenGL ES 2.0 specification:
http://www.khronos.org/registry/gles/sp ... 2.0.25.pdf (http://www.khronos.org/registry/gles/specs/2.0/es_full_spec_2.0.25.pdf) at '2.10. VERTEX SHADERS', page 33

Sergejack
05-23-2012, 03:05 AM
Thanks but this won't work with webGL since you don't work with numeric pointers in it (so "location x+1" is invalid).