Scene Graphs: The good, the bad and the ugly

I’m not quite understanding your analogy. I don’t see that using an IDE prevents you from needed to learn anything about a language. On the contrary, most modern IDEs allow one to learn a language faster via integrated help (and other documentation) and “as-you-type” warnings and errors with suggestions. I suppose you could claim that one isn’t learning about manual building tools, but so what? That’s not very interesting for most beginners. Likewise it is reasonable for beginners to use some kind of engine when starting off with graphical programming. The same can be said for any high level construct. As for graphics, my only suggestion is to avoid scenegraphs like the plague.

@Hibernate - If you want to talk about relational database related stuff, start you’re own darn thread! :wink:
@MS Windows - Go troll somewhere else.
@spatial partitioning methods with traditional scene graph - No, just no.

@lhkbob: I’ve mentioned this in other threads. I’ve very strong reservations about component based systems in a language like Java. With a lot of work, the can be made to be effective in languages that support manual memory management since the programmer can “know” where nearby memory chunks reside. If Java were to add support for arrays of structures then the picture would dramatically change. Setting my previous comments aside, I think it would be very interesting to discuss the interaction between spatial database & entity systems.

Simply looking at the spatial database portion, I’m a firm believer of “there is no silver bullet”. Even for moderately complex situations hybrid solutions will often be the best choice.

I agree that as was presented by many writes, a component system did not map well into Java land easily. It was either too close to the database (for largescale projects like MMOs) or was, as you said, relying on memory management. When I did my component system, I just captured the ideas of separation of data and logic and then tried to code those up as best I could with Java’s memory model.

[quote]@lhkbob: I’ve mentioned this in other threads. I’ve very strong reservations about component based systems in a language like Java. With a lot of work, the can be made to be effective in languages that support manual memory management since the programmer can “know” where nearby memory chunks reside. If Java were to add support for arrays of structures then the picture would dramatically change. Setting my previous comments aside, I think it would be very interesting to discuss the interaction between spatial database & entity systems.
[/quote]
Component based systems can work very well in Java too with a good implementation (very low garbage and fast cross component access). we actually use one on a project and the benefit become really viewable now that the project is advanced : to modify something and/or add new features. In this project we exclusivly work in memory and save all the system (all entity and component) every minutes wich is very simple and fast with an entity system (cloning data synchronously and then saving to DB asynchronously in an other thread), even debug become easier. Finally I cannot see where we are loosing performance against a standard approch.

[quote]Simply looking at the spatial database portion, I’m a firm believer of “there is no silver bullet”. Even for moderately complex situations hybrid solutions will often be the best choice.
[/quote]
Agree, but there is sometime strong base that you can always start with (and then customize)

about SceneGraph, this is not an obligation to use only one scenegraph, I use to use differents scenegraph in the same project using “bridge” between them, because some are more suitable for rendering, other for physics , other for saving, etc… separating them by functionality may even be more easy to use/understand/debug. Sometime you are forced to do that like in case one use a physics engine that have a different representation of the 3d engine he use and the global scenegraph manager he built

Hybenrate burk… One years ago I dropped Hibernate as well as Spring on a project I was working on, and life become better

Using modern IDEs with a strong will of learning how it works underneath is fine. However, I have seen a lot of students using lots of features that allow to do things faster and easier but they were completely unable to repair their pretty tools or to find an alternative route when their favorite IDEs were unable to build a JAR for example. Using an IDE does not prevent you from needing to learn anything about a language but some things become no more mandatory. If your favorite IDE is able to make a JAR, maybe you will want to understand what it is exactly and how it is created but some lazy students won’t. When I was at the university, lots of students didn’t even know the Java API, they didn’t remember the names of the methods, they were completely lost without auto-completion and they were ill at ease when they had to write some code with a pen and a sheet of paper… Things are complicated before becoming simple. I think that using low level tools at first is more efficient in term of pedagogy than directly advise students to use IDEs. Computer science is not only composed of interesting things, there are boring aspects and students have to get accustomed to it otherwise they will be really disappointed when they will enter the professional world.

I saw some people on various forums who only want to load and display their models with the scene graph that they have chosen without learning OpenGL whereas a deep understanding of OpenGL would have helped them to understand the scene graphs. For example, knowing what a frustum is is not useless when using Java3D. A newbie did not succeed in displaying his space ship because it was too far; another guy who has no knowledge of Java3D explained to him that it was not in the frustum, it was not enough. Using a scene graph is easier when you have some notions of computer graphics.

In my humble opinion, this problem is deeper, some people want to do many things but they don’t want to face the difficulties and I find this way of thinking not very efficient…

Personally I don’t understand why you advise people to avoid scene graphs.

