[osg-users] Properties in osg::Camera and values of gl_ModelViewMatrix seem out of sync.

2015-03-25 Thread Robin Wu
Hi all,

Recently, I discovered a weird issue that the view/Proj matrix in the main 
camera updated by the default cameramanipulator of osgViewer does not sync with 
the one I got in the shader, e.g gl_ModelViewMatrix, gl_ProjectionMatrix. 

The following two code snippets produce different results. 
The first one is using the built in gl_ModelViewProjectionMatrix uniform passed 
in during renderingTraversals()

The second one is using the properties from _viewer-getCamera() as uniforms, 
e.g mainCamera-getViewMatrix().


Code:

void main()
{
 gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
}





Code:

uniform mat4 u_modelMatrix;
uniform mat4 u_viewMatrix;
uniform mat4 u_projMatrix;

mat4 getModelToWorldMatrix()
{
 return osg_ViewMatrixInverse * gl_ModelViewMatrix;
}

void main()
{
 gl_Position = u_projMatrix * u_viewMatrix * getModelToWorldMatrix() * 
gl_Vertex;
}




When overlapping the rendering results of the two shaders into one buffer, the 
second shader is approximately one frame slower than the first one, making me 
doubt that the view/proj matrix managed by the main camera is not synced with 
the one managed by the renderingTraversals(). 

This out of sync problem is also pronounced in Wang Rui's effectcompositor. In 
the ssao.xml demo, if you turn on the analysis mode, you'll see that in the 
linearDepth buffer view, the depth is unstable (flickering) when you zoom in 
and out quickly. 

The following is the code snippet from Rui's ssao.xml

Code:

void main(void)
{
 vec4 vecInEye = gl_ModelViewMatrix * gl_Vertex;
 depthValue = (-vecInEye.z - nearPlaneValue) / (farPlaneValue - nearPlaneValue);
 gl_Position = ftransform();
}




I suspect that the nearPlaneValue and farPlaneValue form the built-in 
projection matrix's uniforms are somehow not synced with the corresponding ones 
in gl_ProjectionMatrix ( from ftransfrom() ); 

This problem bugs me for a long time. My current workaround is just using the 
manually supplied uniforms from the main camera. But the extra computation of 
the modelviewprojecionmatrix is definitely a waste in the vertex shader.

Any ideas?

Thank you. 

... 

Robin[/code]

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





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


Re: [osg-users] Render into a QQuickFramebufferObject (osg / osgEarth)

2015-03-25 Thread Sascha Voth
Hi Stefan,

Thank you for your tips and hints, they were pointing me into the right 
direction! Especially the explanation how osg and osgearth handles the 
OpenGLContext was very useful for me! Great!

Regards,
Sascha

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





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


Re: [osg-users] Properties in osg::Camera and values of gl_ModelViewMatrix seem out of sync.

2015-03-25 Thread Robert Osfield
Hi Robin,

I'm a bit perplexed by the issue, as the uniform should be tracking the
modelview matrix directly as osg::State does a substitution.

Could you create a small code example that reproduces the problem?

Robert.

