I think you should use the texture matrix in the shader. Been experimenting with the same lately and it seem to wok -Nick
On Tue, Feb 9, 2010 at 4:32 PM, Jean-Sébastien Guay < jean-sebastien.g...@cm-labs.com> wrote: > Hi all, > > I'm trying to replace the fixed function texgen for a given effect by a > shader in order to remove the back projection problem. But I'm struggling a > bit to even get the texgen to work with shaders (once that's done removing > the back projection will be a cinch). > > The original (fixed pipeline) code does: > > _texGen= new osg::TexGen; > _texGen->setMode( osg::TexGen::OBJECT_LINEAR ); > > osg::StateSet *ss = geode->getOrCreateStateSet(); > ss->setTextureMode( > _textureUnit, GL_TEXTURE_GEN_S, osg::StateAttribute::ON ); > ss->setTextureMode( > _textureUnit, GL_TEXTURE_GEN_T, osg::StateAttribute::ON ); > ss->setTextureMode( > _textureUnit, GL_TEXTURE_GEN_R, osg::StateAttribute::ON ); > ss->setTextureMode( > _textureUnit, GL_TEXTURE_GEN_Q, osg::StateAttribute::ON ); > ss->setTextureAttributeAndModes( > _textureUnit, _texGen.get(), osg::StateAttribute::ON ); > > And then later, in the cull traversal, it does: > > _texGen->setPlanesFromMatrix( someMatrix ); > > This works well on the fixed pipeline. Now my first question when replacing > this by shaders is: I understand I need to replace the calculation by shader > code like this in the vertex shader: > > gl_TexCoord[1].s = dot(gl_Vertex, gl_ObjectPlaneS[1]); > gl_TexCoord[1].t = dot(gl_Vertex, gl_ObjectPlaneT[1]); > gl_TexCoord[1].p = dot(gl_Vertex, gl_ObjectPlaneR[1]); > gl_TexCoord[1].q = dot(gl_Vertex, gl_ObjectPlaneQ[1]); > > But does the setPlanesFromMatrix() fill in the gl_ObjectPlaneS/T/R/Q > builtins, or should I remove the osg::TexGen stateAttribute completely and > instead place that same matrix in some uniform and use that? i.e. in the > cull traversal: > > geode->getOrCreateStateSet()->getOrCreateUniform( > "texGen", osg::Uniform::FLOAT_MAT4)->set(matrix); > > and then in my shader: > > uniform mat4 texGen; > //... then in main() > gl_TexCoord[1].s = dot(gl_Vertex, texGen[0]); > gl_TexCoord[1].t = dot(gl_Vertex, texGen[1]); > gl_TexCoord[1].p = dot(gl_Vertex, texGen[2]); > gl_TexCoord[1].q = dot(gl_Vertex, texGen[3]); > > What is better? > > Next question, is there something special I need to do in the fragment > shader to use these generated texture coordinates? Because I tried simply > doing the obvious: > > vec4 col = texture2D( tex, gl_TexCoord[1].st ); > > and it doesn't work (I've tried using the vertex shader both ways above, > and even without any vertex shader which should revert to fixed pipeline > vertex stage...). > > So I guess my second question is more important, why does the texturing > with OBJECT_LINEAR texGen not work when I just replace the fragment shader > and use the fixed function vertex processing? I would think that would > isolate the mistake to only the fragment shader... > > Do I need to do something else in the fragment shader? Maybe transform the > generated texture coordinates somehow? What does the fixed pipeline do with > generated texture coords? > > Thanks in advance, > > J-S > -- > ______________________________________________________ > Jean-Sebastien Guay jean-sebastien.g...@cm-labs.com > http://www.cm-labs.com/ > http://whitestar02.webhop.org/ > _______________________________________________ > osg-users mailing list > osg-users@lists.openscenegraph.org > http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org >
_______________________________________________ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org