OpenSceneGraph Forum Forum Index OpenSceneGraph Forum
Official forum which mirrors the existent OSG mailing lists. Messages posted here are forwarded to the mailing list and vice versa.
 
   FAQFAQ    SearchSearch    MemberlistMemberlist    RulesRules    UsergroupsUsergroups    RegisterRegister 
 Mail2Forum SettingsMail2Forum Settings  ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
   AlbumAlbum  OpenSceneGraph IRC ChatOpenSceneGraph IRC Chat   SmartFeedSmartFeed 

Shader Update Latency?!


 
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> General
View previous topic :: View next topic  
Author Message
Thorsten Roth
Guest





PostPosted: Wed Dec 01, 2010 6:15 pm    Post subject:
Shader Update Latency?!
Reply with quote

Hi,

I currently have a problem with a shader update callback I do not
understand. I have a vertex and fragment shader which calculate linear
depth in [0,1] for me, also respecting dynamic clipping planes. To
achieve this, I pass zNear and zFar as uniform parameters to the shader.
To have them updated, I have the following callback methods (zFar is
looking accordingly):

class UpdateShaderZNear: public osg::Uniform::Callback {
public:
virtual void operator()(osg::Uniform* uniform, osg::NodeVisitor* nv) {
double x, zNear;
viewer->getCamera()->getProjectionMatrixAsPerspective(x,x,zNear,x);
uniform->set((float)zFar);
}
};

Now when I move my camera towards and away from the object, it seems
like the shader update is one frame (or so) "too late", as I get values
that do not correspond to the [0,1]-normalization and the problem
disappears as soon as the camera stops.

Is there any reason for that/does anyone have an idea what I'm doing
wrong? If more information or code is necessary, just tell me :-)

-Thorsten


------------------
Post generated by Mail2Forum
Back to top
Tim Moore
Guest





PostPosted: Wed Dec 01, 2010 6:22 pm    Post subject:
Shader Update Latency?!
Reply with quote

Have you set the data variance of the Uniform object -- and the containing StateSet object -- to Object::DYNAMIC?

Tim

On Wed, Dec 1, 2010 at 7:15 PM, Thorsten Roth < (
Only registered users can see emails on this board!
Get registred or enter the forums!
)> wrote:
Quote:
Hi,

I currently have a problem with a shader update callback I do not understand. I have a vertex and fragment shader which calculate linear depth in [0,1] for me, also respecting dynamic clipping planes. To achieve this, I pass zNear and zFar as uniform parameters to the shader. To have them updated, I have the following callback methods (zFar is looking accordingly):

class UpdateShaderZNear: public osg::Uniform::Callback {
public:
       virtual void operator()(osg::Uniform* uniform, osg::NodeVisitor* nv) {
               double x, zNear;
       viewer->getCamera()->getProjectionMatrixAsPerspective(x,x,zNear,x);
               uniform->set((float)zFar);
       }
};

Now when I move my camera towards and away from the object, it seems like the shader update is one frame (or so) "too late", as I get values that do not correspond to the [0,1]-normalization and the problem disappears as soon as the camera stops.

Is there any reason for that/does anyone have an idea what I'm doing wrong? If more information or code is necessary, just tell me Smile

-Thorsten
_______________________________________________
osg-users mailing list
(
Only registered users can see emails on this board!
Get registred or enter the forums!
)
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


------------------
Post generated by Mail2Forum
Back to top
Thorsten Roth
Guest





PostPosted: Wed Dec 01, 2010 6:37 pm    Post subject:
Shader Update Latency?!
Reply with quote

I have actually tried it now, but it made no difference :-(

-Thorsten

Am 01.12.2010 19:22, schrieb Tim Moore:
Quote:
Have you set the data variance of the Uniform object -- and the
containing StateSet object -- to Object::DYNAMIC?

Tim

On Wed, Dec 1, 2010 at 7:15 PM, Thorsten Roth <
<mailto:>> wrote:

Hi,

I currently have a problem with a shader update callback I do not
understand. I have a vertex and fragment shader which calculate
linear depth in [0,1] for me, also respecting dynamic clipping
planes. To achieve this, I pass zNear and zFar as uniform parameters
to the shader. To have them updated, I have the following callback
methods (zFar is looking accordingly):

class UpdateShaderZNear: public osg::Uniform::Callback {
public:
virtual void operator()(osg::Uniform* uniform,
osg::NodeVisitor* nv) {
double x, zNear;

viewer->getCamera()->getProjectionMatrixAsPerspective(x,x,zNear,x);
uniform->set((float)zFar);
}
};

Now when I move my camera towards and away from the object, it seems
like the shader update is one frame (or so) "too late", as I get
values that do not correspond to the [0,1]-normalization and the
problem disappears as soon as the camera stops.

Is there any reason for that/does anyone have an idea what I'm doing
wrong? If more information or code is necessary, just tell me :-)