On 25 March 2015 at 01:28, Robin Wu wqxho...@hotmail.com wrote:

 Hi all,

 Recently, I discovered a weird issue that the view/Proj matrix in the main
 camera updated by the default cameramanipulator of osgViewer does not sync
 with the one I got in the shader, e.g gl_ModelViewMatrix,
 gl_ProjectionMatrix.

 The following two code snippets produce different results.
 The first one is using the built in gl_ModelViewProjectionMatrix uniform
 passed in during renderingTraversals()

 The second one is using the properties from _viewer-getCamera() as
 uniforms, e.g mainCamera-getViewMatrix().


 Code:

 void main()
 {
  gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
 }





 Code:

 uniform mat4 u_modelMatrix;
 uniform mat4 u_viewMatrix;
 uniform mat4 u_projMatrix;

 mat4 getModelToWorldMatrix()
 {
  return osg_ViewMatrixInverse * gl_ModelViewMatrix;
 }

 void main()
 {
  gl_Position = u_projMatrix * u_viewMatrix * getModelToWorldMatrix() *
 gl_Vertex;
 }




 When overlapping the rendering results of the two shaders into one buffer,
 the second shader is approximately one frame slower than the first one,
 making me doubt that the view/proj matrix managed by the main camera is not
 synced with the one managed by the renderingTraversals().

 This out of sync problem is also pronounced in Wang Rui's
 effectcompositor. In the ssao.xml demo, if you turn on the analysis mode,
 you'll see that in the linearDepth buffer view, the depth is unstable
 (flickering) when you zoom in and out quickly.

 The following is the code snippet from Rui's ssao.xml

 Code:

 void main(void)
 {
  vec4 vecInEye = gl_ModelViewMatrix * gl_Vertex;
  depthValue = (-vecInEye.z - nearPlaneValue) / (farPlaneValue -
 nearPlaneValue);
  gl_Position = ftransform();
 }




 I suspect that the nearPlaneValue and farPlaneValue form the built-in
 projection matrix's uniforms are somehow not synced with the corresponding
 ones in gl_ProjectionMatrix ( from ftransfrom() );

 This problem bugs me for a long time. My current workaround is just using
 the manually supplied uniforms from the main camera. But the extra
 computation of the modelviewprojecionmatrix is definitely a waste in the
 vertex shader.

 Any ideas?

 Thank you.

 ...

 Robin[/code]

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





 ___
 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


[osg-users] How to rotate a osg::Text heading when camera changes?

2015-03-25 Thread Lv Qing
Hi,

[Image: http://forum.osgearth.org/file/n7587273/无标题.jpg ]
... 
like pictures above,we use some icon to display a plane,this icon is osg::Text 
which using some special fonts file.we dynamic set this plane's  heading  to 
this osg::Text,like the left picture ,if the camera head to north,this 
osg::Text looks like head to the plane's  heading.If we rotate the camera  a 
bit ,like right pitcure ,it dosen't work. 
I know the reason,but not to know how to solve it .is there some way to 
re-computer the osg::Text heading when camera angle changes? 

Thank you!

Cheers,
Lv

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





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


[osg-users] flash the DatabasePager on demmand

2015-03-25 Thread Trajce Nikolov NICK
Hi community,

is there a way to flush (discard) the currently pending PagedLODs with a
call? I read the class and didn;t found anything

Thanks a bunch as always!

Nick

-- 
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] flash the DatabasePager on demmand

2015-03-25 Thread Trajce Nikolov NICK
okay :-) .. maybe someone else will come up with a hint

Thanks anyway

Nick

On Wed, Mar 25, 2015 at 6:51 PM, Robert Osfield robert.osfi...@gmail.com
wrote:

 Hi Nick,

 I'm afraid I don't have any ideas off the top of my head.  Too many other
 complex things on my table to handle pontificating on anything else
 complicated right now.

 Robert.

 On 25 March 2015 at 17:24, Trajce Nikolov NICK 
 trajce.nikolov.n...@gmail.com wrote:

 Hi Robert,

 here is my situation. My client has large UTM database. Their IOS
 software needs to offset the database for each mission, so I have a
 NodeVisitor that apply some positinal offset to Geometry/Matrices/LODs. And
 there is a ReadCallback that uses this offset too. This works great, I can
 offset tiles that are loaded and to be loaded dynamically. However, I dont
 have control on the PagedLODs that are loading in between changing the
 offset, so these new tiles do not catch the correct offset. Any hint/hack
 for this situation? This is what I think is going on, not 100% sure though

 Thanks a lot!

 Nick

 On Wed, Mar 25, 2015 at 5:24 PM, Robert Osfield robert.osfi...@gmail.com
  wrote:

 HI Nick,

 I don't recall a method call to explicitly discards all pending
 DatabaseRequests.

 The DatabasePager discards DatabaseRequest's automatically if they
 aren't been refreshed by PagedLOD's that need them - this is done by
 tracking the frame number that of when the cull traversal hits a PagedLOD
 and requests a child.

 Robert.

 On 25 March 2015 at 16:04, Trajce Nikolov NICK 
 trajce.nikolov.n...@gmail.com wrote:

 Hi community,

 is there a way to flush (discard) the currently pending PagedLODs with
 a call? I read the class and didn;t found anything

 Thanks a bunch as always!

 Nick

 --
 trajce nikolov nick

 ___
 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




 --
 trajce nikolov nick

 ___
 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




