[osg-users] Draw two translucent geometries in specific order

252 views
Skip to first unread message

Kristofer Krus

unread,
May 18, 2018, 9:41:43 AM5/18/18
to osg-...@lists.openscenegraph.org
Hi,

I have two geometries, A and B, that are both translucent, of which A should always be rendered before B because it is farther from the camera fragment-wise. However, OpenSceneGraph sometimes renders A first and sometimes renders B first, depending on the viewing angle, which, when B is rendered first, causes A to disappear at the fragments where A and B overlap.

How can I make sure A is always rendered first and then B?

Thank you!

Cheers,
Kristofer

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





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

Robert Osfield

unread,
May 18, 2018, 10:21:15 AM5/18/18
to OpenSceneGraph Users
Hi Kristofer,

On 18 May 2018 at 14:42, Kristofer Krus <kristof...@liu.se> wrote:
> I have two geometries, A and B, that are both translucent, of which A should always be rendered before B because it is farther from the camera fragment-wise. However, OpenSceneGraph sometimes renders A first and sometimes renders B first, depending on the viewing angle, which, when B is rendered first, causes A to disappear at the fragments where A and B overlap.
>
> How can I make sure A is always rendered first and then B?

There a several ways to achieve it. The most common way is assign the
two geometries to two different RenderBins

subgraphA->getOrCrreateStateSet()->setRenderinBinDetails("RenderBin",
5); // or "DepthSortedBin" if you have mulitple transparent objects
that need sorting
subgraphB->getOrCrreateStateSet()->setRenderinBinDetails("RenderBin", 6);

Or put them both into a traversal order bin:

Group* group = new osg::Group;
group->getOrCreateStateSet()->setRenderinBinDetails("TraversalOrderBin", 5);
group->addChild(subgraphA);
group->addChild(subgraphB);

Performance wise the later might be a little faster, but won't be a
huge difference.

Cheers,
Robert.

Kristofer Krus

unread,
May 18, 2018, 12:04:09 PM5/18/18
to osg-...@lists.openscenegraph.org
Hi,

Thanks for the reply Robert! I think the concept of render bin sounds logical, but I'm slightly confused about how RenderBins work in OSG (OpenSceneGraph). I’ve tried to find information about what RenderBins are and how to use them, but what I’ve been able to find so far has been limited, so I still have some questions about them:

1. Why does a bin have both a number and a name? Wouldn’t just one of those be enough as an identifier?

2. The article http://www.bricoworks.com/articles/stategraph/stategraph.html seems to imply that there are two default RenderBins: One with number 0 in which OSG puts all opaque objects and one with number 10 in which it puts all translucent objects. Is that how it works?

3. What are the names of those bins? (Or is that unimportant?)

4. How does OSG determine whether an object is translucent in order to put it into the correct bin? Does it look at all the colors and textures that are associated with the object and check whether at least some polygon or some pixel is translucent?

