Re: [osg-users] Lagging between main camera MV and prerender camera

2015-01-12 Thread Daniel Schmid
Hi all

I solved the problem! Actually the mistake I made is that the uniform holding 
the texture-matrix was added to the stateset of the root node. Instead I had to 
dive into the ShadowedScene, find the stateset of the shadow receiving scene 
part and add the matrix (and the prerendered texture) there. 
Now everything is working fine...

Cheers,
Daniel

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=62303#62303





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


Re: [osg-users] Lagging between main camera MV and prerender camera

2014-12-15 Thread Robert Osfield
Hi Daniel,

If you aren't modifying the modelview matrix in cull then at least in
theory using that value should be safe.

If modelview matrix usage is OK, then my best alternative guess would be
that your render to texture pass is not being done prior to the rendering
of the main scene.  You have to set Render to Texture the
Camera::RenderOrder to PRE_RENDER to make sure it's drawn first.

Robert.

On 15 December 2014 at 07:01, Daniel Schmid daniel.sch...@swiss-simtec.ch
wrote:

 Hi Robert

 I do all my matrix calculations in the cull, which is renderTraversal. I
 don't understand why the camera matrices shouldn't be correct at this
 time...



 Code:

 void EfxTracksPrerenderer::ViewData::cull(osgUtil::CullVisitor* a_cv)
 {
   osg::NodePath l_NodePath = a_cv-getNodePath();
   osg::Node* l_Root = l_NodePath.front();

   osg::StateSet* l_StateSet = l_Root-getStateSet();

   osg::Camera* l_MainCamera = a_cv-getCurrentCamera();

   osg::Matrixd l_MainViewMatrix  =
 (*a_cv-getModelViewMatrix());//l_MainCamera-getViewMatrix();
   osg::Matrixd l_MainProjMatrix  =
 (*a_cv-getProjectionMatrix());//l_MainCamera-getProjectionMatrix();


   osg::Matrix l_ViewMatrix;
   osg::Matrix l_ProjMatrix;

   osg::Vec3d eyePos, centerPos, upPos;
   l_MainViewMatrix.getLookAt(eyePos, centerPos, upPos);

   // calculate the eye dir vector
   osg::Vec3 eyeDir = centerPos - eyePos;
   eyeDir.normalize();

   // do post perpspective setup of view and projection matrices
   // here...

   m_Camera-setProjectionMatrix(l_ProjMatrix);
   m_Camera-setViewMatrix(l_ViewMatrix);

   // compute the matrix which takes a vertex from local coords into tex
 coords
   // will use this later to specify osg::TexGen..
   osg::Matrix MVP = m_Camera-getViewMatrix() *
 m_Camera-getProjectionMatrix();

   osg::Matrix MVPT = l_MainCamera-getInverseViewMatrix() *
  MVP *
  osg::Matrix::translate(1.0,1.0,1.0) *
  osg::Matrix::scale(0.5,0.5,0.5);

   m_TextureMatrix = MVPT;

   m_Camera-accept(*a_cv);

 }




 As you see above, I tried with getCurrentCamera and also getting the
 matrices from the CullVisitior, which gives identical results.

 So I kind of don't understand the issue between updateTraversal and
 renderTraversal. I'm probably missing something... I do all my calc in
 Cull. The only potential problem I could imagine is because I have a cull
 thread and a parallel draw thread, and the matrices are not correctly used?
 I out of ideas...[/quote]

 --
 Read this topic online here:
 http://forum.openscenegraph.org/viewtopic.php?p=62055#62055





 ___
 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] Lagging between main camera MV and prerender camera

2014-12-14 Thread Daniel Schmid
Hi Robert

I do all my matrix calculations in the cull, which is renderTraversal. I don't 
understand why the camera matrices shouldn't be correct at this time...



Code:

void EfxTracksPrerenderer::ViewData::cull(osgUtil::CullVisitor* a_cv)
{
  osg::NodePath l_NodePath = a_cv-getNodePath();
  osg::Node* l_Root = l_NodePath.front();

  osg::StateSet* l_StateSet = l_Root-getStateSet();

  osg::Camera* l_MainCamera = a_cv-getCurrentCamera();

  osg::Matrixd l_MainViewMatrix  = 
(*a_cv-getModelViewMatrix());//l_MainCamera-getViewMatrix();
  osg::Matrixd l_MainProjMatrix  = 
(*a_cv-getProjectionMatrix());//l_MainCamera-getProjectionMatrix();


  osg::Matrix l_ViewMatrix;
  osg::Matrix l_ProjMatrix;

  osg::Vec3d eyePos, centerPos, upPos;
  l_MainViewMatrix.getLookAt(eyePos, centerPos, upPos);

  // calculate the eye dir vector
  osg::Vec3 eyeDir = centerPos - eyePos;
  eyeDir.normalize();

  // do post perpspective setup of view and projection matrices
  // here... 

  m_Camera-setProjectionMatrix(l_ProjMatrix);
  m_Camera-setViewMatrix(l_ViewMatrix);

  // compute the matrix which takes a vertex from local coords into tex coords
  // will use this later to specify osg::TexGen..
  osg::Matrix MVP = m_Camera-getViewMatrix() *
m_Camera-getProjectionMatrix();

  osg::Matrix MVPT = l_MainCamera-getInverseViewMatrix() *
 MVP *
 osg::Matrix::translate(1.0,1.0,1.0) *
 osg::Matrix::scale(0.5,0.5,0.5);

  m_TextureMatrix = MVPT;

  m_Camera-accept(*a_cv);

}