-- 
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] flash the DatabasePager on demmand

2015-03-25 Thread Robert Osfield
HI Nick,

I don't recall a method call to explicitly discards all pending
DatabaseRequests.

The DatabasePager discards DatabaseRequest's automatically if they aren't
been refreshed by PagedLOD's that need them - this is done by tracking the
frame number that of when the cull traversal hits a PagedLOD and requests a
child.

Robert.

On 25 March 2015 at 16:04, Trajce Nikolov NICK 
trajce.nikolov.n...@gmail.com wrote:

 Hi community,

 is there a way to flush (discard) the currently pending PagedLODs with a
 call? I read the class and didn;t found anything

 Thanks a bunch as always!

 Nick

 --
 trajce nikolov nick

 ___
 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] flash the DatabasePager on demmand

2015-03-25 Thread Trajce Nikolov NICK
Hi Robert,

here is my situation. My client has large UTM database. Their IOS software
needs to offset the database for each mission, so I have a NodeVisitor that
apply some positinal offset to Geometry/Matrices/LODs. And there is a
ReadCallback that uses this offset too. This works great, I can offset
tiles that are loaded and to be loaded dynamically. However, I dont have
control on the PagedLODs that are loading in between changing the offset,
so these new tiles do not catch the correct offset. Any hint/hack for this
situation? This is what I think is going on, not 100% sure though

Thanks a lot!

Nick

On Wed, Mar 25, 2015 at 5:24 PM, Robert Osfield robert.osfi...@gmail.com
wrote:

 HI Nick,

 I don't recall a method call to explicitly discards all pending
 DatabaseRequests.

 The DatabasePager discards DatabaseRequest's automatically if they aren't
 been refreshed by PagedLOD's that need them - this is done by tracking the
 frame number that of when the cull traversal hits a PagedLOD and requests a
 child.

 Robert.

 On 25 March 2015 at 16:04, Trajce Nikolov NICK 
 trajce.nikolov.n...@gmail.com wrote:

 Hi community,

 is there a way to flush (discard) the currently pending PagedLODs with a
 call? I read the class and didn;t found anything

 Thanks a bunch as always!

 Nick

 --
 trajce nikolov nick

 ___
 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




-- 
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] flash the DatabasePager on demmand

2015-03-25 Thread Robert Osfield
Hi Nick,

I'm afraid I don't have any ideas off the top of my head.  Too many other
complex things on my table to handle pontificating on anything else
complicated right now.

Robert.

On 25 March 2015 at 17:24, Trajce Nikolov NICK 
trajce.nikolov.n...@gmail.com wrote:

 Hi Robert,

 here is my situation. My client has large UTM database. Their IOS software
 needs to offset the database for each mission, so I have a NodeVisitor that
 apply some positinal offset to Geometry/Matrices/LODs. And there is a
 ReadCallback that uses this offset too. This works great, I can offset
 tiles that are loaded and to be loaded dynamically. However, I dont have
 control on the PagedLODs that are loading in between changing the offset,
 so these new tiles do not catch the correct offset. Any hint/hack for this
 situation? This is what I think is going on, not 100% sure though

 Thanks a lot!

 Nick

 On Wed, Mar 25, 2015 at 5:24 PM, Robert Osfield robert.osfi...@gmail.com
 wrote:

 HI Nick,

 I don't recall a method call to explicitly discards all pending
 DatabaseRequests.

 The DatabasePager discards DatabaseRequest's automatically if they aren't
 been refreshed by PagedLOD's that need them - this is done by tracking the
 frame number that of when the cull traversal hits a PagedLOD and requests a
 child.

 Robert.

 On 25 March 2015 at 16:04, Trajce Nikolov NICK 
 trajce.nikolov.n...@gmail.com wrote:

 Hi community,

 is there a way to flush (discard) the currently pending PagedLODs with a
 call? I read the class and didn;t found anything

 Thanks a bunch as always!

 Nick

 --
 trajce nikolov nick

 ___
 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




 --
 trajce nikolov nick

 ___
 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


