Hi Damian, The OSG svn/trunk has a new feature called #pragma(tic) shader composition that allows you to control which shader paths are used by provided the defines to control them from StateSet::setDefine() methods placed in the scene graph. You could write your shaders to use a particular define then set the appropriate Define you want on the Camera StateSet for each View, each View would then select the appropriate path.
If you can't use OSG svn/trunk then you can do something similar using a Uniform place on the the Camera StateSet for each View. How efficiently the driver/gpu manages this will depend upon the drive and hardware. Ideally it'd optimize away the branch for you. Using either of these mechanism will totally avoid the need to trying to be clever with callbacks. The OSG is designed to handle this type of task so just use it the way it was intended :-) Robert. On 1 April 2015 at 07:54, Damian Stewart <[email protected] > wrote: > Hi, > > I've exhausted what references I could find without really coming up with > a good way of doing this, so I am hoping someone can advise me on an > efficient method of achieving the following outcome in OSG. > > I have an arbitrary, large number of nodes scene that I don't control the > contents of before it's loaded. (eg, assume a giant world scene that is > created by an artist) > > I would like to render the same scene in two views, without duplicating > the nodes or assets (memory constraints). Lets say View A renders the scene > as normal, View B renders the scene in an alternate mode (lets say, changes > the output pixel from colour to greyscale for discussion purposes). > > The current method uses a bool Uniform that is set on each camera and the > fragment shader checks the bool to tell which view it is rendering in and > changes the output pixel accordingly. This seems "bad" to me. It works, but > surely there's got to be a better way than doing a branch (or multiple > branches) in the fragment shader. > > Ideally I would create two statesets (with optimal shaders etc), and > switch between them at render time. > > So I was thinking I might be able to use one of the various callback > methods. Eg, I could attach an update callback to each model in the scene > that checks "something" unique to each view, and sets the state as > appropriate. However, I'm not sure if the update callback is called once > for each view, or only once per frame etc. If the update callback is called > per view, what's a fast way to check which view is the current render pass > etc? Would a better method be to use the draw callback on Drawables perhaps? > > Thank for any help/advice you can give me. > > Cheers, > Damian > > ------------------ > Read this topic online here: > http://forum.openscenegraph.org/viewtopic.php?p=63246#63246 > > > > > > _______________________________________________ > 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

