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/

Reply via email to