just a quick thought, but have a look at the code that sets up the
"osg_" predefined GLSL uniforms.  that feature was added pre-OSG 1.0,
and may have drifted during the viewer rework moving into OSG 2.x.
dont know how many folks actually use those uniforms, and thus how
much exercise they get.
-- mew


On Wed, Apr 16, 2008 at 10:51 AM, Jean-Sébastien Guay
<[EMAIL PROTECTED]> wrote:
> Hello,
>
>  In my current project, I have 3 slave cameras rendering to texture with
>  offsets in their view matrices, and then another camera reassembling the
>  images with a deformation to map it onto a half-sphere dome (similar to
>  osgdistortion --dome). I'm trying to fix the problem where
>  view-dependent shading is wrong because the shading uses the slave
>  camera's offset view matrix instead of the master camera's view matrix.
>  You can also see this problem in osgdistortion --dome cow.osg, if you
>  move the cow so that it's on the junction of two cameras, the reflection
>  mapping shows the junction.
>
>  What I'm doing is, right before the draw traversal, I call a function
>  like this:
>
>      void MyClass::updateViewMatrices(osgViewer::CompositeViewer* viewer)
>      {
>          for (unsigned int i = 0; i < viewer->getNumViews(); i++)
>          {
>              osg::Camera* camera = viewer->getView(i)->getCamera();
>              osg::StateSet* stateset = camera->getOrCreateStateSet();
>              osg::Uniform* viewMatrixUniform =
>                  stateset->getUniform("my_CameraViewMatrix");
>              if (!viewMatrixUniform)
>              {
>                  viewMatrixUniform =
>                      new osg::Uniform("my_CameraViewMatrix",
>                                       camera->getViewMatrix());
>                  stateset->addUniform(viewMatrixUniform);
>              }
>              else
>              {
>                  viewMatrixUniform->set(camera->getViewMatrix());
>              }
>          }
>      }
>
>  So this should set a uniform with the main camera's view matrix, which I
>  will want to use in the shader when rendering the slave cameras' views.
>
>  My vertex shader looks like this:
>
>  uniform mat4 osg_ViewMatrixInverse;  // according to glsl_quickref.pdf
>  uniform mat4 my_CameraViewMatrix;
>
>  // ...
>
>  void main (void)
>  {
>      // Calculate the model view matrix relative to the main camera.
>      mat4 modelMatrix = gl_ModelViewMatrix * osg_ViewMatrixInverse;
>      mat4 modelViewMatrix = modelMatrix * my_CameraViewMatrix;
>
>      // Eye-coordinate position of vertex, needed in various calculations
>      // Use our modelview matrix instead of gl_ModelViewMatrix.
>      vec4 ecPosition = modelViewMatrix * gl_Vertex;
>
>      // Do fixed functionality vertex transform
>      gl_Position = ftransform();
>
>
>      // ...
>      // Use ecPosition for shading, shadows and fog
>      // ...
>  }
>
>  Is there any reason why this shouldn't work?
>
>  What I see is that shadows and fog aren't in the right place, and
>  anyways it doesn't fix the view-dependent shading issue I was trying to
>  fix... I suspect my math is wrong (it often is) but I can't spot the
>  problem.
>
>  Suggestions welcome.
>
>  J-S
>  --
>  ______________________________________________________
>  Jean-Sebastien Guay    [EMAIL PROTECTED]
>                                 http://www.cm-labs.com/
>                          http://whitestar02.webhop.org/
>  _______________________________________________
>  osg-users mailing list
>  osg-users@lists.openscenegraph.org
>  http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>



-- 
Mike Weiblen -- Austin Texas USA -- http://mew.cx/
_______________________________________________
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to