Spatial Data Structures and Speed-Up Techniques. Ulf Assarsson Department of Computer Science and Engineering Chalmers University of Technology

Similar documents
Spatial Data Structures and Speed-Up Techniques. Tomas Akenine-Möller Department of Computer Engineering Chalmers University of Technology

Speeding up your game

Spatial Data Structures and Acceleration Algorithms

Computer Graphics (CS 543) Lecture 13b Ray Tracing (Part 1) Prof Emmanuel Agu. Computer Science Dept. Worcester Polytechnic Institute (WPI)

Spatial Data Structures

Scene Management. Video Game Technologies 11498: MSc in Computer Science and Engineering 11156: MSc in Game Design and Development

CS 563 Advanced Topics in Computer Graphics Culling and Acceleration Techniques Part 1 by Mark Vessella

Spatial Data Structures

Computer Graphics. Bing-Yu Chen National Taiwan University The University of Tokyo

Acceleration Data Structures. Michael Doggett Department of Computer Science Lund university

Spatial Data Structures and Acceleration Algorithms

Announcements. Written Assignment2 is out, due March 8 Graded Programming Assignment2 next Tuesday

Motivation. Culling Don t draw what you can t see! What can t we see? Low-level Culling

l Without collision detection (CD), it is practically impossible to construct e.g., games, movie production tools (e.g., Avatar)

Spatial Data Structures

Computer Graphics. Bing-Yu Chen National Taiwan University

Spatial Data Structures

Spatial Data Structures

Tomas Akenine-Möller Department of Computer Engineering Chalmers University of Technology

Culling. Computer Graphics CSE 167 Lecture 12

Using Bounding Volume Hierarchies Efficient Collision Detection for Several Hundreds of Objects

TDA362/DIT223 Computer Graphics EXAM (Same exam for both CTH- and GU students)

Ray Tracing Acceleration Data Structures

Computer Graphics. Lecture 9 Hidden Surface Removal. Taku Komura

Acceleration Data Structures

Accelerating Geometric Queries. Computer Graphics CMU /15-662, Fall 2016

Lecture 25 of 41. Spatial Sorting: Binary Space Partitioning Quadtrees & Octrees

Ray Tracing III. Wen-Chieh (Steve) Lin National Chiao-Tung University

Hidden surface removal. Computer Graphics

Hidden Surface Elimination: BSP trees

Universiteit Leiden Computer Science

Clipping & Culling. Lecture 11 Spring Trivial Rejection Outcode Clipping Plane-at-a-time Clipping Backface Culling

LOD and Occlusion Christian Miller CS Fall 2011

COMP 175: Computer Graphics April 11, 2018

CSE 167: Introduction to Computer Graphics Lecture #10: View Frustum Culling

Intersection Acceleration

Acceleration Data Structures for Ray Tracing

INFOGR Computer Graphics. J. Bikker - April-July Lecture 11: Acceleration. Welcome!

S U N G - E U I YO O N, K A I S T R E N D E R I N G F R E E LY A VA I L A B L E O N T H E I N T E R N E T

CPSC / Sonny Chan - University of Calgary. Collision Detection II

Bounding Volume Hierarchies

CSE 167: Introduction to Computer Graphics Lecture #9: Visibility. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2018

Overview. Pipeline implementation I. Overview. Required Tasks. Preliminaries Clipping. Hidden Surface removal

Sung-Eui Yoon ( 윤성의 )

CS535 Fall Department of Computer Science Purdue University

CSE 167: Introduction to Computer Graphics Lecture #11: Visibility Culling

Algorithms for GIS:! Quadtrees

EECE 478. Learning Objectives. Learning Objectives. Rasterization & Scenes. Rasterization. Compositing

Lecture 11: Ray tracing (cont.)

Space-based Partitioning Data Structures and their Algorithms. Jon Leonard

Real-Time Rendering (Echtzeitgraphik) Dr. Michael Wimmer

CS451Real-time Rendering Pipeline

TDA361/DIT220 Computer Graphics, January 15 th 2016

