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 

Draw two translucent geometries in specific order


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


Joined: 03 May 2018
Posts: 8

PostPosted: Fri May 18, 2018 1:42 pm    Post subject:
Draw two translucent geometries in specific order
Reply with quote

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
Back to top
View user's profile Send private message
robertosfield
OSG Project Lead


Joined: 18 Mar 2009
Posts: 12094

PostPosted: Fri May 18, 2018 2:22 pm    Post subject:
Draw two translucent geometries in specific order
Reply with quote

Hi Kristofer,

On 18 May 2018 at 14:42, Kristofer Krus <> wrote:
Quote:
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.


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


Joined: 03 May 2018
Posts: 8

PostPosted: Fri May 18, 2018 4:04 pm    Post subject:
Reply with quote

Hi,

Thanks for your 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. This article 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? I see that this method also takes an optional mode. 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 these articles (and the OpenSceneGraph source code) that you can recommend that explains how render bin works in OpenSceneGraph in greater detail?

Cheers,
Kristofer
Back to top
View user's profile Send private message
Chris Hanson
Guest





PostPosted: Sun May 20, 2018 3:15 pm    Post subject:
Draw two translucent geometries in specific order
Reply with quote

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.


On Fri, May 18, 2018 at 10:04 AM, Kristofer Krus < (
Only registered users can see emails on this board!
Get registred or enter the forums!
)> wrote:
Quote:
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





_______________________________________________
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






--
Chris 'Xenon' Hanson, omo sanza lettere. 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]

------------------
Post generated by Mail2Forum
Back to top
krikr42
Newbie


Joined: 03 May 2018
Posts: 8

PostPosted: Mon May 21, 2018 7:52 am    Post subject:
Re: Draw two translucent geometries in specific order
Reply with quote

Chris Hanson wrote:
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.


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).
Back to top
View user's profile Send private message
krikr42
Newbie


Joined: 03 May 2018
Posts: 8

PostPosted: Mon May 21, 2018 9:34 am    Post subject:
Re: Draw two translucent geometries in specific order
Reply with quote

Hi again robertosfield, I took a look at the code you posted at this thread, 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 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.
Back to top
View user's profile Send private message
robertosfield
OSG Project Lead


Joined: 18 Mar 2009
Posts: 12094

PostPosted: Mon May 21, 2018 10:29 am    Post subject:
Draw two translucent geometries in specific order
Reply with quote

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.

On 21 May 2018 at 10:34, Kristofer Krus <> wrote:
Quote:
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:
Quote:
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








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


Joined: 03 May 2018
Posts: 8

PostPosted: Mon May 21, 2018 3:29 pm    Post subject:
Reply with quote

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
Back to top
View user's profile Send private message
robertosfield
OSG Project Lead


Joined: 18 Mar 2009
Posts: 12094

PostPosted: Mon May 21, 2018 4:36 pm    Post subject:
Draw two translucent geometries in specific order
Reply with quote

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.

On 21 May 2018 at 16:29, Kristofer Krus <> wrote:
Quote:
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








------------------
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 Extra draw calls in osgText? gwaldron General 1 Thu Jul 19, 2018 8:48 pm View latest post
No new posts Draw geometry on demand sergio2k18 General 5 Sun Jun 10, 2018 7:53 am View latest post
No new posts Geometries disappearing at optimization Andreas Ekstrand General 3 Mon Apr 02, 2018 12:08 am View latest post
No new posts Show part of geometry which intersect... aozdin General 15 Mon Mar 26, 2018 2:38 pm View latest post
No new posts Matrix multiplication order Flogo General 3 Thu Mar 22, 2018 9:53 am 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