-Thorsten
_______________________________________________
osg-users mailing list

<mailto:>
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org







------------------
Post generated by Mail2Forum
Back to top
robertosfield
OSG Project Lead


Joined: 18 Mar 2009
Posts: 12206

PostPosted: Wed Dec 01, 2010 7:52 pm    Post subject:
Shader Update Latency?!
Reply with quote

Hi Thorsten,

By default the OSG computes the near/far planes on the fly during the
cull traversal on every single frame. You can disable this.
Alternatively you could just use the gl_ProjectionMatrix directly on
the GPU to get the near/far planes - this is how I'd do it, far more
flexible and never needs any additional uniforms or callbacks.

Robert.

On Wed, Dec 1, 2010 at 6:15 PM, Thorsten Roth <> wrote:
Quote:
Hi,

I currently have a problem with a shader update callback I do not
understand. I have a vertex and fragment shader which calculate linear depth
in [0,1] for me, also respecting dynamic clipping planes. To achieve this, I
pass zNear and zFar as uniform parameters to the shader. To have them
updated, I have the following callback methods (zFar is looking
accordingly):

class UpdateShaderZNear: public osg::Uniform::Callback {
public:
       virtual void operator()(osg::Uniform* uniform, osg::NodeVisitor* nv)
{
               double x, zNear;
       viewer->getCamera()->getProjectionMatrixAsPerspective(x,x,zNear,x);
               uniform->set((float)zFar);
       }
};

Now when I move my camera towards and away from the object, it seems like
the shader update is one frame (or so) "too late", as I get values that do
not correspond to the [0,1]-normalization and the problem disappears as soon
as the camera stops.

Is there any reason for that/does anyone have an idea what I'm doing wrong?
If more information or code is necessary, just tell me :-)

-Thorsten




------------------
Post generated by Mail2Forum
Back to top
View user's profile Send private message
Thorsten Roth
Guest





PostPosted: Wed Dec 01, 2010 7:55 pm    Post subject:
Shader Update Latency?!
Reply with quote

Hi Robert,

thank you for this information. I did not know that I could do this, as
I'm an absolute newbie concerning shader stuff and was happy that I just
got it to work somehow ;)

I will try the approach with gl_ProjectionMatrix tomorrow, thank you :)

-Thorsten

Am 01.12.2010 20:51, schrieb Robert Osfield:
Quote:
Hi Thorsten,

By default the OSG computes the near/far planes on the fly during the
cull traversal on every single frame. You can disable this.
Alternatively you could just use the gl_ProjectionMatrix directly on
the GPU to get the near/far planes - this is how I'd do it, far more
flexible and never needs any additional uniforms or callbacks.

Robert.

On Wed, Dec 1, 2010 at 6:15 PM, Thorsten Roth<> wrote:
Quote:
Hi,

I currently have a problem with a shader update callback I do not
understand. I have a vertex and fragment shader which calculate linear depth
in [0,1] for me, also respecting dynamic clipping planes. To achieve this, I
pass zNear and zFar as uniform parameters to the shader. To have them
updated, I have the following callback methods (zFar is looking
accordingly):

class UpdateShaderZNear: public osg::Uniform::Callback {
public:
virtual void operator()(osg::Uniform* uniform, osg::NodeVisitor* nv)
{
double x, zNear;
viewer->getCamera()->getProjectionMatrixAsPerspective(x,x,zNear,x);
uniform->set((float)zFar);
}
};

Now when I move my camera towards and away from the object, it seems like
the shader update is one frame (or so) "too late", as I get values that do
not correspond to the [0,1]-normalization and the problem disappears as soon
as the camera stops.

Is there any reason for that/does anyone have an idea what I'm doing wrong?
If more information or code is necessary, just tell me :-)

-Thorsten





------------------
Post generated by Mail2Forum
Back to top
Guo Chow
Guest





PostPosted: Wed Jan 12, 2011 7:10 am    Post subject:
Shader Update Latency?!
Reply with quote

Robert Osfield <robert.osfield@...> writes:

Quote:

Hi Thorsten,

By default the OSG computes the near/far planes on the fly during the
cull traversal on every single frame. You can disable this.
Alternatively you could just use the gl_ProjectionMatrix directly on
the GPU to get the near/far planes - this is how I'd do it, far more
flexible and never needs any additional uniforms or callbacks.

Robert.

On Wed, Dec 1, 2010 at 6:15 PM, Thorsten Roth
<thorsten.roth@...> wrote:
Quote:
Hi,

I currently have a problem with a shader update callback I do not
understand. I have a vertex and fragment shader which calculate linear
depth
Quote:
Quote:
in [0,1] for me, also respecting dynamic clipping planes. To achieve this,
I
Quote:
Quote:
pass zNear and zFar as uniform parameters to the shader. To have them
updated, I have the following callback methods (zFar is looking
accordingly):

