Re: [osg-users] Transformation nodes with shaders

2011-05-17 Thread SkullCheck
Hi Robert,

Thanks for the tips and I set the UseModelViewAndProjectionUniforms
flag on the Viewer-Camera-GraphicsContext-State object. However
when I do this then absolutely nothing shows up on screen. Basically
what I've had to do is manually append the view matrix onto each
light's model transformation each frame and that gives the expected
transformation. I'm not really sure why the OSG way isn't working but
will have to debug it later.

Chris

On Mon, May 16, 2011 at 9:50 AM, Robert Osfield
robert.osfi...@gmail.com wrote:
 Hi Chris,

 On Sun, May 15, 2011 at 9:45 AM, SkullCheck csklu...@gmail.com wrote:
 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

 This are drop in replacements for the traditional gl_ variables that
 are provided in
 OpenGL 2.x's GLSL.  These replaements are required for GL3+ (with backwards
 compatibility) and GLES 2 as neither provide the gl_ varaibles.  For a
 GL 2.x app
 it's safe to just target the gl_ variables.

 - 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_castosgViewer::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);

 The osg::State object is held by the GraphicsContext, you don't need
 to go chasing
 up internal implementation details like SceneView.

 If you have just one master camera that maintains the only one
 graphics context the code is simply:

   osg::State* state = viewer.getCamera()-getGraphicsContext()-getState();

 For the GL3 and GLES2 profiles the OSG automaitcally
 setUseModelViewAndProjectionUniforms(true);


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

    osg::ref_ptrosg::State state = new osg::State;
    state-convertVertexShaderSourceToOsgBuiltIns( srcString );
    shader-setShaderSource(srcString);

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

 This method is called when required, you never need to call it
 yourself.  This method is purely there
 to help with backwards compatibility between GL 2.x and GL3/GLES2 apps.

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

 It does sound rather like you might be putting too much effort in, you
 may well be able to
 just use the standard gl_ built-ins.

 Robert.
 ___
 osg-users mailing list
 osg-users@lists.openscenegraph.org
 http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] Transformation nodes with shaders

2011-05-16 Thread Robert Osfield
Hi Chris,

On Sun, May 15, 2011 at 9:45 AM, SkullCheck csklu...@gmail.com wrote:
 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

This are drop in replacements for the traditional gl_ variables that
are provided in
OpenGL 2.x's GLSL.  These replaements are required for GL3+ (with backwards
compatibility) and GLES 2 as neither provide the gl_ varaibles.  For a
GL 2.x app
it's safe to just target the gl_ variables.

 - 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_castosgViewer::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);

The osg::State object is held by the GraphicsContext, you don't need
to go chasing
up internal implementation details like SceneView.

If you have just one master camera that maintains the only one
graphics context the code is simply:

   osg::State* state = viewer.getCamera()-getGraphicsContext()-getState();

For the GL3 and GLES2 profiles the OSG automaitcally
setUseModelViewAndProjectionUniforms(true);


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

    osg::ref_ptrosg::State state = new osg::State;
    state-convertVertexShaderSourceToOsgBuiltIns( srcString );
    shader-setShaderSource(srcString);

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

This method is called when required, you never need to call it
yourself.  This method is purely there
to help with backwards compatibility between GL 2.x and GL3/GLES2 apps.

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

It does sound rather like you might be putting too much effort in, you
may well be able to
just use the standard gl_ built-ins.

Robert.
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org