[osg-users] embed osgViewer into FLTK window...

2015-03-25 Thread Shayne Tueller
All,

I'm trying to embed an osgViewer that has a transparent background into an FLTK 
main window. The embedded osgViewer needs to have a transparent background so 
that I can see the parent window behind it.

Is this even possible?

What I'm trying to do is use the osgViewer as an overlay to render symbology on 
top of the main parent FLTK window. I've looked at the osgViewerFLTK example 
and the osgHUD example but nothing has worked so far.

Any suggestions or help would be appreciated...

Shayne

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





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


[osg-users] Negative Parallax

2015-03-25 Thread Leonardo Rocha
Hi,

I am working in a research project where the scene is rendered in two TVs with 
a 120 degree angle between them. The objective is to emulate an hologram using 
3d stereo vision and the fishtank formed by the TVs. I am setting each view 
with different view and projection matrices, similar as described in 
Generalized Perspective Projection by Robert Kooima,
using slave cameras. My questions are regarding the following: 

1) Is there any way to set a negative parallax to the entire scene while 
keeping fixed in the origin? This is necessary to keep the scene fixed, and the 
only view transforms are the rotation of the view frustums in order to align 
them with the TVs, as in the paper linked above.  I've already tried 
billboarding,  vextex shader program, and setting the fusionDistance. Any good 
results so far.

2) Is there any way to set  the slave projection matrix (using the math 
described in the link), with non-perpendicular offsets (of the projection 
pyramid) so I keep the main projection transform in the main camera´s 
projection matrix (and use the standard slaveCallback, maybe)?


Thank you!

Cheers,
Leonardo

Ps. The image attached is old but shows the idea of the setup.

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




Attachments: 
http://forum.openscenegraph.org//files/stereo_frustum_165.png


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


Re: [osg-users] Properties in osg::Camera and values of gl_ModelViewMatrix seem out of sync.

2015-03-25 Thread Robin Wu
Hi Robert, 

Thank you for replying.

Here is the example code. 
shader1.vert

Code:

#version 120
varying vec4 v_color;

void main()
{
v_color = gl_Color;
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
}




shader2.vert

Code:

#version 120

uniform mat4 u_viewMatrix;
uniform mat4 u_projMatrix;
uniform mat4 osg_ViewMatrixInverse;

varying vec4 v_color;

mat4 getModelToWorldMatrix()
{
return osg_ViewMatrixInverse * gl_ModelViewMatrix;
}

void main()
{
v_color = gl_Color;
gl_Position = u_projMatrix * u_viewMatrix * getModelToWorldMatrix() * 
gl_Vertex;
}




shader.frag

Code:

#version 120

varying vec4 v_color;

void main()
{
gl_FragColor = v_color;
}




main.cpp

Code:

#include osgDB/ReadFile
#include osgViewer/Viewer
#include osg/StateAttributeCallback
#include osg/Shape
#include osg/ShapeDrawable

class StateNodeCallback : public osg::StateSet::Callback
{
public:
StateNodeCallback(osg::Camera *mainCamera) : _mainCamera(mainCamera) {}
virtual void operator () (osg::StateSet*ss, osg::NodeVisitor*nv)
{

ss-getUniform(u_projMatrix)-set(osg::Matrixf(_mainCamera-getProjectionMatrix()));

ss-getUniform(u_viewMatrix)-set(osg::Matrixf(_mainCamera-getViewMatrix()));
}

private:
osg::ref_ptrosg::Camera _mainCamera;
};

