tips for making a scene graph

Was wondering if anyone has tips for putting together a scene graph for use in openFrameworks?

I have been avoiding using one for a while now but have come across the issue of opengl depth test not working correctly with alpha blending ( http://www.opengl.org/resources/faq/tec-…-arency.htm #15.050 )

It seems like a scene graph can be useful for doing things like sorting all faces of all geometry for correct rendering order - as well as detecting when objects are offscreen and don’t need rendering.

Cheers,
Theo

Hi Theo,

For those two cases you don’t need a scene graph at all, just a list of the triangles (or objects, or aabbs, or anything else) you’ll be rendering.

For frustum culling, one of the possible techniques is to project your vertices and check them against the boundaries of the clip space cube:

http://www.lighthouse3d.com/opengl/viewfrustum/index.php

For depth sorting just sort the list on projected z-depth, with radix sort being the common choice:

http://www.codercorner.com/RadixSortRevisited.htm

(the link points to a google cache because the original article was on a server flagged as malware by google)

Also, Tom Forsyth wrote a-very-interesting-article on why a scene-graph is almost always not the best fit for realtime 3D.

Hope this helps,

P.

I’ve been looking for the one, true scenegraph for a while.

Have you looked at any of the current open source offerings? The two that come to mind are OpenScenegraph and Ogre3d. My own misgiving in using them is that you have to drink a lot of the kool-aid to use them at all. They are very feature rich, but I get the impression you kind of have to do things their way, and they may not play nice with OF.

I guess the alternative is to create something lightweight. A tree of nodes, each node holding a transform and some geometry. Occlusion culling is a big subject, of course, though frustum culling is easy.

Scene graphs are also nice in creating intuitive abstractions for lights and cameras, which I always have to fuss with in OpenGL, and usually get wrong several times before I get them right. And automatically managing the matrix and attribute stacks is nice, too.

My own hesitation in making one so far is that I’ve always been sure that someone, somewhere has to have made one that suits my purposes. But I haven’t found it yet.

Kevin

I’ve done one project with Ogre 3D, it’s nothing short of awesome, but it’s pretty heavyweight.

Anything to do with rendering is abstracted away, making some things incredibly easy and some things a bit harder, you definitely won’t be injecting any OpenGL commands without some serious workaround, the upside being that you can switch renderers by just selecting the one you want on startup (provided you have all you shaders in the right format as well).

I was getting much better performance out of Direct3D than OpenGL BTW, not sure if it’s due to Ogres implementation of drivers.

/A

[quote author=“pangelo”]Hi Theo,

For those two cases you don’t need a scene graph at all, just a list of the triangles (or objects, or aabbs, or anything else) you’ll be rendering.

For frustum culling, one of the possible techniques is to project your vertices and check them against the boundaries of the clip space cube:

http://www.lighthouse3d.com/opengl/viewfrustum/index.php

For depth sorting just sort the list on projected z-depth, with radix sort being the common choice:

http://www.codercorner.com/RadixSortRevisited.htm

(the link points to a google cache because the original article was on a server flagged as malware by google)

Also, Tom Forsyth wrote a-very-interesting-article on why a scene-graph is almost always not the best fit for realtime 3D.

Hope this helps,

P.[/quote]

Hey - thanks!
That is extremely helpful!

I was a bit overwhelmed on how to put everything into a graph - I’ll try just sorting it and sending it as a list. That radix sort code is quite genius! Such a simple concept!

Yeah I was checking out open scene graph and this one: simple scene graph - http://plib.sourceforge.net/ssg/index.html. Simple Scene Graph seemed a bit more minimal but I think both require quite a big change in coding style and how you put things together.

But actually for one project where I was making dynamic trees (not the data structure) being able to parent the branches and not have to figure out both relative rotational values and absolute coordinate positions would have been a god send.

Thanks both for the tips!

Theo

[quote author=“hahakid”]I’ve done one project with Ogre 3D, it’s nothing short of awesome, but it’s pretty heavyweight.

Anything to do with rendering is abstracted away, making some things incredibly easy and some things a bit harder, you definitely won’t be injecting any OpenGL commands without some serious workaround, the upside being that you can switch renderers by just selecting the one you want on startup (provided you have all you shaders in the right format as well).

I was getting much better performance out of Direct3D than OpenGL BTW, not sure if it’s due to Ogres implementation of drivers.

/A[/quote]

Would using Ogre 3D inside of OF be feasible? I guess you could treat the ogre environment as almost a separate window and render it into an FBO or something.

Though I think it would definitely be overkill for what I need at the moment : )

Well, for one it would be hard to get at the FBO in the first place! :slight_smile:

I think it would be pretty hard to mix the two as Ogre has no concept of OpenGL really (apart from the OpenGL rendering plugin implementation).

Having said that, here is a discussion on how to mix OpenGL commands with Ogre:
http://forum.openframeworks.cc/t/l/43156/0">http://www.ogre3d.org/phpBB2/http://forum.openframeworks.cc/t/l/43156/0

I definitely think Ogre is far too heavyweight to be mixed in with OF like that, I went the other way so to speak and ported the OpenGL specific code I had in my videograbber to Ogre and went from there.

By the way Horde3D also has a scene graph, and it’s much more lightweight and accessible than Ogre…

One problem that crops up with alpha sorting is when you want to load a 3D model…sorting all those polygons as well as directly rendered stuff can be difficult.

Early this morning I realized I might actually have what you need already made.

http://flickr.com/photos/hahakid/216630-…-633305953/

http://www.nanikawa.com/temp/FrustumCulling.zip

I was doing a particle system at some point and I needed to sort the particles by distance from the camera so that the alpha blending would work properly.

It will only sort by position, the radius parameter is only used for culling. Fine for a particle system, but not great for models that might have vastly different sizes.

The code is not OF, so it might not compile on your machine!
Having SDL installed would be a good start.

It’s pretty messy as it was done in a hurry, but it did the trick. There is a AFrustumSortingManager that holds several AFrustumSortingGroups. A group lets you add entities to it that you can then cull and sort against the camera frustum.

One thing to look out for is that you need to grab the view matrix before you do anything else, done with grabMainCameraFustrum()

At the moment it is doing everything in the draw function, this was just a quick test of it.

If you manage to get it compiling without moving it to OF first (and getting pretty familiar with it), SPACE will switch cameras to let you see the culling in action, ENTER toggles distance sorting and holding B toggles frustum culling.

Right mouse button and mouse wheel move the camera.

/A