[osg-users] how to do culling with shader tranformed geometry?

14 views
Skip to first unread message

Alexej Fink

unread,
Aug 23, 2012, 6:52:05 AM8/23/12
to osg-...@lists.openscenegraph.org
Hello,

I need an advice regarding the culling setup.
In my application I use a vertex shader to transform 3d geometry from the flat-world scene graph to the related position on a sphere (globe).

Having a normal camera, which hovers over the transformed spheric world breaks the culling stage, cause the frustum culling is applied to the untransformed (flat) world in the scene graph compared to the rendered spheric world with transformed geometry.

So how to setup the culling for such a scenario?
* Can I setup two different cameras, one for culling and one for drawing (how)?
* And how to deal with the culling on boundaries in the flat world which shall met in the spheric world -- they usually do not fit into a single frustum?


Cheers,
Alexej

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





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

Robert Osfield

unread,
Aug 23, 2012, 7:31:17 AM8/23/12
to osg-...@lists.openscenegraph.org
Hi Alexej,

Use the osg::Geometry::setInitialBound() to the extents that you
transformed geometry will be placed.

Robert.

Alexej Fink

unread,
Aug 23, 2012, 8:34:18 AM8/23/12
to osg-...@lists.openscenegraph.org
Hello Robert,
tank you for the fast replay!

Grep-ing the includes reported, that two classes have the setInitialBound() interface: Drawable and Node.
I would like to avoid setting this initial-bound for each single peace of geometry (~ Drawable).

Can I just put the initial-bounds on the hi-level group nodes and just skip this step for underlying refinement nodes?
Do I have to disable the dynamic bbox calculation of the geometry nodes then?



robertosfield wrote:
> Hi Alexej,
>
> Use the osg::Geometry::setInitialBound() to the extents that you
> transformed geometry will be placed.
>
> Robert.
:D

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

Robert Osfield

unread,
Aug 23, 2012, 8:42:48 AM8/23/12
to osg-...@lists.openscenegraph.org
Hi Alexej,

On 23 August 2012 13:34, Alexej Fink <dk...@gmx.net> wrote:
> Hello Robert,
> tank you for the fast replay!
>
> Grep-ing the includes reported, that two classes have the setInitialBound() interface: Drawable and Node.
> I would like to avoid setting this initial-bound for each single peace of geometry (~ Drawable).
>
> Can I just put the initial-bounds on the hi-level group nodes and just skip this step for underlying refinement nodes?
> Do I have to disable the dynamic bbox calculation of the geometry nodes then?

The InitialBound support is only available at the Drawable level.

Robert.

Sebastian Messerschmidt

unread,
Aug 23, 2012, 11:44:10 AM8/23/12
to osg-...@lists.openscenegraph.org, Alexej Fink
Am 23.08.2012 14:34, schrieb Alexej Fink:
> Hello Robert,
> tank you for the fast replay!
>
> Grep-ing the includes reported, that two classes have the setInitialBound() interface: Drawable and Node.
> I would like to avoid setting this initial-bound for each single peace of geometry (~ Drawable).
>
> Can I just put the initial-bounds on the hi-level group nodes and just skip this step for underlying refinement nodes?
> Do I have to disable the dynamic bbox calculation of the geometry nodes then?
Hi Alexej,

I had some similiar issue for drawining instanced geometry where the
geometry indeed has to cover the bounds of the complete instanced patch.
For this i used the setComputeBoundingBoxCallback on the geometry in
question to set it to the correct bounding box.
Maybe you could use this on your first-class Node?

cheers
Sebastian

Alexej Fink

unread,
Aug 24, 2012, 5:42:24 AM8/24/12
to osg-...@lists.openscenegraph.org
Hello Sebastian.


Sebastian Messerschmidt wrote:
> For this i used the setComputeBoundingBoxCallback on the geometry in
> question to set it to the correct bounding box.
> Maybe you could use this on your first-class Node?
>