improving raytracing speed

Bounding Volume Hierarchies. CS 6965 Fall 2011

Visibility and Occlusion Culling

Computer Graphics. - Spatial Index Structures - Philipp Slusallek

More Hidden Surface Removal

Computer Graphics. - Ray-Tracing II - Hendrik Lensch. Computer Graphics WS07/08 Ray Tracing II

Last Time: Acceleration Data Structures for Ray Tracing. Schedule. Today. Shadows & Light Sources. Shadows

Page 1. Area-Subdivision Algorithms z-buffer Algorithm List Priority Algorithms BSP (Binary Space Partitioning Tree) Scan-line Algorithms

11 - Spatial Data Structures

Today. Acceleration Data Structures for Ray Tracing. Cool results from Assignment 2. Last Week: Questions? Schedule

Ulf Assarsson Department of Computer Engineering Chalmers University of Technology

Shadow Rendering EDA101 Advanced Shading and Rendering

Topic 10: Scene Management, Particle Systems and Normal Mapping. CITS4242: Game Design and Multimedia

Recall: Inside Triangle Test

Project Gotham Racing 2 (Xbox) Real-Time Rendering. Microsoft Flighsimulator. Halflife 2

Lecture 2 - Acceleration Structures

Speeding Up Ray Tracing. Optimisations. Ray Tracing Acceleration

Chapter 11 Global Illumination. Part 1 Ray Tracing. Reading: Angel s Interactive Computer Graphics (6 th ed.) Sections 11.1, 11.2, 11.

Visible Surface Detection. (Chapt. 15 in FVD, Chapt. 13 in Hearn & Baker)

Spatial Data Structures for Computer Graphics

CS 563 Advanced Topics in Computer Graphics QSplat. by Matt Maziarz

Point Cloud Filtering using Ray Casting by Eric Jensen 2012 The Basic Methodology

CSE 167: Lecture #5: Rasterization. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2012

Ray Tracing: Intersection

Accelerating Ray-Tracing

Geometry proxies (in 2D): a Convex Polygon

Homework 1: Implicit Surfaces, Collision Detection, & Volumetric Data Structures. Loop Subdivision. Loop Subdivision. Questions/Comments?

Ray-tracing Acceleration. Acceleration Data Structures for Ray Tracing. Shadows. Shadows & Light Sources. Antialiasing Supersampling.

Comparison of hierarchies for occlusion culling based on occlusion queries

Advanced 3D-Data Structures

INFOGR Computer Graphics. J. Bikker - April-July Lecture 11: Visibility. Welcome!

Ray Tracing. Cornell CS4620/5620 Fall 2012 Lecture Kavita Bala 1 (with previous instructors James/Marschner)

Computing Visibility. Backface Culling for General Visibility. One More Trick with Planes. BSP Trees Ray Casting Depth Buffering Quiz

CSE528 Computer Graphics: Theory, Algorithms, and Applications

Ray Tracing with Spatial Hierarchies. Jeff Mahovsky & Brian Wyvill CSC 305

Accelerated Raytracing

Advanced Ray Tracing

Geometric Algorithms. Geometric search: overview. 1D Range Search. 1D Range Search Implementations

