Maths & Technologies for Games Spatial Partitioning 2

Slides:



Advertisements
Similar presentations
Visible-Surface Detection(identification)
Advertisements

GR2 Advanced Computer Graphics AGR
Christian Lauterbach COMP 770, 2/16/2009. Overview  Acceleration structures  Spatial hierarchies  Object hierarchies  Interactive Ray Tracing techniques.
Spatial Indexing SAMs. Spatial Indexing Point Access Methods can index only points. What about regions? Z-ordering and quadtrees Use the transformation.

Advanced Light and Shadow Culling Methods Eric Lengyel.
Ray Tracing CMSC 635. Basic idea How many intersections?  Pixels  ~10 3 to ~10 7  Rays per Pixel  1 to ~10  Primitives  ~10 to ~10 7  Every ray.
CSE 381 – Advanced Game Programming Scene Management
Visibility Culling. Back face culling View-frustrum culling Detail culling Occlusion culling.
Korea Univ. Graphics Lab. 3D Game Engine Design Chapter 12. Spatial Sorting Chung Ji Hye
Week 14 - Monday.  What did we talk about last time?  Bounding volume/bounding volume intersections.
Space Partitioning for Broad Sweep Collision Detection Part 2 - Quadtrees Game Design Experience Professor Jim Whitehead February 13, 2009 Creative Commons.
Query Processing in Databases Dr. M. Gavrilova.  Introduction  I/O algorithms for large databases  Complex geometric operations in graphical querying.
1 Dr. Scott Schaefer Hidden Surfaces. 2/62 Hidden Surfaces.
Multiple-key indexes Index on one attribute provides pointer to an index on the other. If V is a value of the first attribute, then the index we reach.
Tomas Mőller © 2000 Speeding up your game The scene graph Culling techniques Level-of-detail rendering (LODs) Collision detection Resources and pointers.
Introduction General Data Structures - Arrays, Linked Lists - Stacks & Queues - Hash Tables & Binary Search Trees - Graphs Spatial Data Structures -Why.
A lion in the desert How do you find a lion in the desert? How about when you have a predicate that tells you if the lion is in front or behind a separating.
Introduction General Data Structures - Arrays, Linked Lists - Stacks & Queues - Hash Tables & Binary Search Trees - Graphs Spatial Data Structures -Why.
A lion in the desert How do you find a lion in the desert? How about when you have a predicate that tells you if the lion is in front or behind a separating.
Bounding Volume Hierarchies and Spatial Partitioning Kenneth E. Hoff III COMP-236 lecture Spring 2000.
1 Advanced Scene Management System. 2 A tree-based or graph-based representation is good for 3D data management A tree-based or graph-based representation.
10/11/2001CS 638, Fall 2001 Today Kd-trees BSP Trees.
10/02/03CS679 - Fall Copyright Univ. of Wisconsin Last Time Octrees.
Introduction to 3D Graphics John E. Laird. Basic Issues u Given a internal model of a 3D world, with textures and light sources how do you project it.
Hidden Surface Removal
BSP Trees, Quadtrees & Octrees Glenn G. Chappell U. of Alaska Fairbanks CS 481/681 Lecture Notes Wednesday, January 28, 2004.
Computer Graphics 2 Lecture x: Acceleration Techniques for Ray-Tracing Benjamin Mora 1 University of Wales Swansea Dr. Benjamin Mora.
Spatial Data Structures Jason Goffeney, 4/26/2006 from Real Time Rendering.
Managing Your Objects Paul Taylor 2009 Assignment Due Fri 5/6/2009.
10/09/2001CS 638, Fall 2001 Today Spatial Data Structures –Why care? –Octrees/Quadtrees –Kd-trees.
1 Speeding Up Ray Tracing Images from Virtual Light Field Project ©Slides Anthony Steed 1999 & Mel Slater 2004.
The Visibility Problem In many environments, most of the primitives (triangles) are not visible most of the time –Architectural walkthroughs, Urban environments.
On a Few Ray Tracing like Algorithms and Structures. -Ravi Prakash Kammaje -Swansea University.
Visible-Surface Detection Jehee Lee Seoul National University.
1 Advanced Scene Management. 2 This is a game-type-oriented issue Bounding Volume Hierarchies (BVHs) Binary space partition trees (BSP Trees) “Quake”
PRESENTED BY – GAURANGI TILAK SHASHANK AGARWAL Collision Detection.
Using BSP for CD Ref: BSP in deBerg et al ’ s book (url)url.
2 COEN Computer Graphics I Evening’s Goals n Discuss application bottleneck determination n Discuss various optimizations for making programs execute.
CIS 350 – I Game Programming Instructor: Rolf Lakaemper.
David Luebke11/26/2015 CS 551 / 645: Introductory Computer Graphics David Luebke
CSCE 552 Spring D Models By Jijun Tang. Triangles Fundamental primitive of pipelines  Everything else constructed from them  (except lines and.
Ray Tracing Fall, Introduction Simple idea  Forward Mapping  Natural phenomenon infinite number of rays from light source to object to viewer.
Spatial Indexing Techniques Introduction to Spatial Computing CSE 5ISC Some slides adapted from Spatial Databases: A Tour by Shashi Shekhar Prentice Hall.
Ray Tracing II. HW1 Part A due October 10 Camera module Object module –Read from a file –Sphere and Light only Ray tracer module: –No shading. No reflection.
R-Trees: A Dynamic Index Structure For Spatial Searching Antonin Guttman.
Maths & Technologies for Games Spatial Partitioning 1 CO3303 Week 8-9.
Honours Graphics 2008 Session 5. Today’s focus Rasterization Visibility determination Coarse / fine visibility determination.
CSE554Contouring IISlide 1 CSE 554 Lecture 5: Contouring (faster) Fall 2015.
1 CSCE 441: Computer Graphics Hidden Surface Removal Jinxiang Chai.
Game Engine Design Quake Engine Presneted by Holmes 2002/12/2.
01/28/09Dinesh Manocha, COMP770 Visibility Computations Visible Surface Determination Visibility Culling.
BSP Tree Supplement Jyun-Ming Chen. Fall Kd-Tree and BSP tree kd-tree is a special kind of bsp tree.
David Luebke 3/5/2016 Advanced Computer Graphics Lecture 4: Faster Ray Tracing David Luebke
1 Advanced Scene Management. 2 This is a game-type-oriented issue Bounding Volume Hierarchies (BVHs) Binary space partition trees (BSP Trees) “Quake”
Solid Modeling Dr. Scott Schaefer.
Hierarchical Data Structure in Game Programming Yanci Zhang Game Programming Practice.
CS552: Computer Graphics Lecture 28: Solid Modeling.
Spatial Data Management

Bounding Volume Hierarchies and Spatial Partitioning
Bounding Volume Hierarchies and Spatial Partitioning
Hidden Surfaces Dr. Scott Schaefer.
Modeliranje kompleksnih modelov
Query Processing in Databases Dr. M. Gavrilova
CSCE 441: Computer Graphics Hidden Surface Removal
Quadtrees 1.
CS679 - Fall Copyright Univ. of Wisconsin
Modeliranje kompleksnih modelov
Presentation transcript:

Maths & Technologies for Games Spatial Partitioning 2 CO3303 Week 9

Contents Introduction Grid-based Partitions Quad-Trees / Oct-Trees Binary Space Partitioning

Introduction / Recap Dividing a game world into partitions has many uses Have looked at PVS & portal systems To cull unseen partitions Such visibility techniques also useful for AI entities Here we introduce a range of tree-based partitions BSP / Quad / Oct trees

Grids as Spatial Partitions One of the most intuitive spatial partitions is a grid Can collect local entities for visibility culling, AI etc. Can be used to map terrain: Height maps, influence maps… Can be extended to 3D Or 2.5D – 2D grid with heights Disadvantages: May have many empty nodes, wasting memory & reducing cache efficiency Choice of partition size tricky – too small gives many empty nodes, too large and culling etc. is ineffective

Mapping a Grid to the World A grid is an integer indexed structure (e.g. an array) For a rectangle of world space Need to map between world-space coords & grid indexes (GridX,GridY)  (WorldX,WorldY) Conversions for X dimension are (Y dimension similar): GridX = (int)(GridWidth * (WorldX – MinX) / (MaxX – MinX)) WorldX = MinX + (float)GridX * (MaxX – MinX) / GridWidth Second formula will give bottom-left of grid square For centre of grid square add 0.5 to GridX

Quadtrees / Octrees Quadtrees / Octrees are hierarchical partition systems Use a tree structure to represent an area/volume of space Formed by recursive subdivision Use specific division scheme Unlike portals where division into partitions was arbitrary Quadtrees are in 2D, octrees in 3D Otherwise the same Some similarities with grid system

Creating a Quadtree Root node is entire space Usually square Divide into four equal quadrants These are the children nodes Repeat division with each quadrant Until some condition is met Maximum depth An empty node Only one entity contained Etc…application dependent

Location in a Quadtree Easy to find which node point is in: Start at root node Find the quadrant the point is in Just two comparisons (X and Y) Repeat process on this quadrant Can be optimised: Have world space as square Power of 2 in size (e.g. 2048) Centred on origin Can use bitwise integer math [See Rabin]

Quadtrees for Visibility Culling Use for frustum culling: Traverse quadtree from root Cull entire nodes outside frustum Along with all entities and all child nodes in them Reject many entities at once Nodes are AABB Viewing frustum is 6 planes To test if a node is visible: Six AABB <-> plane tests Saw this idea in initial lecture on partitions. Several approaches, see: www.lighthouse3d.com/opengl/viewfrustum/index.php

Quadtree Problem Problem: Worst case: entity overlaps origin Entities aren’t points May overlap a node boundary In this case the entity needs to be in a larger parent node Worst case: entity overlaps origin Doesn’t fit in any node except root Even a tiny entity Will never be culled Hot-spots like this al the way around the boundaries of larger nodes

Loose Quadtrees Solution: Loose Quadtrees Few changes to algorithms Have nodes overlap Entities will then fit in original node area Potentially with their bounding sphere overlapping adjacent nodes Few changes to algorithms Increase node size: When inserting entities When doing frustum culling Removes hot-spot problem At the expense of larger nodes at the same level

Quadtrees for Collision Detection We saw intersection of viewing frustum with quadtree Fairly easy to find intersection of other primitives Spheres, cuboids, rays, capsules Find the set of nodes intersected And hence the set of entities that are candidates for collision Basis for collision detection / ray casting / physics systems Can help if we add adjacency information to the tree

Binary Space Partitioning A Binary Space Partition (BSP) is also a hierarchical division of space Another tree structure This one represents all space Quadtrees only cover root node Partitions separated by: Lines in 2D Planes in 3D Recursively divide each partition into two smaller ones with an arbitrary line / plane Creates a binary tree

Creating a BSP Repeatedly divide space in two Stop when: Use best line/plane to balance tree Stop when: Maximum of X elements in each partition (X = 1 here) Partitions are small enough Tree reaches certain depth Choice depends on application

Locating a Point in a BSP Given a point, easy to find which partition it is in: Start at root of tree Find which side of the dividing line/plane the point is on Follow appropriate edge Repeat until find leaf partition Example here: Check P against X Not in A, follow other edge Check P against Y Not in B, follow other edge, etc.

Reminder: which Side of a Plane? A plane is defined by: A vertex on the plane P A vector / normal N at right angles to the plane To find which side of the plane a vertex A is on: d = N • PA = |N| |PA| cos α A will be on the same side pointed at by the vector N if: N • PA is a simple operation Don’t need to calculate α

BSP for Solid/Hollow Spaces Can use the polygons in the scene as the division planes Choose a polygon as a plane All other polygons placed on one or other side of plane Polygons crossing the planes are split BSP splits space into hollow / solid volumes All polygons / entities placed in hollow ones

BSP / Brush Modelling This “traditional” style of BSP used for FPS games First appeared in Doom (original version) Often used in conjunction with a PVS Can also be used to render partitions in a strict back to front order Lends itself to a unique form of 3D modelling called brush modelling Start with a entirely solid world Cut out primitives (boxes, cylinders etc.) Entities placed in hollowed out areas Like "digging out" the level

BSP Pros / Cons BSP trees are a well established technique Real-world apps tend to use refinements of the approach Used for rendering / collision / ray-tracing Can be generated automatically Fully classify space Easy to find which partition a point is in Need good algorithm to choose dividing planes Try to balance tree, examples were unbalanced Hollow/solid BSP generates extra polygons due to splitting