Hm, maybe.
Unfortunately the "documentation" to Drawable::setComputeBoundingBoxCallback(..) does not say anything about how often this callback is called and what is the tirgger (if called on demand).
I thought this callback is desired for dynamic geometry, which can change (nearly) per frame.


I still think the idea of one or more independent cull-camera(s) and separate draw-camera is not that bad.
Does anyone know: Is possible to realize that using build in OSG tools?

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

Sebastian Messerschmidt

unread,
Aug 24, 2012, 5:50:01 AM8/24/12
to osg-...@lists.openscenegraph.org, Alexej Fink
Am 24.08.2012 11:42, schrieb Alexej Fink:
> Hello Sebastian.
>
>
> Sebastian Messerschmidt wrote:
>> For this i used the setComputeBoundingBoxCallback on the geometry in
>> question to set it to the correct bounding box.
>> Maybe you could use this on your first-class Node?
>>
>
> Hm, maybe.
> Unfortunately the "documentation" to Drawable::setComputeBoundingBoxCallback(..) does not say anything about how often this callback is called and what is the tirgger (if called on demand).
> I thought this callback is desired for dynamic geometry, which can change (nearly) per frame.
The callback will be called if the bounds are marked as dirty. (i.e. if
a new PrimitiveSet is added).
In my use case I simple set the callback, called getBounds once on the
parent and then removed the callback after loading and before attaching
the node to the scenegraph. I can do this safely as I know that the
instanced geometry set is not changed in any way.

cheers
Sebastian

Alexej Fink

unread,
Aug 24, 2012, 6:09:52 AM8/24/12
to osg-...@lists.openscenegraph.org

Sebastian Messerschmidt wrote:
> The callback will be called if the bounds are marked as dirty. (i.e. if
> a new PrimitiveSet is added).
> In my use case I simple set the callback, called getBounds once on the
> parent and then removed the callback after loading and before attaching
> the node to the scenegraph. I can do this safely as I know that the
> instanced geometry set is not changed in any way.
>
> cheers
> Sebastian
>


Thanks, this sounds reasonable.

One more point. I really don't care about culling on the Drawable-instances level.
Can I setup the bboxes just for the parent grouping nodes and have nothing at the drawable level, is it possible?

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

Sebastian Messerschmidt

unread,
Aug 24, 2012, 8:04:19 AM8/24/12
to osg-...@lists.openscenegraph.org, Alexej Fink
Am 24.08.2012 12:09, schrieb Alexej Fink:
> Sebastian Messerschmidt wrote:
>> The callback will be called if the bounds are marked as dirty. (i.e. if
>> a new PrimitiveSet is added).
>> In my use case I simple set the callback, called getBounds once on the
>> parent and then removed the callback after loading and before attaching
>> the node to the scenegraph. I can do this safely as I know that the
>> instanced geometry set is not changed in any way.
>>
>> cheers
>> Sebastian
>>
>
> Thanks, this sounds reasonable.
>
> One more point. I really don't care about culling on the Drawable-instances level.
> Can I setup the bboxes just for the parent grouping nodes and have nothing at the drawable level, is it possible?
I've tried this via setCullingActive(false) on the Node, but I'm not
quite sure if this the correct way to do this. Following documentation
it should disable small feature/frustum culling.
Maybe Robert can give some insights here.

Cheers
Sebastian

Glenn Waldron

unread,
Aug 24, 2012, 8:52:56 AM8/24/12
to osg-...@lists.openscenegraph.org
On Fri, Aug 24, 2012 at 6:09 AM, Alexej Fink <dk...@gmx.net> wrote:

Sebastian Messerschmidt wrote:
> The callback will be called if the bounds are marked as dirty. (i.e. if
> a new PrimitiveSet is added).
> In my use case I simple set the callback, called getBounds once on the
> parent and then removed the callback after loading and before attaching
> the node to the scenegraph. I can do this safely as I know that the
> instanced geometry set is not changed in any way.
>
> cheers
> Sebastian
>


Thanks, this sounds reasonable.

