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 

Shaders with multiple views using ViewportCallback


 
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> General
View previous topic :: View next topic  
Author Message
christoph
Newbie


Joined: 10 Jul 2014
Posts: 7

PostPosted: Wed May 09, 2018 9:20 am    Post subject:
Shaders with multiple views using ViewportCallback
Reply with quote

Hi all,

I need to use the viewport dimensions for some calculations in my vertex shader. The most found way of doing the update of the viewport-size uniform is the ViewportCallback derived from osg::Uniform::Callback which encapsulates a camera.
But what happens if I have multiple views?
How can I fetch the viewport size in my shader per viewer?

Thank you!

Cheers,
Christoph
Back to top
View user's profile Send private message
robertosfield
OSG Project Lead


Joined: 18 Mar 2009
Posts: 12024

PostPosted: Wed May 09, 2018 11:24 am    Post subject:
Shaders with multiple views using ViewportCallback
Reply with quote

Hi Chritoph,

The right way to do is to to assign an osg::Uniform to each
osg::View's master Camera's StateSet i,e


view->getCamera()->getOrCreateStateSet()->addUniform(new
osg::Uniform("viewport", osg:::Vec4(x,y,w,h));

Robert

On 9 May 2018 at 10:20, Christoph Dohmen <> wrote:
Quote:
Hi all,

I need to use the viewport dimensions for some calculations in my vertex shader. The most found way of doing the update of the viewport-size uniform is the ViewportCallback derived from osg::Uniform::Callback which encapsulates a camera.
But what happens if I have multiple views?
How can I fetch the viewport size in my shader per viewer?

Thank you!

Cheers,
Christoph

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








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


Joined: 10 Jul 2014
Posts: 7

PostPosted: Wed May 09, 2018 2:36 pm    Post subject:
Reply with quote

Ahhh, Robert, thanks, that's the trick Smile

Cheers,
Christoph
Back to top
View user's profile Send private message
christoph
Newbie


Joined: 10 Jul 2014
Posts: 7

PostPosted: Mon May 14, 2018 7:08 am    Post subject:
Reply with quote

Hi Robert,

I just tried the uniform setting for the camera and it worked quite nice.
But I'm not able to use a callback to do the updating stuff Sad.

I tried to install this callback:

Code:

struct ViewportCallback : public osg::Uniform::Callback
{
    ViewportCallback( osg::Camera* camera )
                    : _camera( camera )
    {
        std::cout << "ViewportCallback::ViewportCallback()" << std::endl;
    }

    virtual void operator()( osg::Uniform* uniform, osg::NodeVisitor* /*nv*/)
    {
        std::cout << "ViewportCallback::operator()" << std::endl;
        osg::Viewport * vp( _camera->getViewport() );
        uniform->set( osg::Vec4( vp->x(), vp->y(), vp->width(), vp->height() ) );
    }

    osg::Camera* _camera;
};


and set it via

Code:

    osg::Viewport * vp( viewer.getCamera()->getViewport() );
    osg::Uniform * viewportUniform = new osg::Uniform( "viewport", osg::Vec4( vp->x(), vp->y(), vp->width(), vp->height() ) );
    viewportUniform->setUpdateCallback( new ViewportCallback( viewer.getCamera() ) );
    viewer.getCamera()->getOrCreateStateSet()->addUniform( viewportUniform );


But I don't get any output from operator() nor do I get an updated viewport value in my shader.

What's wrong with this?


Thank you!

Cheers,
Christoph
Back to top
View user's profile Send private message
robertosfield
OSG Project Lead


Joined: 18 Mar 2009
Posts: 12024

PostPosted: Mon May 14, 2018 7:59 am    Post subject:
Shaders with multiple views using ViewportCallback
Reply with quote

Hi Christoph,

I would have thought it would work, but haven't tried this specifically myself.

Older versions of the OSG didn't have support for calling update
callbacks on view(er) Camera's. I've just had a look at 3.2, 3.4 and
3.6/master and then all look to the have the code to do the update
traversal on the view's master and slave Camera.

A fall-back would be to assign an update/event callback to the Camera
to do the update.

Robert.

On 14 May 2018 at 08:08, Christoph Dohmen <> wrote:
Quote:
Hi Robert,

I just tried the uniform setting for the camera and it worked quite nice.
But I'm not able to use a callback to do the updating stuff Sad.

I tried to install this callback:


Code:

struct ViewportCallback : public osg::Uniform::Callback
{
ViewportCallback( osg::Camera* camera )
: _camera( camera )
{
std::cout << "ViewportCallback::ViewportCallback()" << std::endl;
}

virtual void operator()( osg::Uniform* uniform, osg::NodeVisitor* /*nv*/)
{
std::cout << "ViewportCallback::operator()" << std::endl;
osg::Viewport * vp( _camera->getViewport() );
uniform->set( osg::Vec4( vp->x(), vp->y(), vp->width(), vp->height() ) );
}

osg::Camera* _camera;
};




and set it via


Code:

osg::Viewport * vp( viewer.getCamera()->getViewport() );
osg::Uniform * viewportUniform = new osg::Uniform( "viewport", osg::Vec4( vp->x(), vp->y(), vp->width(), vp->height() ) );
viewportUniform->setUpdateCallback( new ViewportCallback( viewer.getCamera() ) );
viewer.getCamera()->getOrCreateStateSet()->addUniform( viewportUniform );




But I don't get any output from operator() nor do I get an updated viewport value in my shader.

What's wrong with this?


Thank you!

Cheers,
Christoph

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








------------------
Post generated by Mail2Forum
Back to top
View user's profile Send private message
robertosfield
OSG Project Lead


Joined: 18 Mar 2009
Posts: 12024

PostPosted: Mon May 14, 2018 8:54 am    Post subject:
Shaders with multiple views using ViewportCallback
Reply with quote

Hi Christoph,

On 14 May 2018 at 08:58, Robert Osfield <> wrote:
Quote:
I would have thought it would work, but haven't tried this specifically myself.

Older versions of the OSG didn't have support for calling update
callbacks on view(er) Camera's. I've just had a look at 3.2, 3.4 and
3.6/master and then all look to the have the code to do the update
traversal on the view's master and slave Camera.

I added your code snippets to an example program and reproduce the bug
of the update callback not being called on the view's master Camera's
StatetSet's Uniform. This bug exists in 3.2, 3.4, 3.6 and master!

I have fixed bug that existed for both the update and event traversals
and am currently applying this to master and 3.2, 3.4, 3.6 branches.

https://github.com/openscenegraph/OpenSceneGraph/commit/8656ab8a3c1da12e48ac212b70f58a34996d5193

Quote:
A fall-back would be to assign an update/event callback to the Camera
to do the update.

Without the bug fix it should be possible to use a node rather uniform
update callback on the Camera, or place the StateSet on the root of
the scene graph.

Robert.


------------------
Post generated by Mail2Forum
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 osgQt scenegraph flickering with mult... Meldryt General 1 Tue May 29, 2018 3:04 pm View latest post
No new posts Shader composition with multiple func... hartwigw General 1 Sat May 12, 2018 9:59 pm View latest post
No new posts Can a FrameBufferObject be shared by ... gwaldron General 2 Thu May 10, 2018 1:03 pm View latest post
No new posts EXTERNAL: Re: Getting a callback to u... Rowley, Marlin R General 1 Tue Apr 10, 2018 6:58 pm View latest post
No new posts Getting a callback to update shaders? Rowley, Marlin R General 2 Tue Apr 10, 2018 12:49 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