Hi,

I'm working on implementing some lighting effects with shaders and
I've run into the problem that vertex positions are passed to the
shader in local coordinates. This means that if there are any
transformation nodes in the scenegraph underneath where the shader is
active, the lighting calculations won't be transformed correctly.

I've dug into the OSG source code a bit and found the following:

- special osg_* uniforms are maintained in the State class, the ones
of interest are osg_ModelViewProjectionMatrix, osg_Vertex, etc

- the updating of these uniforms during draw traversal must be enabled
by calling State::setUseModelViewAndProjectionUniforms(true)
  I'm not quite sure where to set this though since States are used in
multiple places, I've tried the following:

    osgViewer::Viewer * viewer = new osgViewer::Viewer;
    osgViewer::Renderer * renderer = dynamic_cast<osgViewer::Renderer
*>(viewer->getCamera()->getRenderer());
    osgUtil::SceneView * sceneView = renderer->getSceneView(0); // Do
this also for 2nd sceneview
    sceneView->setActiveUniforms( osgUtil::SceneView::ALL_UNIFORMS );
    sceneView->getState()->setUseModelViewAndProjectionUniforms(true);


- Modify the shader source to use the special osg_* built-in uniforms:

    osg::ref_ptr<osg::State> state = new osg::State;
    state->convertVertexShaderSourceToOsgBuiltIns( srcString );
    shader->setShaderSource(srcString);

   (Couldn't osg::State::convertVertexShaderSourceToOsgBuiltIns() be a
static method or free function?)

But when I do this, then nothing appears. What am I doing wrong or are
there other things I should be doing?

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

Reply via email to