One more point. I really don't care about culling on the Drawable-instances level.
Can I setup the bboxes just for the parent grouping nodes and have nothing at the drawable level, is it possible?

No, you need to apply it on the drawables, otherwise they will still get culled.

I created some utilities to support DrawInstanced usage in osgEarth, including a visitor that will apply the static bounding box to drawables. Perhaps it would be useful to you:


Glenn Waldron / Pelican Mapping / @glennwaldron

Alexej Fink

unread,
Aug 24, 2012, 9:24:34 AM8/24/12
to osg-...@lists.openscenegraph.org

gwaldron wrote:
>
> No, you need to apply it on the drawables, otherwise they will still get culled.
>
>
> I created some utilities to support DrawInstanced usage in osgEarth, including a visitor that will apply the static bounding box to drawables. Perhaps it would be useful to you:
>
>
> http://github.com/gwaldron/osgearth/blob/master/src/osgEarth/DrawInstanced (https://github.com/gwaldron/osgearth/blob/master/src/osgEarth/DrawInstanced.cpp)
> http://github.com/gwaldron/osgearth/blob/master/src/osgEarth/DrawInstanced.cpp (https://github.com/gwaldron/osgearth/blob/master/src/osgEarth/DrawInstanced.cpp)
>


Do I understand your approach right: That you set the same "static" bbox for each drawable by setting the same calcBBox callback for a group of Drawable instances?

If so. Although this is an other interesting work around. It still does not reduce the culling effort visiting each Drawable instance, which I would like to avoid, since it is meaningless in my setup -- culling on the parent group node would be sufficient. Can I use some cull-callback to prevent the culling visitor to go deeper to the single Drawables and cull based only on the group node bbox?

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

Sergey Polischuk

unread,
Aug 24, 2012, 9:31:25 AM8/24/12
to osg-...@lists.openscenegraph.org
Hi

>Can I use some cull-callback to prevent the culling visitor to go deeper to the single Drawables and cull based only on the group node bbox?

there are problem: cullvisitor grabbing drawables for later drawing, and if you dont go deeper, nothing would be drawed
Cheers.

24.08.2012, 17:24, "Alexej Fink" <dk...@gmx.net>:

Glenn Waldron

unread,
Aug 24, 2012, 9:37:58 AM8/24/12
to osg-...@lists.openscenegraph.org
On Fri, Aug 24, 2012 at 9:24 AM, Alexej Fink <dk...@gmx.net> wrote:

gwaldron wrote:
>
> No, you need to apply it on the drawables, otherwise they will still get culled.
>
>
> I created some utilities to support DrawInstanced usage in osgEarth, including a visitor that will apply the static bounding box to drawables. Perhaps it would be useful to you:
>
>
> http://github.com/gwaldron/osgearth/blob/master/src/osgEarth/DrawInstanced (https://github.com/gwaldron/osgearth/blob/master/src/osgEarth/DrawInstanced.cpp)
> http://github.com/gwaldron/osgearth/blob/master/src/osgEarth/DrawInstanced.cpp (https://github.com/gwaldron/osgearth/blob/master/src/osgEarth/DrawInstanced.cpp)
>


Do I understand your approach right: That you set the same "static" bbox for each drawable by setting the same calcBBox callback for a group of Drawable instances?

If so. Although this is an other interesting work around. It still does not reduce the culling effort visiting each Drawable instance, which I would like to avoid, since it is meaningless in my setup -- culling on the parent group node would be sufficient. Can I use some cull-callback to prevent the culling visitor to go deeper to the single Drawables and cull based only on the group node bbox?

Look at CullVisitor::apply(Geode&) to see how it works.

I believe your drawables have to return a valid bound since CV uses that to calculate near/far clipping planes, renderleaf depth, etc.

Alexej Fink

unread,
Aug 24, 2012, 9:41:29 AM8/24/12
to osg-...@lists.openscenegraph.org

hybr wrote:
>
> there are problem: cullvisitor grabbing drawables for later drawing, and if you dont go deeper, nothing would be drawed
> Cheers.
>


