Hi,

I use a TextureRectangle to store instances transformations matrix :

- TextureRectangle because it's easier to read a specific coordinate
- texure format is set on RGBA_32F to get full 32 bit floating point precision
- RGBA => there are 4 values (R, G, B, A) per pixel

So, a full transform matrix is 4x4 = 16 values => I use 4 pixels to store a 
full matrix this way :

- Texture size is 4 x InstanceCount
- on each row, there are 4 pixels => 16 values

So, in the shader, to retrieve the full matrix, I can do this : (code from 
memory, no garanty this is exact)

mat4 matrix;
matrix[0] = Texture2DRectangle(myTexture, 0, gl_InstanceID); => read 4 values
matrix[1] = Texture2DRectangle(myTexture, 1, gl_InstanceID); => read 4 values
matrix[2] = Texture2DRectangle(myTexture, 2, gl_InstanceID); => read 4 values
matrix[3] = Texture2DRectangle(myTexture, 3, gl_InstanceID); => read 4 values

and I transform gl_Vertex with this matrix.

It's a little heavy (4 texel fetch for each vertex) but it allow to send full 
matrix (position, attitude, scale...). If you need only the position, you can 
store it as a vec4 in a RGBA_32F TextureRectangle of 1 pixel width.

 

Cheers,
Aurelien

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=51309#51309





_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to