Chapter 5 - the Scene Graph
Total Page:16
File Type:pdf, Size:1020Kb
Chapter 5 - The Scene Graph • Why a scene graph? • What is stored in the scene graph? – objects – appearance – camera – lights • Rendering with a scene graph • Practical example LMU München – Medieninformatik – Andreas Butz – Computergrafik 1 – SS2015 – Kapitel 5 1 The 3D Rendering Pipeline (our version for this class) 3D models in 3D models in world 2D Polygons in Pixels in image model coordinates coordinates camera coordinates coordinates Scene graph Camera Rasterization Animation, Lights Interaction LMU München – Medieninformatik – Andreas Butz – Computergrafik 1 – SS2015 – Kapitel 5 2 Why a Scene Graph? • Naive approach: – for each object in the scene, set its transformation by a single matrix (i.e., a tree 1 level deep and N nodes wide) • advantage: very fast for rendering • disadvantage: if several objects move, all of their transforms change • Observation: Things in the world are made from parts • Approach: define an object hierarchy along the part-of relation – transform all parts only relative to the whole group – transform group as a whole with another transform – parts can be groups again http://www.bosy-online.de/Veritherm/Explosionszeichnung.jpg LMU München – Medieninformatik – Andreas Butz – Computergrafik 1 – SS2015 – Kapitel 5 3 Chapter 5 - The Scene Graph • Why a scene graph? • What is stored in the scene graph? – objects – appearance – camera – lights • Rendering with a scene graph • Practical example LMU München – Medieninformatik – Andreas Butz – Computergrafik 1 – SS2015 – Kapitel 5 4 Geometry in the Scene Graph • Leafs are basic 3D objects • Non-leaf nodes (groups) contain a transformation Welt – can have one or several children – transformation is given by a homogeneous Matrix Auto TAuto • Root is the entire world TKarosserie Karosserie Räder TRäder • Nodes can be the child of several groups TChassis Chassis Kabine grau Rad1 Rad2 Rad3 Rad4 – not a tree, but a directed T Kabine acyclic graph (DAG) Quader1 Quader2 Rad – effective reuse of geometry Felge Reifen Zylinder1 weiß Zylinder2 schwarz LMU München – Medieninformatik – Andreas Butz – Computergrafik 1 – SS2015 – Kapitel 5 5 Appearance in the Scene Graph • Scene graph also contains appearances – Appearance: E.g. Color, reflection, transparency, texture Details see next lecture – can be reused similarly to geometry Auto ! • Appearance can be only partially specified Karosserie Räder – unspecified values are inherited Chassis Kabine grau Rad1 Rad2 Rad3 Rad4 Quader1 Quader2 Rad Felge Reifen Zylinder1 weiß Zylinder2 schwarz LMU München – Medieninformatik – Andreas Butz – Computergrafik 1 – SS2015 – Kapitel 5 6 Lights in the Scene Graph • Light sources also need a position and/or direction Welt – Just include them into the scene graph Sonne – Can be animated just like geometry Auto ! Licht1 • Lights can be in local coordinate Karosserie Räder systems of geometry groups – move with them Chassis Kabine grau Rad1 Rad2 Rad3 Rad4 – example: lights on a car Quader1 Quader2 Rad Felge Reifen Zylinder1 weiß Zylinder2 schwarz LMU München – Medieninformatik – Andreas Butz – Computergrafik 1 – SS2015 – Kapitel 5 7 The Camera in the Scene Graph • Camera also needs a position and direction – Just include it into the scene graph Welt – Can be animated just like geometry Kamera Sonne ! Auto • Camera can be in local coordinate Kamera1 Licht1 systems of geometry groups Karosserie Räder – move with them – example: driver‘s view from a car Chassis Kabine grau Rad1 Rad2 Rad3 Rad4 Quader1 Quader2 Rad Felge Reifen Zylinder1 weiß Zylinder2 schwarz LMU München – Medieninformatik – Andreas Butz – Computergrafik 1 – SS2015 – Kapitel 5 8 Chapter 5 - The Scene Graph • Why a scene graph? • What is stored in the scene graph? – objects – appearance – camera – lights • Rendering with a scene graph • Practical example LMU München – Medieninformatik – Andreas Butz – Computergrafik 1 – SS2015 – Kapitel 5 9 Scene graph traversal for rendering • set Tact to TAuto Auto • push state • set Tact to Tact x TKarosserie • push state Karosserie Räder • set Tact to Tact x TChassis • render Quader1 Chassis Kabine grau Rad1 Rad2 Rad3 Rad4 • pop state • set Tact to Tact x TKabine Quader1 Quader2 Rad • render Quader2 • pop state • pop state Felge Reifen • set Tact to Tact x TRäder • ... Zylinder1 weiß Zylinder2 schwarz LMU München – Medieninformatik – Andreas Butz – Computergrafik 1 – SS2015 – Kapitel 5 10 Scene Graph Libraries • Scene graphs exist on a more abstract layer than OpenGL! • VRML/X3D – descriptive text format, ISO standard • OpenInventor – based on C++ and OpenGL – originally Silicon Graphics, 1988 – now supported by VSG3d.com • Java3D – provides 3D data structures in Java – not supported anymore • Open Scene Graph (OSG) http://www.shlomifish.org/open-source/bits-and-bobs/open-inventor-bsd-daemon/ • Various Game Engines – e.g. JMonkey 3 (scene graph based game engine for Java) LMU München – Medieninformatik – Andreas Butz – Computergrafik 1 – SS2015 – Kapitel 5 11 Scene Graphs in Practice • Creation of scene graphs and objects – Specific authoring software (e.g. Blender, Maya, 3DS Max) • Assets (models, objects) exported to exchange formats – E.g. (X3D,) Wavefront OBJ (.obj), 3ds Max (.3ds), Ogre XML (.mesh) • Objects typically are tesselated – Polygon meshes – No primitive geometric objects visible/readable anymore • Example: – JME Scene Viewer / Composer LMU München – Medieninformatik – Andreas Butz – Computergrafik 1 – SS2015 – Kapitel 5 12 Chapter 5 - The Scene Graph • Why a scene graph? • What is stored in the scene graph? – objects – appearance – camera – lights • Rendering with a scene graph • Practical example LMU München – Medieninformatik – Andreas Butz – Computergrafik 1 – SS2015 – Kapitel 5 13 Example of a scene graph • Graph to be drawn together in the lecture • VRML world linked from the class page LMU München – Medieninformatik – Andreas Butz – Computergrafik 1 – SS2015 – Kapitel 5 14 .