Why? I agree with DzzD:

[quote=“DzzD,post:23,topic:36146”]
and I succeeded in using a scene graph both as a tree and as a graph, it is not DzzD’s approach but it worked. What is wrong with this?

+1 gouessej

“Professional” programmers who can’t build their app manually are incompetent really, I see it also a lot on Visual C++ users. It’s not just about inability to build, but lacking the knowledge how things are composed at this level and it often manifastes in having wrong view how such basic things are done, which is really harmful.

I agree also with DzzD, but I have this feeling that the term “scene graph” is not meant to be used for that. Every engine/game of course have multiple “views” of the data optimized for various usages. These views are mostly “flat” specialized structures.

[quote]but I have this feeling that the term “scene graph” is not meant to be used for that. Every engine/game of course have multiple “views” of the data optimized for various usages. These views are mostly “flat” specialized structures.
[/quote]
Whatever wiki or other “official” say, I would define that scenegraph is a graph representing scene data :persecutioncomplex:, graph can be hierarchical or not…

They do in fact appear to be a very simple yet deeply complex subject :slight_smile: But, WRT the original post - there’s nothing inherently wrong or daft about using scenegraphs for games at all I don’t think: using the wrong scenegraph for your game on the other hand, is going to cause you troubles at some point.

Most programmers like to try and abstract everything away into common interfaces but at some point the very specification of the interfaces becomes intrinsically tied to the efficacy of their use. Using a generic scenegraph sounds like a wonderful way of getting a quick fix to your scenegraph needs but eventually the clever things you really want to do will become impossibly inefficient or difficult to do. If this weren’t the case people wouldn’t still be developing new ones :slight_smile:

Cas :slight_smile:

A scenegraph is often a tree.

no you’re talking about scenetree :slight_smile:

I advise people to avoid scene graphs because every scene graph I’ve seen tries to do too many things and ends up making things difficult. It might be the case that your usage of a scene graph hasn’t come up against the limits it imposes.

The thing to realize here is that using graphs and trees to organize various parts of your data is a must in a game. You have state graphs, animation graphs, transform hierarchies, etc. A scene graph tries to force the programmer to use a single structure to store all of them. This mashes together transform location, hierarchy information, and rendering appearance. In Ardor3D and JMonkeyEngine, each node has a transform, it’s parent node and any new appearance states it uses. The final transforms are accumulated together from root to child, along with the final set of appearance states. This means that if you want a sword to be attached to the hand of a soldier, the sword is a child node, but then problems occur because the sword’s appearance is different than the soldier’s. There are ways to get around this but this is how the scene graph devolves into a difficult paradigm.

A scene graph is not just a graph/tree that holds scene data, it is a single graph/tree that holds all of the scene data. Because a scene graph has a well designed graph API, it is often easy to just reuse that framework to create your multiple views but this is limiting. Take the example of transform hierarchies: each complete hierarchy is independent from the others, one soldier with a sword does not need to be linked (by transforms) to any other soldier. I can model this in a graph by having each hierarchy share the common root node, but why not model it as a forest? There are likely to be many more objects in the scene that have no hierarchy, so if you separate out those needing hierarchy processing, you are more efficient.

Oh, I think what you’re trying to say here really is avoid readymade scenegraphs because you will try to shoehorn your peculiar game design into someone else’s idea and it might not work out particularly efficient.

Then again it probably will. YMMV. Choose your tools and APIs carefully! If you followed DzzD’s advice literally nobody would be using Unity, Wurm Online would never have gotten anywhere, in fact neither would Half Life or any number of Quake / Doom based games. And so on. If you’ve got a problem that fits really well with someone’s particular scenegraph implementation you’re laughing. If not - you’ll have to make your own one.

Cas :slight_smile:

So what is the alternative to using a ready made scenegraph? Roll your own?

I agree that scenegraph apis usually try to do too much. They should stick to rendering. If you use it just for rendering then they will give you optimizations like state sorting, view frustum culling, display list/vbo for static meshes. As well as giving you a nice transform hierarchy and retained datastructure of what to render. There are also lots of utilities like model loaders that comes with it.

However sound, physics, gamelogic etc should not be in the scenegraph used for rendering. They belong in the game engine or just the game itself. It is the game engine that ties all the pieces together.

Using a scenegraph will save you a lot of time, depending on the game. Using a game engine like Unity would probably safe you even more. The problem sees that rendering scenegraphs wants to be game engines. And that is not always a good idee.

Again, since I haven’t mentioned it in this thread: Quake, Doom, etc. etc. are NOT scenegraphs. I cannot think of a single high profile game which is a scenegraph. They are all based on SPATIAL PARTITIONING.

