[osg-users] Multiple Shaders

167 views
Skip to first unread message

J. Brent Spears

unread,
Aug 3, 2011, 12:29:17 PM8/3/11
to osg-...@lists.openscenegraph.org
Hi,

What happens if I attach a program shader to a group node and then a different program shader to the child node? Are both shaders executed? Just one? What order? Precedence, etc?

Thank you!

Cheers,
GB

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

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

Glenn Waldron

unread,
Aug 3, 2011, 12:58:34 PM8/3/11
to osg-...@lists.openscenegraph.org
GB, 
The child's shader program completely replaces the parent's shader program.

Glenn Waldron / Pelican Mapping / @glennwaldron

Jean-Sébastien Guay

unread,
Aug 3, 2011, 1:03:39 PM8/3/11
to osg-...@lists.openscenegraph.org
Hi Brent,

> What happens if I attach a program shader to a group node and then a different program shader to the child node? Are both shaders executed? Just one? What order? Precedence, etc?

The same rule as for any other state applies here: a state attribute on
a child is inherited from the parent, unless the child specifies its own
attribute.

However, shaders are not executed while traversing the graph, they are
only executed when something is drawn. Only one state attribute can be
active on a given state set at a time, so no, shaders cannot be combined
like that. So the question is which program is active on a given
drawable, and that is determined by the path down to the drawable and
which program was last encountered on that path.

Say you have

root <-- programA
/ \
/ \
no program --> Node1 Node2 <-- programB

Well, if Node1 has any drawables under it, programA will be active when
those drawables are drawn, and if Node2 has any drawables under it,
programB will be active for them.

Hope that helps,

J-S
--
______________________________________________________
Jean-Sebastien Guay jean-seba...@cm-labs.com
http://www.cm-labs.com/
http://whitestar02.dyndns-web.com/

Stephen Haith

unread,
Aug 4, 2011, 10:19:01 AM8/4/11
to osg-...@lists.openscenegraph.org
Very timely thread - I am looking at doing the same thing.

How can you apply a shader effect to the entire scene, AND another effect to only a part of the tree?

Thanks,

Stephen

------------------
Read this topic online here:

http://forum.openscenegraph.org/viewtopic.php?p=41851#41851

Glenn Waldron

unread,
Aug 5, 2011, 5:35:59 PM8/5/11
to osg-...@lists.openscenegraph.org
Stephen,

You need some kind of shader composition. Personally, I prefer the VirtualProgram approach taken in the osgvirtualprogram example. IIRC, Robert did not consider this flexible enough to be a general-purpose shader comp solution, so it's not in the core OSG. However it suited our needs quite well so we adopted and extended it for use in the osgEarth project.


Glenn Waldron / Pelican Mapping / @glennwaldron


hait...@gdls.com

unread,
Aug 9, 2011, 10:03:28 AM8/9/11
to OpenSceneGraph Users

Glenn,
Thanks for the response. Do you know where I can find the
osgvirtualprogram example?
The program I have worked on has recently moved from osg 2.2 to 2.8.3 (dark
ages, I know). I do not see osgvirtualprogram in the osg examples
directories for 2.2, 2.8.2, or 2.8.3.

I am adding precipitation effects (and dust effects) to a project that
currently uses shaders produce a rendered scene that represents sensor
returns - the render target is read back by the main program,
where the data is consumed. For the app/channel that has the sensor, the
program/shader is added to a node near the top of the tree. I have added
the precip effect program/shader to a node slightly below this one - at the
same level as the top terrain and entities node. The sensor shader
basically does range calculation, applies some error, and does some
processing for alpha fragments. For the visual channel, that has no higher
shaders, this works fine. However, for the sensor channel, the precip
particles don't get seen by sensor shader.

My implementation of rain/snow is based on a slightly modified
osgPrecipitationEffect. Perhaps shader is not the way to go for the precip
effect, but I thought it would provide the best efficiency. Nevertheless,
I can definitely see the need in the near future to have multiple,
accumulated, non-overriding effects. Currently, I would like to be able to
have the results from osgPrecipitationEffect like shader be seen by the
higher sensor shader.

Any thoughts?

Stephen Haithcock
General Dynamics Land Systems
38500 Mound Rd.
Sterling Heights, MI 48310
MZ 436-40-15
(586) 825-8573


Glenn Waldron
<gwaldron@gmail.c
om> To
Sent by: osg-...@lists.openscenegraph.org
osg-users-bounces cc
@lists.opensceneg
raph.org Subject
Re: [osg-users] Multiple Shaders

08/05/2011 05:35
PM


Please respond to
OpenSceneGraph
Users
<osg-users@lists.
openscenegraph.or
g>


Stephen,

http://github.com/gwaldron/osgearth/blob/master/src/osgEarth/ShaderComposition

Thanks,

Stephen

This is an e-mail from General Dynamics Land Systems. It is for the intended recipient only and may contain confidential and privileged information. No one else may read, print, store, copy, forward or act in reliance on it or its attachments. If you are not the intended recipient, please return this message to the sender and delete the message and any attachments from your computer. Your cooperation is appreciated.

Glenn Waldron

unread,
Aug 9, 2011, 10:59:04 AM8/9/11
to OpenSceneGraph Users
Stephen,
That example is in the main distro; you need to enable the examples in CMake to see it. The source is here

Yes, yours is a case for shader composition. PrecipitationEffect is self-contained so you would need to modify it to make it work in a composition framework.

BTW here is a write-up on the shader composition approach we use in osgEarth. Like I said, we started with VirtualProgram and extended it to support user function injection.



Glenn Waldron / Pelican Mapping / @glennwaldron


Reply all
Reply to author
Forward
0 new messages