5. Will OSG’s choice of RenderBin to put each object in, based on translucency, be overridden if I use setRenderBinDetails (http://public.vrac.iastate.edu/vancegroup/docs/OpenSceneGraphReferenceDocs-3.0/a00762.html#a498095c3811e00b2fc6123a24ef5ec81)? I see that this method also takes an optional mode (http://public.vrac.iastate.edu/vancegroup/docs/OpenSceneGraphReferenceDocs-3.0/a00762.html#a43d4fd1ed6001ab862e89e7c4e877ff1). Does this variable have something to do with that? What does it do?

6. When I call setRenderBinDetails, if I specify a bin number that doesn’t exist, will this create a new bin?

7. If a bin with than number already exists, will the function call change the name and mode of that bin?

8. In your reply, you used the numbers 5 and 6. Was there some reason you did so, or was the choice of numbers arbitrary?

Finally, is there some other source, except from http://www.bricoworks.com/articles/stateset/stateset.html and http://www.bricoworks.com/articles/stategraph/stategraph.html (and the OpenSceneGraph source code) that you can recommend that explains how render bin works in OpenSceneGraph in greater detail?

Cheers,
Kristofer

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

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

Chris Hanson

unread,
May 20, 2018, 11:14:31 AM5/20/18
to OpenSceneGraph Users
You might also look at OSGTransparencyToolkit. http://alphapixel.com/project/osg-transparency-toolkit/

There are several Order Independent Transparency implementation out there that let you not worry about the object draw order.






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



--
Chris 'Xenon' Hanson, omo sanza lettere. Xe...@AlphaPixel.com http://www.alphapixel.com/
Training • Consulting • Contracting
3D • Scene Graphs (Open Scene Graph/OSG) • OpenGL 2 • OpenGL 3 • OpenGL 4 • GLSL • OpenGL ES 1 • OpenGL ES 2 • OpenCL
Legal/IP • Forensics • Imaging  UAVs • GIS • GPS • osgEarth • Terrain • Telemetry • Cryptography • LIDAR • Embedded • Mobile • iPhone/iPad/iOS • Android
@alphapixel facebook.com/alphapixel (775) 623-PIXL [7495]

Kristofer Krus

unread,
May 21, 2018, 3:51:47 AM5/21/18
to osg-...@lists.openscenegraph.org

Chris Hanson wrote:
> You might also look at OSGTransparencyToolkit. http://alphapixel.com/project/osg-transparency-toolkit/ (http://alphapixel.com/project/osg-transparency-toolkit/)

>
> There are several Order Independent Transparency implementation out there that let you not worry about the object draw order.


Thanks, I might possibly take a look at this if I can't make it work in any other way. Currently, I just want to make sure B is rendered after A (and that A and B are both rendered after everything else, which is fully opaque).

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

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

Kristofer Krus

unread,
May 21, 2018, 5:33:46 AM5/21/18
to osg-...@lists.openscenegraph.org
Hi again robertosfield, I took a look at the code you posted at this thread (http://forum.openscenegraph.org/viewtopic.php?t=17289), and it gave me some further questions.

According to this code, there seems like there are six default rendering bins, and I don't see that any numbers are associated with them. However, the article (http://www.bricoworks.com/articles/stategraph/stategraph.html) I linked to claims there are two default rendering bins, numbered 0 and 10. Why does that article claim that, if the code seems to imply something very different? Also, why would it say that the numbers used for those bins are 0 and 10? That seems kind of arbitrary to me and doesn't make much sense.


robertosfield wrote:
> subgraphA->getOrCrreateStateSet()->setRenderinBinDetails("RenderBin", 5); // or "DepthSortedBin" if you have mulitple transparent objects that need sorting
> subgraphB->getOrCrreateStateSet()->setRenderinBinDetails("RenderBin", 6);


There is no method called setRenderinBinDetails, but there is a method called setRenderBinDetails. And the order of the arguments for this method is the reversed compared to what you write, i.e. setRenderBinDetails(5, "RenderBin") and setRenderBinDetails(6, "RenderBin").

Also, what do the arguments do? When I use the code you suggested, A is now always rendered after B, i.e. in the wrong order, no matter if I use the numbers 5 and 6 or if I swap them so that I use the numbers 6 and 5. (This seems to be independent of the direction I view the scene from, which is a good thing, though.) I had the impression that render bins with higher numbers would always be rendered later, and that the number we provide as an argument to setRenderBinDetails is the number of the bin we want to put the subgraph in, but this doesn't seem to be the case.

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

Robert Osfield

unread,
May 21, 2018, 6:28:40 AM5/21/18
to OpenSceneGraph Users
Hi Kirs,

I'm afraid I'm too busy with other work right now to spend lots of
time reading other various posts on topic, or provide long essays on
here on the topic.

In short:

There is only one default RenderBin in the OSG, that's the main
RenderStage (subclasses from RenderBin).

The StateSet::setRenderBinDetails(BinNumber, "RenderBinPrototypeName")
sets the BinNumber and the "RenderBinPrototypeName" string hints to
the cull traversal what type of bin to create for that BinNumber if
one hasn't yet been created for it. The strings match up to the list
I posted earlier - this RenderBinProtypeList maps the string to a
RenderBin that is cloned and stored in the rendering backend, and it's
into this bin that the subgraph below that StateSet are dropped into.

RenderBin's can be nested as many times as you want. A RenderStage is
a RenderBin subclass that is used for high level stages in rendering
such as render to a texture or rendering to the main window, in this
case you have control over the clearing of buffers and any operations
that are done after the rendering. The front end for controlling
RenderStage is osg::Camera.

Robert.

Kristofer Krus

unread,
May 21, 2018, 11:28:47 AM5/21/18
to osg-...@lists.openscenegraph.org
Hi Robert,

Thanks for your reply.

The problem was that setRenderingHint(osg::StateSet::TRANSPARENT_BIN) was called after I called setRenderBinDetails. While I checked that setRenderBinDetails was not called anywhere else in the code, I didn't know that you could also choose render bin through the setRenderingHint method. Removing the calls to setRenderingHint resolved the problem.

Cheers,
Kristofer

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

Robert Osfield

unread,
May 21, 2018, 12:35:21 PM5/21/18
to OpenSceneGraph Users
Hi Kristofer,

StateSet::serRenderingHint pre-dates StateSet::setRenderBinDetails()
and was kept for backwards compatibility and ease of use, as you say
it overrides previous calls to RenderBinDetails as it actually calls
RenderBinDetails itself.

Robert.
Reply all
Reply to author
Forward
0 new messages