Emulating OpenGL texture matrix

Hi, in my Program (Delphi source) I set the Texture Matrix (4x4) here

glMatrixMode(GL_TEXTURE);
  if UseTextureMatrix then
   glLoadMatrixf(addr(TextureMatrix))
  else
   glLoadIdentity;
glMatrixMode(GL_MODELVIEW);

then I use it into the OpenGL Shader in this mode:

gl_TexCoord[0].st = (gl_TextureMatrix[0] * gl_MultiTexCoord0).st;

How can I do the same in Optix? (best way to pass a matrix form Host to Optix and exact code for matrix-vector multiplication)

Thank you very much

AD

You could do exactly the same in OptiX by using an optix::Matrix4x4 variable defined in optixu_matrix_namespace.h.

E.g. code like this:

rtDeclareVariable(optix::Matrix4x4, textureMatrix0, , );
rtDeclareVariable(float4, varTexCoord0, attribute TEXCOORD0, ); 
...
float4 texCoord0 = textureMatrix0 * varTexCoord0;

Please search for other use cases in the OptiX SDK samples source code.

Mind that OpenGL fills in matrices in column-major order and multiplies from the left, so watch the transpose flag when filling OptiX matrices from the same data.

Wow , nice trick !

Where can I find the complete list of attributes that I can specify as third argument of the function “rtDeclareVariable” ? I suspect that the list is long and very usefull…

;-)

AD

Please read the OptiX Programming Guide chapter 4.1.4 Attribute Variables.

The attribute semantic names are user defined!
Pick anything you like. I chose them to match old Cg shaders.

That user defined attribute semantic name is used to link the attributes you generate inside the intersection program with the variables you read inside the closest hit program.
The variable names themselves don’t actually need to match in the two domains, just the type and attribute semantic name. That is all explained in that small chapter.