class UpdateShaderZNear: public osg::Uniform::Callback {
public:
       virtual void operator()(osg::Uniform* uniform, osg::NodeVisitor* nv)
{
               double x, zNear;
       viewer->getCamera()->getProjectionMatrixAsPerspective(x,x,zNear,x);
               uniform->set((float)zFar);
       }
};

Now when I move my camera towards and away from the object, it seems like
the shader update is one frame (or so) "too late", as I get values that do
not correspond to the [0,1]-normalization and the problem disappears as
soon
Quote:
Quote:
as the camera stops.

Is there any reason for that/does anyone have an idea what I'm doing wrong?
If more information or code is necessary, just tell me

-Thorsten




Hi Robert,

I encounter a similar latency problem when I try to update a uniform using
camera's view matrix in the uniform's callback. Since this uniform is needed
to compute only once per frame, I decide to compute it on CPU before it's
submitted to GPU.

It seems that when the uniform's callback is called, the camera has not been
updated yet, right?

Currently I solve this problem by updating the uniform in a PreDrawCallback of
the camera. But is this a graceful way to achieve it?

Thanks in advance.

Guo



------------------
Post generated by Mail2Forum
Back to top
robertosfield
OSG Project Lead


Joined: 18 Mar 2009
Posts: 12206

PostPosted: Wed Jan 12, 2011 9:13 am    Post subject:
Shader Update Latency?!
Reply with quote

Hi Guo,

On Wed, Jan 12, 2011 at 7:04 AM, Guo Chow <> wrote:
Quote:
I encounter a similar latency problem when I try to update a uniform using
camera's view matrix in the uniform's callback. Since this uniform is needed
to compute only once per frame, I decide to compute it on CPU before it's
submitted to GPU.

It seems that when the uniform's callback is called, the camera has not been
updated yet, right?

Currently I solve this problem by updating the uniform in a PreDrawCallback of
the camera. But is this a graceful way to achieve it?

By default the osgViewer::Viewer/CompositeViewer runs the update
traversal before the camera matrices are set, this is done as camera
manipulators might be tracking movement of nodes in the scene which
are update in the update traversal so has to be run second.

One thing you could do is set the camera view matrix prior to the
updateTraversal() method is called, or do the update of your Uniforms
explicitly after the updateTraversal().

Robert.


------------------
Post generated by Mail2Forum
Back to top
View user's profile Send private message
Steal
User


Joined: 26 Jan 2017
Posts: 78

PostPosted: Sat Feb 11, 2017 7:05 pm    Post subject:
Reply with quote

Hi,

This problem affects my shaders, since all my shaders rely on the correct view matrices.

robertosfield wrote:

By default the osgViewer::Viewer/CompositeViewer runs the update
traversal before the camera matrices are set, this is done as camera
manipulators might be tracking movement of nodes in the scene which
are update in the update traversal so has to be run second.

One thing you could do is set the camera view matrix prior to the
updateTraversal() method is called, or do the update of your Uniforms
explicitly after the updateTraversal().


How can I get such function (that updates the uniforms) to run after the updateTraversal that you speak of?

Do I have to use the Uniform Callback wrapper to prevent choppy shaders?

Thank you!

Cheers,
Johny


Last edited by Steal on Sun Feb 12, 2017 4:04 pm; edited 3 times in total
Back to top
View user's profile Send private message
Steal
User


Joined: 26 Jan 2017
Posts: 78

PostPosted: Sat Feb 11, 2017 7:20 pm    Post subject:
Reply with quote

Again,

Okay this is definitely not a bug, but it seems quite a common pitfall to say the least.

Instead of using viewer.frame(), which is a helper function that "calls advance(), eventTraversal(), updateTraversal(), renderingTraversals()" use the following.

Code:
viewer.advance();

viewer.eventTraversal();
viewer.updateTraversal();

updateShaders();

viewer.renderingTraversals();


This fixed my case of choppy shader updating.

Cheers,
Johny
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum

Similar Topics
Topic Author Forum Replies Posted
No new posts why does the adding of lighting shade... mirro General 0 Mon Feb 11, 2019 3:03 am View latest post
No new posts Question about security of shader dev... Werner Modenbach General 5 Wed Jan 30, 2019 5:50 pm View latest post
No new posts Compiling vertext shader fails on Intel loopy General 7 Fri Dec 14, 2018 7:28 pm View latest post
No new posts Update node color on demand dhhabyc General 12 Sat Nov 24, 2018 3:05 pm View latest post
No new posts Latency d_a_heitbrink General 4 Mon Oct 01, 2018 5:25 pm View latest post


Board Security Anti Bot Question MOD - phpBB MOD against Spam Bots
Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP