Hello,

i've developed a simple test environment for a dot3 shading
test on a simple plane object. All works fine until yet. 

Now i've create a second object, based on the geometry
 values of the first one with a new second stateSet object.

If i place this second object with an attitude transform in 
the near of the first one, on both objects the shading 
results are exactly the same. This could not be correct,  
because if i place a lightsource between both objects, 
the reflection are exactly the same. This is what i do:

//create first object
osg::Group* rootNode = new osg::Group();
osg::Geode*  quadNode = createQuad(osg::Vec3(0.0f, 0.0f, 0.0f), 10.0f);
osg::PositionAttitudeTransform* pos1 = new osg::PositionAttitudeTransform();
pos1->setPosition(osg::Vec3(0,0,0));
pos1->addChild(quadNode);

//create 2nd one (does nothing special,
//only copies the geometry data and add
//to a new geode)
osg::Geode*  quadNode2 = rebuildQuad(); 
osg::PositionAttitudeTransform* pos2 = new osg::PositionAttitudeTransform();
pos2->setPosition(osg::Vec3(20,0,0));
pos2->addChild(quadNode2);

//add to root
rootNode->addChild(pos1);
rootNode->addChild(pos2);

//create root stateSet
osg::StateSet* rootState = rootNode->getOrCreateStateSet();
rootState->setMode(GL_LIGHTING, osg::StateAttribute::OFF);
..

As you can see, no magic stuff for object creation and position. 
Now the source fragment for shader creation which is executed once:

osg::StateSet* bumpMapState;
osg::Program* bumpMapProgramObject = new osg::Program;

osg::Shader* brickVertexObject = 
        new osg::Shader( osg::Shader::VERTEX );
osg::Shader* brickFragmentObject = 
        new osg::Shader( osg::Shader::FRAGMENT );

bool ok =
        loadShaderSource( brickVertexObject, "dot3.vert" ) 
      &&
        loadShaderSource( brickFragmentObject, "dot3.frag" ) ; 

if(!ok)
{
   std::cout << "Couldn't load shaders" << std::endl;
   return -1;
}

bumpMapProgramObject->addShader( brickFragmentObject );
bumpMapProgramObject->addShader( brickVertexObject );

// bind render attributes for BT-Values 
bumpMapProgramObject->addBindAttribLocation("tangent", 
osg::Drawable::ATTRIBUTE_6);
bumpMapProgramObject->addBindAttribLocation("binormal", 
osg::Drawable::ATTRIBUTE_7);

// set shader hooks and bind it to application sources
osg::Uniform* lightPosU = new osg::Uniform("LIGHT_POSITION", 
osg::Vec4(lpos.x(), lpos.y(), lpos.z(), 1.0)); 
osg::Uniform* cameraPosU = new osg::Uniform("CAMERA_POSITION", 
osg::Vec3(posV[0], posV[1], posV[2]));

osg::Uniform* normalMapU = new osg::Uniform("normalMap",1); 
osg::Uniform* baseTextureU = new osg::Uniform("decalMap",0); 

osg::Uniform* ambientU = new osg::Uniform("matAmbient", osg::Vec4(0.0f, 0.0f, 
0.0f, 1.0f));
osg::Uniform* diffuseU = new osg::Uniform("matDiffuse", osg::Vec4(0.8f, 0.8f, 
0.8f, 1.0f));
osg::Uniform* specularU = new osg::Uniform("matSpecular", osg::Vec4(0.8f, 0.8f, 
0.8f, 1.0f));

lightPosU->setUpdateCallback(new updateBumpShader());
cameraPosU->setUpdateCallback(new updateShaderView());


Now bind Shadersources explicit to object StateSets,
separated:

for(int i=0; i<2; i++)
{
        if(i==0){
         bumpMapState = new osg::StateSet();
           quadNode->setStateSet(bumpMapState);
     }

     else if(i==1){
           bumpMapState = new osg::StateSet();
         quadNode2->setStateSet(bumpMapState);
     }

     bumpMapState->setMode(GL_CULL_FACE,osg::StateAttribute::ON);

     // bind variables
     bumpMapState->addUniform(lightPosU);
     bumpMapState->addUniform(cameraPosU);
     bumpMapState->addUniform(normalMapU);
     bumpMapState->addUniform(baseTextureU);
     bumpMapState->addUniform(diffuseU);
     bumpMapState->addUniform(ambientU);
     bumpMapState->addUniform(specularU);

     // bind attributes
     bumpMapState->setAttributeAndModes(bumpMapProgramObject, 
osg::StateAttribute::ON);

     Then do texture stuff ...
     This was all ...
}

Know's anyone what i do wrong?
Thanks for any help,

Best regards,
Chris





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

Reply via email to