PDA

View Full Version : Automatic Texture Coordinate Generation in fragment Program



unreal
04-15-2005, 08:12 AM
hello!
A Simple Question...
How can I eneble Automatic Texture Cordinate Generation in a vertex/fragment program?
thank you!

Java Cool Dude
04-15-2005, 09:20 AM
Can you be a little more specific on what you consider texture coordinates generation on the GPU?
I can think of few examples; texture projection, toon shading etc...

unreal
04-15-2005, 12:31 PM
I want it for caustics.. you know..

glTexGenfv(GL_S, GL_OBJECT_PLANE, sPlane);
glTexGenfv(GL_T, GL_OBJECT_PLANE, tPlane);
glEnable(GL_TEXTURE_GEN_S);
glEnable(GL_TEXTURE_GEN_T);
glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);

how i do them when i use a vertex/fragment program?

3B
04-15-2005, 02:39 PM
in the vertex program, use
state.texgen[n].eye.{strq}, state.texgen[n].object.{strq}, and the equations in the GL docs under "Generating Texture Coordinates"(2.11.4)

untested code off the top of my head for your example:
PARAM sPlane = state.texgen.object.s;
PARAM tPlane = state.texgen.object.t;
DP4 result.texcoord.x,vertex.position,sPlane;
DP4 result.texcoord.y,vertex.position,tPlane;

michagl
04-15-2005, 04:32 PM
what is this business about 'state.texgen'? can you access opengl states from within shaders?

where can i read about this and what states are available?

Korval
04-15-2005, 09:23 PM
what is this business about 'state.texgen'? can you access opengl states from within shaders?Yes.


where can i read about this and what states are available?Probably in the extension specification. ARB_vertex_program (http://oss.sgi.com/projects/ogl-sample/registry/ARB/vertex_program.txt) .

dorbie
04-18-2005, 12:16 PM
Note this is raw state, no calculations are done as yet so it's basically the settings direct from the application, hence the dot products in the example shader.

It would be far better for a lot of texgen coordinates to just set the texture coordinates s, t & r based on the eyespace x, y, z and then just transform the tex coord through a matrix. It means less reliance on setting app level state where texgen is really kinda redundant because the shader knows what it needs, typically just the inverse modelview and heck that doesn't even need to go on the texture matrix.

You could use a 3x3 for some stuff but for projection you may need a full homogeneous coord.

For some projections I've also seen q set directly to equal z instead of using a projection matrix, it really depends on what you want to do. Sometimes a full frustum call on the projection has its uses w.r.t. matching a frustum near & far in a depth map rendering.