Engine Basics: Optimizing Geometry CS 446: Real-Time Rendering & Game Technology David Luebke University of Virginia Demo Time • SIGN UP SHEET • Today: Fight Night videos Real-Time Rendering 2 David Homework • The pitch: “due” Tuesday, keep pitching • The game: due today at midnight Real-Time Rendering 3 David Recap: Scene Graph Node Examples • • • • Objects Groups of objects LOD selectors Animation “effectors” – – – – • Transforms • Useful state – Bounding boxes, partitions • Graphics state – Which textures, shaders bound – Material – Other state - glEnable(GL_FOO) “Flipbook” animation selectors Transform drivers Deformers Skeletal animation players • “Raw” geometry – Vertices and triangles • Lights! • Cameras! Note: often actual geometry only exists at leaves Real-Time Rendering 4 David Scene Graph Traverals • Classical use of scene graph: – Traverse in depth-first fashion – Apply effects of “action” nodes when reached • LOD selectors, animation effectors – Push/pop matrices when reach/leave xform nodes – Issue geometry as reached • Not very efficient for complex scenes (why?) – – – – Unnecessary pushing/popping Constantly switching graphics state No spatial organization Lots of recalculation for multiple passes Real-Time Rendering 5 David Scene Graph Traversals • Can optimize traversal logic several ways, e.g.: – Cache per-frame computations: bbox, matrices – Flatten hierarchy for unchanging subgraphs – Call animation effectors first & update bboxes bottom-up • Visibility computations affect traversal – View-frustum culling: top-down, separate visibility grid – Cells & portals: portals can be special arcs – Other: BSP trees, 2.5D from-region, fog-of-war Real-Time Rendering 6 David Scene Graph Traversals • Common traversals: – Simple depth-first. Optional: • View-frustum culling or other visibility scheme • Different LOD biases • Cache bbox/visibility/matrix info for later passes – Rough front-to-back sort – Sorted by state – Geometry-only Real-Time Rendering 7 David Efficient Rendering • So leaves of the scene graph represent geometry… • How to efficiently represent that geometry? – Hint: not like this: typedef float Point[3]; typedef Point Triangle[3]; Triangle tris[] = new Triangle[ntris]; ... glBegin(GL_TRIANGLES); for (i=0;i<nverts;i++) { glVertex3fv(tris[i][0]); glVertex3fv(tris[i][1]); glVertex3fv(tris[i][2]); } glEnd(); Real-Time Rendering 8 David 5 Steps to Efficient Rendering • • • • • Step 1: reduce #vertices/triangle Step 2: reduce overhead of each vertex Step 3: recognize the existence of the vertex cache Step 4: display lists (deprecated re: performance) Step 5: learn about the hardware Real-Time Rendering 9 David Other things you should know • Most interesting stuff in OpenGL isn’t in red book – Extension registry • http://oss.sgi.com/projects/ogl-sample/registry/ • Extensions you should know: – – – – – – – – – Real-Time Rendering ARB_multitexture EXT_framebuffer_object ARB_occlusion_query ARB_point_sprite ARB_texture_rectangle ARB_draw_buffers ARB_texture_float (_framebuffer_float, _half_float_pixel, etc) ARB_depth_texture ARB_vertex_buffer_object (_pixel_buffer_object) 10 David Coming Up • Next topic: programmable graphics hardware – We’ll use NVIDIA’s Cg language because I know it – Similar alternatives: • Microsoft’s HLSL for DirectX • OpenGL Shading Language (GLSL, once Glslang) – Different approach: Sh Real-Time Rendering 11 David