Hi J-S,
When you start using slave cameras with view offsets/rotation you'll
need to take care over the lighting models used - using a light source
such as a directional head light that is set in eye coordinates and
along eye's z axis you'll find that the effective light direction is
different for each camera. The OSG by default has a directional head
light so you'll hit this problem right away.
Using a light source that is fixed in the world coordinates, or one
that is not directional i.e. a positional light source that is placed
at the eye point resolves the shading problem.
Robert.
On Wed, Apr 16, 2008 at 4:51 PM, 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
> [email protected]
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org