As you see above, I tried with getCurrentCamera and also getting the matrices 
from the CullVisitior, which gives identical results.

So I kind of don't understand the issue between updateTraversal and 
renderTraversal. I'm probably missing something... I do all my calc in Cull. 
The only potential problem I could imagine is because I have a cull thread and 
a parallel draw thread, and the matrices are not correctly used? I out of 
ideas...[/quote]

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=62055#62055





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


Re: [osg-users] Lagging between main camera MV and prerender camera

2014-12-12 Thread Trajce Nikolov NICK
Hi Daniel,

I faced the same problem

http://forum.openscenegraph.org/viewtopic.php?t=14354

How I fixed and hints from Robert. Hope it helps

Nick

On Fri, Dec 12, 2014 at 4:08 PM, Daniel Schmid 
daniel.sch...@swiss-simtec.ch wrote:

 Hi all

 Trust me, I searched the forum for a hint but couldn't find stuff that
 could point me into a solution...
 To understand the situation, please have a look at the screenshot.
 I have tracks from a vehicle that are prerendered into a texture, and then
 blended with underground during the main shader. Everything works fine and
 I'm happy with the visual result.

 But there is one problem...
 As soon as I move (rotate) my main camera, the track texture starts to lag
 with the underground, it looks like if the modelview matrix are nomore in
 sync.

 Technical details:

 The model view and projection matrices for the prerender camera are
 calculated and passed into a uniform :


 Code:

 ...
 osg::Matrix MVP = m_Camera-getViewMatrix() *
 m_Camera-getProjectionMatrix();

 osg::Matrix MVPT = l_MainCamera-getInverseViewMatrix() * MVP *
 osg::Matrix::translate(1.0,1.0,1.0) * osg::Matrix::scale(0.5,0.5,0.5);

 m_TextureMatrix = MVPT;

 m_Camera-accept(*a_cv);
 ...




 The uniform with the textureMatrix is added to the root scene nodes
 stateset. In the shader, I calculate the TextureMatrix:


 Code:

 vec4 ecPos = gl_ModelViewMatrix * gl_Vertex;
 TexCoordTracksmap = tracksmapTextureMatrix * ecPos;




 What is the reason for the lagging? What do I have to consider? By the way
 I use ViewDependentShadowMap, and it also uses prerender camera and they
 don't produce lagging shadow, so there has to be a solution.

 Can anybody help?[/code]

 --
 Read this topic online here:
 http://forum.openscenegraph.org/viewtopic.php?p=62044#62044




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



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


Re: [osg-users] Lagging between main camera MV and prerender camera

2014-12-12 Thread Robert Osfield
Hi Daniel,

Sounds like you are doing updating the m_TextureMatrix prior to the main
Camera being updated.  By default the Viewer::updateTraversal() gets the
modelview matrix from the CameraManipulator after the update traversal.
Some camera manipulators track nodes in the scene so have to be called
after the scene has been updated.

In your own app you could override Viewer::updateTraversal() and set up the
update order as you prefer, or do an update of the m_TextureMatrix after
the Viewer::updateTraversal() or force the update of the Camera matrix from
the Camera manipulator prior to the call to Viewer::updateTraversal().

Robert.

On 12 December 2014 at 15:08, Daniel Schmid daniel.sch...@swiss-simtec.ch
wrote:

 Hi all

 Trust me, I searched the forum for a hint but couldn't find stuff that
 could point me into a solution...
 To understand the situation, please have a look at the screenshot.
 I have tracks from a vehicle that are prerendered into a texture, and then
 blended with underground during the main shader. Everything works fine and
 I'm happy with the visual result.

 But there is one problem...
 As soon as I move (rotate) my main camera, the track texture starts to lag
 with the underground, it looks like if the modelview matrix are nomore in
 sync.

 Technical details:

 The model view and projection matrices for the prerender camera are
 calculated and passed into a uniform :


 Code:

 ...
 osg::Matrix MVP = m_Camera-getViewMatrix() *
 m_Camera-getProjectionMatrix();

 osg::Matrix MVPT = l_MainCamera-getInverseViewMatrix() * MVP *
 osg::Matrix::translate(1.0,1.0,1.0) * osg::Matrix::scale(0.5,0.5,0.5);

 m_TextureMatrix = MVPT;

 m_Camera-accept(*a_cv);
 ...




 The uniform with the textureMatrix is added to the root scene nodes
 stateset. In the shader, I calculate the TextureMatrix:


 Code:

 vec4 ecPos = gl_ModelViewMatrix * gl_Vertex;
 TexCoordTracksmap = tracksmapTextureMatrix * ecPos;




 What is the reason for the lagging? What do I have to consider? By the way
 I use ViewDependentShadowMap, and it also uses prerender camera and they
 don't produce lagging shadow, so there has to be a solution.

 Can anybody help?[/code]

 --
 Read this topic online here:
 http://forum.openscenegraph.org/viewtopic.php?p=62044#62044




 ___
 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