But then looking at the two lines together:
stateset->setTextureAttributeAndModes(1,texture,osg::StateAttribute::ON);
stateset->setTextureAttributeAndModes(1,texgen,osg::StateAttribute::ON);
it would appear that both of these textures are being applied to texture
unit 1, and are then being blended together by the osg::TexEnv that is
defined (and also applied to >texture unit 1).
TexGen attribute is not a Texture. One cannot have two Textures active for
one stage. Second texture applied will override the first one.
Two lines above first set Texture for the stage 1 and then set automatic tex
coord generation (TexGen) for the same stage. Only one texture "texture" is
applied, texgen auto generates texture coordinates for all vertices passed
and tex env blends texture with constant color defined (.3f,0.3f,0.3f,0.3f).
State method setTextureAttributeAndModes sets attribute for particular
Texture Stage. It does not only select specific Texture for the stage but
can set other texture attributes like TexGen, TexEnv, TexMat, PointSprite,
TexEnvFilter, TexEnvCombine.
As for the second texture on stage 2. There are other things that could went
wrong. Possible errors may be texture on stage 2 not passed as uniform to
shader, texture coords not present, errors fragment shader code. Provide
some source code and we may be more helpful.
Cheers,
Wojtek Lewandowski
----- Original Message -----
From: Mark W
To: [email protected]
Sent: Thursday, March 01, 2007 8:08 AM
Subject: [osg-users] Simple problem with multitexturing
Hey everyone,
I'm writing a fragment shader to do projective texturing. I'm using an
osg::camera to render a depth map to a texture, and then I'd like to bind
that texture to my model so that I can access it from within my fragment
shader.
I looked at the osgmultitexture example, and the texture code is as follows:
osg::Texture2D* texture = new osg::Texture2D;
texture->setImage(image);
osg::TexGen* texgen = new osg::TexGen;
texgen->setMode(osg::TexGen::SPHERE_MAP);
osg::TexEnv* texenv = new osg::TexEnv;
texenv->setMode(osg::TexEnv::BLEND);
texenv->setColor(osg::Vec4(0.3f,0.3f,0.3f,0.3f));
osg::StateSet* stateset = new osg::StateSet;
stateset->setTextureAttributeAndModes(1,texture,osg::StateAttribute::ON);
stateset->setTextureAttributeAndModes(1,texgen,osg::StateAttribute::ON);
stateset->setTextureAttribute(1,texenv);
rootnode->setStateSet(stateset);
From my understanding, the line:
stateset->setTextureAttributeAndModes(1,texture,osg::StateAttribute::ON);
binds "texture" to texture unit 1 and enables that texture. But then
looking at the two lines together:
stateset->setTextureAttributeAndModes(1,texture,osg::StateAttribute::ON);
stateset->setTextureAttributeAndModes(1,texgen,osg::StateAttribute::ON);
it would appear that both of these textures are being applied to texture
unit 1, and are then being blended together by the osg::TexEnv that is
defined (and also applied to texture unit 1).
My initial thought was that I would just take my model's stateset (the model
is only using a single texture) and make a function call like:
osg::StateSet* stateset = model->getOrCreateStateSet();
stateset->setTextureAttributeAndModes(2,my_texture,osg::StateAttribute::ON);
to bind a texture into texture unit 2 for that model. I tried this and it
doesn't seem to allow me to access the second texture in my fragment shader.
I attempted to put the new texture in texture unit 1 (attempting to copy the
example where both textures are put in the first texture unit) but I didn't
use an osg::TexEnv to blend or anything like that (I just want to be able to
access both textures independently, I don't want them to be blended for me).
I realize this is a pretty elementary question, but it's had me stumped for
longer than I care to admit :). Thanks a bunch in advance for any help you
guys can offer!
Mark
_______________________________________________
osg-users mailing list
[email protected]
http://openscenegraph.net/mailman/listinfo/osg-users
http://www.openscenegraph.org/
_______________________________________________
osg-users mailing list
[email protected]
http://openscenegraph.net/mailman/listinfo/osg-users
http://www.openscenegraph.org/