osg::Geode *createCylinder(const osg::Vec4 color)
{   
osg::ref_ptrosg::Cylinder cylinder = new osg::Cylinder;
cylinder-setHeight(10.0f);
osg::ref_ptrosg::ShapeDrawable sd = new osg::ShapeDrawable;
sd-setShape(cylinder);
sd-setColor(color);
osg::ref_ptrosg::Geode geode = new osg::Geode;
geode-addDrawable(sd);
return geode.release();
}

int main()
{
osgViewer::Viewer viewer;

osg::ref_ptrosg::Geode cylinder1 = createCylinder(osg::Vec4(1, 0, 0, 
1));
osg::ref_ptrosg::Geode cylinder2 = createCylinder(osg::Vec4(0, 1, 0, 
1));

osg::ref_ptrosg::Program shader1 = new osg::Program();
shader1-addShader(osgDB::readShaderFile(shader1.vert));
shader1-addShader(osgDB::readShaderFile(shader.frag));

osg::ref_ptrosg::Program shader2 = new osg::Program();
shader2-addShader(osgDB::readShaderFile(shader2.vert));
shader2-addShader(osgDB::readShaderFile(shader.frag));

osg::ref_ptrosg::Group group1 = new osg::Group();
osg::ref_ptrosg::Group group2 = new osg::Group();
group1-addChild(cylinder1);
group2-addChild(cylinder2);

group1-getOrCreateStateSet()-setAttributeAndModes(shader1, 
osg::StateAttribute::ON | osg::StateAttribute::OVERRIDE);
group2-getOrCreateStateSet()-setAttributeAndModes(shader2, 
osg::StateAttribute::ON | osg::StateAttribute::OVERRIDE);

osg::ref_ptrosg::Camera mainCamera = viewer.getCamera();
group2-getOrCreateStateSet()-setUpdateCallback(new 
StateNodeCallback(mainCamera));
group2-getOrCreateStateSet()-addUniform(new 
osg::Uniform(u_projMatrix, osg::Matrixf(mainCamera-getProjectionMatrix(;
group2-getOrCreateStateSet()-addUniform(new 
osg::Uniform(u_viewMatrix, osg::Matrixf(mainCamera-getViewMatrix(;

osg::ref_ptrosg::Group root = new osg::Group();
root-addChild(group1);
root-addChild(group2);

viewer.setSceneData(root);

viewer.run();
}




Make sure to set OSG_RUN_MAX_FRAME_RATE environment variable to a low value, 
like 20, in order to better expose this issue.

I also attached a screen shot and the source code

... 

Thank you!

Robin



robertosfield wrote:
 Hi Robin,
 
 
 I'm a bit perplexed by the issue, as the uniform should be tracking the 
 modelview matrix directly as osg::State does a substitution.
 
 
 Could you create a small code example that reproduces the problem?
 
 
 Robert.
 
 
 On 25 March 2015 at 01:28, Robin Wu  () wrote:
 
  Hi all,
  
  Recently, I discovered a weird issue that the view/Proj matrix in the main 
  camera updated by the default cameramanipulator of osgViewer does not sync 
  with the one I got in the shader, e.g gl_ModelViewMatrix, 
  gl_ProjectionMatrix.
  
  The following two code snippets produce different results.
  The first one is using the built in gl_ModelViewProjectionMatrix uniform 
  passed in during renderingTraversals()
  
  The second one is using the properties from _viewer-getCamera() as 
  uniforms, e.g mainCamera-getViewMatrix().
  
  
  Code:
  
  void main()
  {
   gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
  }
  
  
  
  
  
  Code:
  
  uniform mat4 u_modelMatrix;
  uniform mat4 u_viewMatrix;
  uniform mat4 u_projMatrix;
  
  mat4 getModelToWorldMatrix()
  {
   return osg_ViewMatrixInverse * gl_ModelViewMatrix;
  }
  
  void main()
  {
   gl_Position = u_projMatrix * u_viewMatrix * getModelToWorldMatrix() * 
  gl_Vertex;
  }
  
  
  
  
  When overlapping the rendering results of the two shaders into one buffer, 
  the second shader is