Friday, 22 November 2013

Scene Graphs

Scene graphs are a very helpful tool when design games. They are used to show the relationships between objects in the game. Scene graph form a hierarchy where certain objects can be parents or children of other objects. These scene graphs are a collection of nodes and edges that form a graph or a tree. These nodes are connected by their edges spatially or physically.  


This is a really basic example of a simple scene graph of a typical house. The nodes show what the objects are of the house and the graph also shows how each object is related to each other. The desk would be the child of the bedroom but the parent of the computer. Or the pillow would be the child of the bed but the pillow is not a parent at all. The house node has 3 children but no parents, which makes the house the root node. 

Scene graphs are great for managing objects in a scene but what else can they do? If a game has any type of animation with a object, there most likely a transformation happening during the animations. When using a scene graph, if a transformation is applied to a parent node, all its children will be affected by it. 


Here is another scene graph with the bones in a human hand/arm. When a transformation is applied to the parent nodes, the children nodes will all be affected by it. Try moving your wrist around, your fingers and the palm of your hand will also move to a new position. If you try moving the tips of your fingers, other parts of your body will not move. This means that the fingers are a child to the palm of the hand. Therefore when a transformation is applied to a parent node, all children of that node is also transformed. But when rotating, there is a certain pivot points that the object rotates around. Parent nodes will rotate in their object space but what about the children? Children nodes will also rotate around the same point as their parents because of the hierarchy created by the scene graph.

Just like for animations and transformations, shaders and effects can also be used with the help of scene graphs. With the use of scene graphs, effects can be applied to the parent and also the children of the parent. For example, if you were to use shadows inside a building, the game would implement shaders in the whole building (since it is the parent node). All objects in the building will also have a shadow, but objects outside of the building will not. This greatly helps with the rendering that the game has to do because it is not rendering shadows outside of the building. Also documentation will be cleaner since the programmer will not have to apply shadows to every single object in the building, just the parent node.

 Scene graphs are a core component of a game engine. It helps organize/manage objects in a scene, create certain groups and relationships between objects (hierarchy), group transformations and shader effects. 

No comments:

Post a Comment