Binary Space Partition Trees. Overview. Binary Space Partitioning Trees (Fuchs, Kedem and Naylor `80)

Collision Detection. These slides are mainly from Ming Lin s course notes at UNC Chapel Hill

CSE328 Fundamentals of Computer Graphics: Concepts, Theory, Algorithms, and Applications

Wed, October 12, 2011

Virtual Environments

Hidden Surface Elimination Raytracing. Pre-lecture business. Outline for today. Review Quiz. Image-Space vs. Object-Space

Ray Tracing. Computer Graphics CMU /15-662, Fall 2016

Spatial Data Structures. Steve Rotenberg CSE168: Rendering Algorithms UCSD, Spring 2017

Particle systems, collision detection, and ray tracing. Computer Graphics CSE 167 Lecture 17

Transcription:

Spatial Data Structures and Speed-Up Techniques Ulf Assarsson Department of Computer Science and Engineering Chalmers University of Technology

Exercises l Create a function (by writing code on paper) that tests for intersection between: two spheres a ray and a sphere view frustum and a sphere Ray and triangle (e.g. use formulas from last lecture) l Make sure you understand matrices: Give a scaling matrix, translation matrix, rotation matrix and simple orthogonal projection matrix

Ray/sphere test l Ray: r(t)=o+td l Sphere center: c, and radius r l Sphere formula: p-c =r l Replace p by r(t), and square it: ( o + td -c) ( o + td -c) - r 2 = 0 t 2 + 2((o c) d)t + (o c) (o c) r 2 = 0 ax 2 +bx + c = 0 x = b 2a ± $ b ' & ) % 2a( 2 c a Bool raysphereintersect(vec3f o, d, c, float r, Vec3f &hitpt) { float b = 2.0f*((o-c).dot(d)); // dot is implemented in class Vec3f float c = (o-c).dot(o-c); if(b*b/4.0f<c) return false; float t = -b/(2.0f) - sqrt(b*b/4.0f-c); // intersection for smallest t if (t<0) t = -b/(2.0f*a) + sqrt(b*b/4.0f-c); // larger t if (t<0) return false; else hitpt = o+d*t; // where * is an operator for vec mul return true; } o d r c

Misc l Half Time wrapup slides are available in Schedule on home page l There is an Advanced Computer Graphics Seminar Course in sp 3+4, 7.5p One seminar every week l Advanced CG techniques Do a project of your choice. Register to the course

Spatial data structures l What is it? Data structure that organizes geometry in 2D or 3D or higher The goal is faster processing Needed for most speed-up techniques l Faster real-time rendering l Faster intersection testing l Faster collision detection l Faster ray tracing and global illumination l Games use them extensively l Movie production rendering tools always use them too l (You may read Designing a PC Game Engine. Link available on website)

How? l Organizes geometry in some hierarchy In 2D space Data structure In 3D space: Tomas Akenine-Mőller 2002

What s the point? An example l Assume we click on screen, and want to find which object we clicked on click! 1) Test the root first 2) Descend recursively as needed 3) Terminate traversal when possible In general: get O(log n) instead of O(n)

3D example click!

Bounding Volume Hierarchy (BVH) l Most common bounding volumes (BVs): Sphere Boxes (AABB and OBB) l The BV does not contibute to the rendered image -- rather, encloses an object l The data structure is a k-ary tree Leaves hold geometry Internal nodes have at most k children Internal nodes hold BVs that enclose all geometry in its subtree

Some facts about trees l Height of tree, h, is longest path from root to leaf l A balanced tree is full except for possibly missing leaves at level h l Height of balanced tree with n nodes: floor( log k (n) ) l Binary tree (k=2) is the simplest k=4 and k=8 is quite common for computer graphics as well

How to create a BVH? Example: BV=AABB l Find minimal box, then split along longest axis x is longest Find minimal boxes Split along longest axis Find minimal boxes Called TOP-DOWN method Works similarly for other BVs

Stopping criteria for Top-Down creation l Need to stop recursion some time Either when BV is empty Or when only one primitive (e.g. triangle) is inside BV Or when <n primitives is inside BV Or when recursion level l has been reached l Similar critera for BSP trees and octrees

Example Killzone (2004- PS2) used kdtree / AABBtree based system for the collision detection Kd-tree = Axis Aligned BSP tree

Binary Space Partitioning (BSP) Trees l Two different types: Axis-aligned Polygon-aligned l General idea: Split space with a plane Divide geometry into the space it belongs Done recursively l If traversed in a certain way, we can get the geometry sorted back-to-front or front-to-back w.r.t. a camera position Exact for polygon-aligned Approximately for axis-aligned

Axis-Aligned BSP tree (1) Split space with a plane Divide geometry into the space it belongs Done recursively l Can only make a splitting plane along x,y, or z Minimal box Split along plane Split along plane Split along plane

Axis-Aligned BSP tree (2) A Plane 1a B D Plane 0 Plane 2 Plane 1b 0 E 1a 1b A B C 2 C D E l Each internal node holds a divider plane l Leaves hold geometry l Differences compared to BVH BSP tree encloses entire space and provides sorting The BV hierarchy can have spatially overlapping nodes(no sort) BVHs can use any desirable type of BV

Axis-aligned BSP tree Rough sorting l 1a Test the planes, recursively from root, against the point of view. For each traversed node: If node is leaf, draw the node s geometry else l l 0 Continue traversal on the hither side with respect to the eye (to sort front to back) Then, continue on the farther side. 2 1b eye A 1a B 4 5 0 1b C 2 l Works in the same way for polygonaligned BSP trees --- but that gives exact sorting 1 D 3 E 2

Polygon Aligned BSP tree Quake 2

Example Quake 2

Polygon-aligned BSP tree l Allows exact sorting l Very similar to axis-aligned BSP tree But the splitting plane are now located in the planes of the triangles Drawing Back-to-Front { recurse on farther side of P; Draw P; Recurse on hither side of P; } //Where hither and farther are with respect to viewpoint v

Algorithm for BSP trees Tree CreateBSP(PolygonList L) { If L empty, return empty tree; Else: T->P = arbitrary polygon in L. T->behindP = CreateBSP(polygons behind P) T->frontOfP = CreateBSP(polygons in front of P) Return T. } Drawing Back-to-Front: void DrawBSP(Tree t) { If (t==null) return; } If eye front of polygon t->p: DrawBSP(t->behindP); Draw P; DrawBSP(t->frontOfP); Else: DrawBSP(t->frontOfP); Draw P; DrawBSP(t->behindP); class BSPtree: Polygon P; BSPtree behindp; BSPtree frontofp; Drawing Back-to-Front { recurse on farther side of P; Draw P; Recurse on hither side of P; } Ulf Assarsson 2006

Octrees (1) l A bit similar to axis-aligned BSP trees l Will explain the quadtree, which is the 2D variant of an octree l In 3D, each square (or rectangle) becomes a box, and 8 children

Example of Octree Recursively split space in eight parts equaly along x,y,z dimension simultaneously for each level

Example of octree Image from Lefebvre et al.

Example of octree Image from Lefebvre et al.

Octrees (2) l Expensive to rebuild (BSPs are too) l (loose octrees, page 656, 3:rd ed.) A relaxation to avoid problems l Octrees can be used to Speed up ray tracing Faster picking Culling techniques Are not used that often in real-time contexts l An exception is loose octrees

Scene graphs l BVH is the data structure that is used most often Simple to understand Simple code l However, it stores just geometry Rendering is more than geometry l The scene graph is an extended BVH with: Lights Materials Transforms And more Typically the logical structure

Scene Graphs Star system Sun Transl + Rotation Transl + rotation Planet 1 Planet 2 Planet Transl + rot Transl + rot Transl + rot Transl + rot Planet Moon A Moon B Moon C Moon D

Scene Graphs

Scene Graphs

Speed-Up Techniques l Spatial data structures are used to speed up rendering and different queries l Why more speed? l Graphics hardware 2x faster in 6-12 months! l Wait then it will be fast enough! l NOT! l We will never be satisfied Screen resolution: angular resolution in gula fläcken ~0.001 degree (eye sweeps scene) l Apple s retina screen: 2880 x 1800 Realism: global illumination Geometrical complexity: no upper limit!

What we ll treat now l Culling techniques l Level-of-detail rendering (LODs) l To cull means to select from group Sort out, remove, cut away, something picked out and put aside as inferior. l In graphics context: do not process data that will not contribute to the final image

Different culling techniques (red objects are skipped) view frustum detail backface occlusion

Backface Culling l Simple technique to discard polygons that faces away from the viewer l Can be used for: closed surface (example: sphere) or whenever we know that the backfaces never should be seen (example: walls in a room) l Two methods (screen space, eye space) l Which stages benefits? l Rasterizer stage

Backface culling (cont d) l l l l Often implemented for you in the API OpenGL: l glcullface(gl_back); l glenable(gl_cull_face); How to determine what faces away? First, must have consistently oriented polygons, e.g., counterclockwise 2 0 1 front facing 1 back facing 2 0

How to cull backfaces l Two ways in different spaces: 1 2 2 eye back 1 0 front back screen space 0 eye space front

View-Frustum Culling l Bound every natural group of primitives by a simple volume (e.g., sphere, box) l If a bounding volume (BV) is outside the view frustum, then the entire contents of that BV is also outside (not visible)

Can we accelerate view frustum culling further? l Do what we always do in graphics l Use a hierarchical approach, e.g., a spatial data structure (BVH, BSP) l Which stages benefits? Geometry and Rasterizer Possibly also bus between CPU and Geometry

Example of Hierarchical View Frustum Culling root camera

Portal Culling Refined view frustum culling: frustum gets smaller for each door Images courtesy of David P. Luebke and Chris Georges l Average: culled 20-50% of the polys in view l Speedup: from slightly better to 10 times

Portal culling example l In a building from above l Circles are objects to be rendered

Portal Culling Algorithm (1) l Divide into cells with portals (build graph) l For each frame: Locate cell of viewer and init 2D AABB to whole screen * Render current cell with View Frustum culling w.r.t. AABB Traverse to closest cells (through portals) Intersection of AABB & AABB of traversed portal Goto *

Portal Culling Algorithm (2) l When to exit: When the current AABB is empty When we do not have enough time to render a cell ( far away from the viewer) l Also: mark rendered objects

Occlusion Culling l Main idea: Objects that lies completely behind another set of objects can be culled l Hard problem to solve efficiently l Has been lots of research in this area l OpenGL: Occlusion Queries

Example final image l Note that Portal Culling is type of occlusion culling

Occlusion culling algorithm Use some kind of occlusion representation O R for each object g do: if( not Occluded(O R,g)) render(g); update(o R,g); end; end;

Level-of-Detail Rendering l Use different levels of detail at different distances from the viewer l More triangles closer to the viewer

LOD rendering l Not much visual difference, but a lot faster l Use area of projection of BV to select appropriate LOD

Scene graph with LODs Large area Car chair Area? medium area small area

Far LOD rendering l When the object is far away, replace with a quad of some color l When the object is really far away, do not render it (called: detail culling)! l Use projected area of BV to determine when to skip

Misc l Half Time wrapup slides will be available in Schedule on home page l There is an Advanced Computer Graphics Seminar Course in sp 3+4, 7.5p One seminar every week l Discussing advanced CG papers and techniques Do a project of your choice. Register to the course

Exercise l Create a function (by writing code on paper) that performs hierarchical view frustum culling void hierarchicalvfc(node* scenegraphnode)

What you need to know l l l l l l l l Top-down construction of BVH, AABSP-tree, Construction + sorting with AABSP and Polygon- Aligned BSP Octree/quadtree (skip loose octrees) Scene Graphs (briefly) Culling VFC, Portal, Detail, Backface, Occlusion Backface culling screenspace is robust, eyespace non-robust. What is LODs Describe how to build and use BVHs, AABSP-tree, Polygon aligned BSP-tree. Describe the octree/quadtree.

BONUS MATERIAL Occlusion Horizon l Target: urban scenery dense occlusion viewer is about 2 meters above ground l Algorithm: Process scene in front-to-back using a quad tree Maintain a piecewise constant horizon Cull objects against horizon Add visible objects occluding power to the horizon Tomas Akenine-Mőller 2002

Occlusion testing with occlusion horizons l To process tetrahedron (which is behind grey objects): find axis-aligned box of projection compare against occlusion horizon culled Tomas Akenine-Mőller 2002

Update horizon l When an object is considered visible: l Add its occluding power to the occlusion representation Tomas Akenine-Mőller 2002

Example: l Read about the details in paper on website (compulsory material!) Tomas Akenine-Mőller 2002