Rendering: Spatial Acceleration Structures Bernhard Kerbl Research Division of Computer Graphics Institute of Visual Computing & Human-Centered Technology TU Wien, Austria With slides based on material by Jaakko Lehtinen, used with permission
How to produce an image? A good image needs realistic intensity and visibility Intensity creates stimulus of optic nerve (black, white, color) Visibility makes sure that objects adhere to depth How would you process the scene on the right to make sure the rendered output image is correct? (Naïve) Ray-Casting Render Loop Shoot a ray through each pixel into the scene Source: Wojciech Mula , Wikipedia “Painter's algorithm” Iterate over all objects and test for intersection Record the closest intersection ( visibility ) Compute color and write to pixel ( intensity ) Rendering – Spatial Acceleration Structures 2
Render Loop void render(Camera cam) { for(Pixel& pix : pixels) { pix.Color = background; Intersection closest; closest.Distance = INFINITY; Ray ray = rayThroughPixel(cam, pix); for (Triangle& tri : triangles) { Intersection sect = findClosestIntersection(ray, tri); if(sect.Distance < closest.Distance) { closest = sect; } } if(closest.Distance != INFINITY) { pix.Color = computeColor(closest); } } } Rendering – Spatial Acceleration Structures 3
Spatial Aliasing void render(Camera cam) { for(Pixel& pix : pixels) { pix.Color = background; Intersection closest; closest.Distance = INFINITY; Ray ray = rayThroughPixel(cam, pix); for (Triangle& tri : triangles) { Intersection sect = findClosestIntersection(ray, tri); if(sect.Distance < closest.Distance) { closest = sect; } Source: renderstuff.com/ } if(closest.Distance != INFINITY) { pix.Color = computeColor(closest); } Those are your dad’s pixels! } } Rendering – Spatial Acceleration Structures 4
Supersampling Instead of a single ray through each pixel, use multiple „ samples “ Source: Parcly Taxel , Wikipedia “ Supersampling ” Rendering – Spatial Acceleration Structures 5
Supersampling void render(Camera cam) { for(Pixel& pix : pixels) { pix.Color = background; Intersection closest; closest.Distance = INFINITY; Ray ray = rayThroughPixel(cam, pix); for (Triangle& tri : triangles) { Intersection sect = findClosestIntersection(ray, tri); if(sect.Distance < closest.Distance) { closest = sect; } Source: renderstuff.com/ } if(closest.Distance != INFINITY) { pix.Color = computeColor(closest); } Antialiased } } Rendering – Spatial Acceleration Structures 6
Updated Render Loop pix.Color = background; Intersection closest; closest.Distance = INFINITY; for(int s = 0; s < NUM_SAMPLES; s++) { SampleInfo sInfo = drawSample(); Ray ray = rayThroughSample(cam, sInfo.Location); for (Triangle& tri : triangles) { Intersection sect = findClosestIntersection(ray, tri); if(sect.Distance < closest.Distance) { closest = sect; } } if(closest.Distance != INFINITY) { RGBColor sample = computeColor(closest); pix.Color += filter(sInfo.Filter, RGBWColor(sample, 1)); } } pix.Color /= pixColor.w; Rendering – Spatial Acceleration Structures 7
Updated Render Loop pix.Color = background; Intersection closest; closest.Distance = INFINITY; for(int s = 0; s < NUM_SAMPLES; s++) { SampleInfo sInfo = drawSample(); Ray ray = rayThroughSample(cam, sInfo.Location); Sampling for (Triangle& tri : triangles) { Intersection sect = findClosestIntersection(ray, tri); Color and Light if(sect.Distance < closest.Distance) { closest = sect; } } Rendering Equation if(closest.Distance != INFINITY) { Filtering RGBColor sample = computeColor(closest); pix.Color += filter(sInfo.Filter, RGBWColor(sample, 1)); Sample Integration } } pix.Color /= pixColor.w; Rendering – Spatial Acceleration Structures 8
Render Loop Run Time Let‘s look at the basic runtime (single sample per pixel) void render(Camera cam) { for(Pixel& pix : pixels) { … for (Triangle& tri : triangles) { … } … } } Rendering – Spatial Acceleration Structures 9
Render Loop Run Time Let‘s look at the basic runtime (single sample per pixel) void render(Camera cam) { for(Pixel& pix : pixels) 𝑂 { … for (Triangle& tri : triangles) 𝑁 { … } … } } This is 𝒫(𝑂 ⋅ 𝑁) , but even worse, it’s Ω 𝑂 ⋅ 𝑁 ! Rendering – Spatial Acceleration Structures 10
Is That Actually a Problem? Run time complexity quickly becomes a limiting factor High-quality scenes can have several million triangles per object Current screens and displays are moving towards 4k resolution Rendering – Spatial Acceleration Structures 11
Amazon Lumberyard “Bistro” 3,780,244 triangles 1200x675 pixels 3 trillion ray/triangle intersection tests? At 10M per second, one shot will take ~4 days. Good luck with your movie! Rendering – Spatial Acceleration Structures 12 Picture provide through Creative Commons CC-BY.4.0
What can we do about it? For rendering, we will want to learn to run before we can walk Find ways to speed up the basic loop for visibility resolution Enter “spatial acceleration structures” Essentially, pre-process the scene geometry into a structure that reduces expected traversal time to something more reasonable Rendering – Spatial Acceleration Structures 13
Spatial Acceleration Structures Structure Additional Memory Building Time Traversal Time none none none abysmal Rendering – Spatial Acceleration Structures 14
Speeding Up Intersection Tests Consider a group of triangles Which ones should we test? Rendering – Spatial Acceleration Structures 15
Regular Grids Overlay scene with regular grid Sort triangles into cells Traverse cells and test against their contents Rendering – Spatial Acceleration Structures 16
Regular Grids Overlay scene with regular grid Sort triangles into cells Traverse cells and test against their contents Rendering – Spatial Acceleration Structures 17
Regular Grids Overlay scene with regular grid Sort triangles into cells Traverse cells and test against their contents Rendering – Spatial Acceleration Structures 18
Regular Grids Geometry is usually not uniform Comes in clusters (buildings, characters, vegetation …) Rendering – Spatial Acceleration Structures 19
Regular Grids Geometry is usually not uniform Comes in clusters (buildings, characters, vegetation …) Almost all triangles in one cell! Hitting this cell will be costly! Rendering – Spatial Acceleration Structures 20
Regular Grids Geometry is usually not uniform Comes in clusters (buildings, characters, vegetation …) Almost all triangles in one cell! Hitting this cell will be costly! Using a finer grid works Rendering – Spatial Acceleration Structures 21
Regular Grids Geometry is usually not uniform Comes in clusters (buildings, characters, vegetation …) Almost all triangles in one cell! Hitting this cell will be costly! Using a finer grid works, but most of its cells are unused! Rendering – Spatial Acceleration Structures 22
Spatial Acceleration Structures Structure Memory Building Time (Expected) Consumption Traversal Time none none none abysmal low – high Regular Grid low uniform scene: ok (resolution) otherwise: bad Rendering – Spatial Acceleration Structures 23
Quadtrees and Octrees Start with scene bounds, do finer subdivisions only if needed Define parameters S 𝑛𝑏𝑦 , 𝑂 𝑚𝑓𝑏𝑔 Recursively split bounds into quadrants (2D) or octants (3D) Stop after S 𝑛𝑏𝑦 subdivisions or if no cell has > 𝑂 𝑚𝑓𝑏𝑔 triangles Rendering – Spatial Acceleration Structures 24
Quad and Octrees: 𝑂 𝑚𝑓𝑏𝑔 = 4 Start with scene bounds, do finer subdivisions only if needed Define parameters S 𝑛𝑏𝑦 , 𝑂 𝑚𝑓𝑏𝑔 Recursively split bounds into quadrants (2D) or octants (3D) Stop after S 𝑛𝑏𝑦 subdivisions or if no cell has > 𝑂 𝑚𝑓𝑏𝑔 triangles Rendering – Spatial Acceleration Structures 25
Quad and Octrees: 𝑂 𝑚𝑓𝑏𝑔 = 4 Start with scene bounds, do finer subdivisions only if needed Define parameters S 𝑛𝑏𝑦 , 𝑂 𝑚𝑓𝑏𝑔 1 2 4 3 Recursively split bounds into quadrants (2D) or octants (3D) Stop after S 𝑛𝑏𝑦 subdivisions or if no cell has > 𝑂 𝑚𝑓𝑏𝑔 triangles Rendering – Spatial Acceleration Structures 26
Quad and Octrees: 𝑂 𝑚𝑓𝑏𝑔 = 4 . 1 2 3 4 1 2 4 3 Rendering – Spatial Acceleration Structures 27
Quad and Octrees: 𝑂 𝑚𝑓𝑏𝑔 = 4 . 1 2 1 2 3 4 4 3 1 2 3 4 Rendering – Spatial Acceleration Structures 28
Quad and Octrees: 𝑂 𝑚𝑓𝑏𝑔 = 4 . 1 2 1 2 3 4 4 3 1 2 3 4 Rendering – Spatial Acceleration Structures 29
Quad and Octrees: 𝑂 𝑚𝑓𝑏𝑔 = 4 1 2 . 4 3 1 2 3 4 1 2 3 4 1 2 3 4 Rendering – Spatial Acceleration Structures 30
Quad and Octrees: 𝑂 𝑚𝑓𝑏𝑔 = 4 1 2 . 4 3 1 2 3 4 1 2 3 4 1 2 3 4 Rendering – Spatial Acceleration Structures 31
Quad and Octrees Triangles may not be contained within a quadrant or octant Triangles must be referenced in all overlapping cells or split at the border into smaller ones Rendering – Spatial Acceleration Structures 32
Recommend
More recommend