Hi,

Am following osgstereomatch example, but can't find my mistake.
Trying to use two Textures in a Fragment Shader, with one set of geometry 
texCoordArray and one with Screen Projected Coordinates.

I include an .osg file in my programm which has properly textured geometry. The 
.osg file has following lines :

Geometry {
 DataVariance STATIC
 StateSet {
   rendering_hint DEFAULT_BIN
   renderBinMode INHERIT
        textureUnit 0 {
                GL_TEXTURE_2D ON
                        Texture2D {
                                name " ... "
                                        file " ... "
                                        ...
                }
                TexEnv {
                        mode REPLACE
                }
                
Its bound to texture Unit 0 to a StateSet attached to my Geometry. When render 
just this file, everything is as expected ( the geometry has ST Coords ).

Now I tweak the rendering, I want to project ( camera projection ) another 
texture ontop of this loaded and textured file.
The SG Structer inside this .osg file is simply : 
Group  - Geode - Geometry
So first I generate a StateSet for my Group Node and just add a sampler 2D 
Uniform, so that the original fileTexture ( should be ) is available in my 
Shader :
stateSet -> addUniform( new osg::Uniform( osg::Uniform::SAMPLER_2D , 
"stTexture" , 1 ) ) ;

Then I add the projectionTexture to my StateSet into Texture Unit 1 and add the 
corresponding Uniform :
        stateSet -> setTextureAttributeAndModes( 1 , projTexture , 
osg::StateAttribute::ON ) ;
        stateSet -> addUniform( new osg::Uniform( osg::Uniform::SAMPLER_2D , 
"projectionTexture" , 1 ) ) ;
        
In my GLSL Fragment Program I Define :
in                      vec2                    texCoord ;                      
// Interpolated gl_MultiTexCoord0.st
const           vec2                    screenRes = ... ;       // Screen 
Resolution    
uniform sampler2D       stTexture ;
uniform sampler2D       projectionTexture ;

and in Main Function :

        vec4 color1 = texture2D( stTexture , texCoord ) ;
        vec4 color2 = texture2D( projectionTexture , gl_FragCoord.st / 
screenRes ) ;    // Projet based on Fragment Coordinate

        gl_FragColor = mix( color1 , color2 , mixValue ) ;
        
The result is, that stTexture gets also projected onto the Geometry, not using 
the geometry texCoordArray, but the Fragment Coordinates.
Also the mixValue doesn't work as expected. Looks like both the Textures are 
Projected and mixed uniformly with same weigth.
What am I missing, or doing wromg ?
I feel that I don't associate the stTexture Sampler with the right texture 
unit, but how can I do it with an loaded .osg file ?


Thank you!

Cheers, searching for the Pivot of my Soul, PP !!!

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=32924#32924





_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to