Examples of things that are NOT SCENEGRAPHS:

I have a feeling that I haven’t done a good job of describing the topic which I really wished to discuss. In a moderately complex game there needs to be a mechanism to perform geometric queries. This database needs to be able perform the following operations at least reasonably well: add, delete, move and intersection. Where “intersection” tests the contents against some geometric object(s). Some examples include (but are far from limited to):

  • Frustums: potential visible set (hopefully near minimal) for rendering, visually perceived events, etc.
  • Spheres: point lights, broadband collision/nearest neighbors
  • Boxes: broadband collision/nearest neighbors
  • Capsule: broadband collision
  • Lines: cheap line-of-sight and some instantaneous events.

For games that have simple “environments” and few entities, the method of storage is of little importance. As the complexity grows, being able to perform of above and similar operations quickly becomes critical.

To be very repetitive: spatial partitioning techniques are not scenegraphs.

A Scenegraph is a hierarchically data-structure, where states that are applied to a given node propagate to all children. Ignoring all kinds of states other than geometric, this means all nodes are within a local (scaled) coordinate frame of its parent. Now let’s assume that the only geometric operations allowed are linear transforms, which is a reasonable limitation. This means that it is effectively is a direct representation of a ridged body system. This is the “strength” of scenegraphs. The ability to simply manipulate a node and all of the modifications are auto-magically applied to the children. It’s is also what makes it nearly worthless as a “world” representation of any complexity. Some issues:

Since state information is all local, when you need global states either the tree must be traversed, concatenation states, for each query (very bad) or they must be cached. This means when a node is updated that the cached values of all children of the node need to be updated as well. The performance of the update can be reduced with a lot of duct tape and glue to avoid computation until needed.

Likewise the data structure presents no spatial coherence. Specifically there is no way to perform the kind of queries that I listed at the start of this post, other than visiting every entry in the structure. Again concatenating states or yanking cached values as one performs the walk. Wait! Hold the phone! Early on people working on scenegraphs noticed this glaring problem and it can made slightly less bad by maintaining a bounding volume hierarchy (BVH) for each node. This volume (typically bounding box, axis aligned bounding box or sphere) covers the entire “extent” of the node and its children. The implication of this is when a node is modified it updates its BVH, then recursively updates the BVHs of all its parents up to the root. Like the previous issue, with some duct tape and glue this can be deferred until needed. The disadvantage of BVHs vs. spatial partitioning is that in spatial partitioning a point query will only ever need to visit one child of a given node, since no spatial overlap is possible between children. Conversely it is very likely that the BVHs of children in a scenegraph will overlap requiring the query to visit multiple children at a given level.

Taking these last two issues together notice that when a node is modified that all of it children’s information is now dirty and well as all of its parents.

These are only a couple of examples of glaring faults of scenegraphs as a world database. The duct tape and glue to lower the cost of those problems above significantly complicate an already complicated codebase as well as increase the required memory footprint. And one goes to all of this hassle to have a world database that’s good at representing a ridged body system. What’s the last 3D game you played that looked like a rigid body system? In practice it seems that a lot of systems that use scenegraphs end up with most nodes directly off the root. This means that you’re really using a very complicated implemenation of a linked list.

A common complaint made against scenegraphs is rendering related (changing textures, states, shaders, etc). Here I have no problem. I advice using spatial partitioning techniques for world databases which suffer from the exact same problem. Besides if one is performing any “modern” rendering methods, a rendering queue is pretty much required.

However, there is a common thing in games that “do” have something in common with ridged bodies: articulated models and character animation. Scenegraph like systems are work well at the model level since the above issues are moot and the data structure actually matches what is being modeled.

[quote]…
A Scenegraph is a hierarchically data-structure, where states that are applied to a given node propagate to all children. Ignoring all kinds of states other than geometric, this means all nodes are within a local (scaled) coordinate frame of its parent. Now let’s assume that the only geometric operations allowed are linear transforms, which is a reasonable limitation. This means that it is effectively is a direct representation of a ridged body system. This is the “strength” of scenegraphs. The ability to simply manipulate a node and all of the modifications are auto-magically applied to the children. It’s is also what makes it nearly worthless as a “world” representation of any complexity. Some issues:

[/quote]
this is a very specific definition of a scenegraph often used by 3D engine, this is not a general case , what you describe is (I suppose) a commonly used scenegraph for 3D rendering (used by most 3D engine and software ex: 3D studio max ), but this is not a general representation of a Scenegraph ( it is specific even for 3D scenegraph wich can be different )

note that even if I link to, I dont agree with Wikipedia definition wich is itself (a little) contradictory

[quote]A scene graph is a collection of nodes in a graph or tree structure.
[/quote]