The point is: At the group node it can be already decided, if the underlying nodes are visible or not. Thus no need to compare against each single Drawable's bbox for refinement.
So I would like to tell the cull-visitor: Take all underlying drawables, if the group-node bbox passes (or skip all, if not).

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

Robert Osfield

unread,
Aug 24, 2012, 11:44:03 AM8/24/12
to osg-...@lists.openscenegraph.org
Hi Alexej,

On 24 August 2012 14:41, Alexej Fink <dk...@gmx.net> wrote:
> The point is: At the group node it can be already decided, if the underlying nodes are visible or not. Thus no need to compare against each single Drawable's bbox for refinement.
> So I would like to tell the cull-visitor: Take all underlying drawables, if the group-node bbox passes (or skip all, if not).

The OSG will automatically stop do the cull tests against the frustum
sides once a frustum side totally encloses a subgraph, so there really
isn't much to be gained by trying to be clever, it's already doing
everything it can to be efficient w.r.t cull tests.

Culling is import even down at the leaf level so there is still
performance to be gained by leaving culling on right down to the leaf
level.

Not only does the OSG using the bounding box of the Drawable for
culling it also uses to help compute the near/far ranges required to
encompass the scene.

So.... stop trying to be clever, you actually just outwitting yourself
for no reason, you'll end up with crappy solution because you are over
thinking things. JUST set the bounding box on the Drawable and let
the OSG do it's stuff, it written this way for a reason.

Robert.

Sebastian Messerschmidt

unread,
Aug 24, 2012, 11:55:31 AM8/24/12
to OpenSceneGraph Users
Hello Alexej, Robert

I think the reason for Alexej to think that disabling the culling would
improve render time in any way, is that he measuring the time of the
cull traversal.
Indeed the cull traversal time is culling + preparing the drawing of the
geometries. I've fallen for this in the beginning.
So maybe the problem lies with the number of drawables (i.e. there are
too many too small batches). So being clever at this point would rather
mean to make bigger yet fewer sets.

cheers
Sebastian

Alexej Fink

unread,
Aug 28, 2012, 6:56:12 AM8/28/12
to osg-...@lists.openscenegraph.org
Hellor Robert,

Every day I try to think a bit less, but it does not work for me... ;)

But seriously:
OSG is a framework, which tries to fit several different use cases. And it is natural, that it will not fit perfect for every possible job. Thus I want to figure out, how I can use it in the best way for my purpose.

I try to use shaders to project flat world geometry on a sphere to keep the scene graph simple. But cannot tune the culling stage to fit this situation (yet) and have to deal with a pretty crude workaround distorting the bounding boxes, which breaks the idea of keeping the flat world scene graph simple.

I highly appreciate your help, but that does not imply, that I shall not have an own vision, of how to do certain things.

Therefore I still think (being clever), that adapting the culling visitor would be a cleaner way. But unfortunately don't know, how to do it now, and since the OSG API is nearly undocumented, it is a hard way to go.
All I want is a custom flat-world culler, set up of four clipping planes and a fitting AND/OR conjunction (for full-inside or warp-on-border cases). Is this that hard to do with OSG?

Cheers,
Alexej

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

Alexej Fink

unread,
Aug 28, 2012, 7:08:07 AM8/28/12
to osg-...@lists.openscenegraph.org
Hello Sebastian,

unfortunately I cannot create bigger sets with more GL geometry in them, cause I need the geometry to be addressable. :(



Sebastian Messerschmidt wrote:
> Hello Alexej, Robert
>
> I think the reason for Alexej to think that disabling the culling would
> improve render time in any way, is that he measuring the time of the
> cull traversal.
> Indeed the cull traversal time is culling + preparing the drawing of the
> geometries. I've fallen for this in the beginning.
> So maybe the problem lies with the number of drawables (i.e. there are
> too many too small batches). So being clever at this point would rather
> mean to make bigger yet fewer sets.
>
> cheers
> Sebastian
>


------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=49620#49620
Reply all
Reply to author
Forward
0 new messages