[quote]A node may have many children but often only a single parent
[/quote]
=> meaning often a tree… wich I dont agree because once again it is specific, it is not a general definition

Yes it is. Because a Scenegraph is a very specific type of data structure. The term was “coin” by the creators of this method and it is not used in graphics literature to refer to anything else. Calling anything else a Scenegraph is a misuage of the term.

WRT: 3D engines, I feel like a broken record. I’ll just quote myself:

[quote]A node may have many children but often only a single parent
[/quote]
=> meaning often a tree… wich I dont agree because once again it is specific, it is not a general definition
[/quote]
Here I’m not quite understanding your point. It’s not infrequent for a node in a graph to have only a single parent. And anyway from the perspective of a DAG - a tree is simply a special case. (Not that I’m advocating calling a tree a DAG).

[quote]the creators of this method
[/quote]
creator of scenegraph ? what method ?

[quote]Again, since I haven’t mentioned it in this thread: Quake, Doom, etc. etc. are NOT scenegraphs. I cannot think of a single high profile game which is a scenegraph. They are all based on SPATIAL PARTITIONING.
[/quote]
using spatial partitioning does not mean you are not using a scenegraph, scenegraph is a logical representation of the scene data as a graph (usually of the world of game), you can use one or more space partitioning in addition, this does not prevent to use a scenegraph, those games may use some kind of scenegraph in addition to space patitioning even if it dont match the specific scenegraph you described.

[quote]Here I’m not quite understanding your point. It’s not infrequent for a node in a graph to have only a single parent. And anyway from the perspective of a DAG - a tree is simply a special case. (Not that I’m advocating calling a tree a DAG).
[/quote]
no but what they say tend to describe scenegraph as often tree (only one parent), sound impartial and subjective to people often using same scene representaion (like 3d engine) and I understand scenegraph as something more generic.

This word is never used whereas at least Xith3D, JMonkeyEngine and Ardor3D are structured as a tree (sorry I have just begun reading the source code of your engine).

[quote=“Roquen,post:33,topic:36146”]
A graph whose nodes have at most a single parent is … a tree. A tree is an acyclic connected graph where each node has zero or more children nodes and at most one parent node (cf. Wikipedia).

I don’t understand. When I use spatial partitioning, I need to have a hierarchy containing the whole scene.

Poor choice of words on my part. 20 some-odd years ago some programmers at SGI (I believe) developed the technique which I have been describing and they decided to call it a scenegraph (for better or worse). Since that time in professional and academic writings the term “scenegraph” has been used only to refer to this technique and logical extensions of it. All other techniques, regardless if there are implemented as graphs or not and represent scenes or not, use some other name. If anyone thinks that I am incorrect in this statement, then please find me a creditable reference (notably a peer reviewed paper) that contradicts me. I’m not attempting to be “anal” about this without reason. We simply cannot have a meaningful discussion if we use the same term for radically different techniques. To those that wish to call something else a scenegraph, I’d love for them to describe it. I’d much rather this thread be about discussing techinques that “going back-and-forth” over terminology.

[quote][quote]Again, since I haven’t mentioned it in this thread: Quake, Doom, etc. etc. are NOT scenegraphs. I cannot think of a single high profile game which is a scenegraph. They are all based on SPATIAL PARTITIONING.
[/quote]
using spatial partitioning does not mean you are not using a scenegraph, scenegraph is a logical representation of the scene data as a graph (usually of the world of game), you can use one or more space partitioning in addition, this does not prevent to use a scenegraph, those games may use some kind of scenegraph in addition to space patitioning even if it dont match the specific scenegraph you described.
[/quote]
Quake uses a single BSP as the world database. The BSP is traversed for spatial queries and the renderer walks it issuing immediately. There is no other world representation. Entities are stored as a flat list.

The first Unreal is exactly the same, except it uses a forest of BSPs connected by portals.

Quake 3 moves to using forest of BSPs and portals as well. The renderer now places graphics calls into a rendering queue. In addition to the world database, there is a side data structure for “bot” pathfinding.

The various Quake source codes are available, so you can check out what I’m saying for yourself.

[quote]I don’t understand. When I use spatial partitioning, I need to have a hierarchy containing the whole scene.
[/quote]
This is hard to comment on without you giving a description of what you’re doing.

Typically if your world database is some kind of spatial partitioning, then you will not need any other hierarchical representation. However some potential exceptions include: using an external physics library, 3D sound propagation and effects and pathfinding (to name a few).

Well, having cleared that up: what sort of games would you use such a scenegraph for, and what sort of games wouldn’t you use it for? Or would you say that a scenegraph is no good for mostly any sort of game?

Cas :slight_smile: