COMP 175: Computer Graphics April 11, 2018

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

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

Spatial Data Structures

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

Spatial Data Structures

Texture. Texture Mapping. Texture Mapping. CS 475 / CS 675 Computer Graphics. Lecture 11 : Texture

CS 475 / CS 675 Computer Graphics. Lecture 11 : Texture

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

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

Spatial Data Structures

Speeding up your game

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

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

Computer Graphics. Bing-Yu Chen National Taiwan University

Spatial Data Structures

improving raytracing speed

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

CSE528 Computer Graphics: Theory, Algorithms, and Applications

Acceleration Data Structures for Ray Tracing

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

Ray Tracing Acceleration Data Structures

Spatial Data Structures

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

Lighting. To do. Course Outline. This Lecture. Continue to work on ray programming assignment Start thinking about final project

CS535 Fall Department of Computer Science Purdue University

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

Hidden Surface Elimination: BSP trees

Topics and things to know about them:

CS580: Ray Tracing. Sung-Eui Yoon ( 윤성의 ) Course URL:

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

Culling. Computer Graphics CSE 167 Lecture 12

Global Rendering. Ingela Nyström 1. Effects needed for realism. The Rendering Equation. Local vs global rendering. Light-material interaction

The Traditional Graphics Pipeline

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

CPSC GLOBAL ILLUMINATION

Real-Time Shadows. Last Time? Textures can Alias. Schedule. Questions? Quiz 1: Tuesday October 26 th, in class (1 week from today!

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

Texture Mapping II. Light maps Environment Maps Projective Textures Bump Maps Displacement Maps Solid Textures Mipmaps Shadows 1. 7.

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

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

Shadows in the graphics pipeline

lecture 18 - ray tracing - environment mapping - refraction

Graphics and Interaction Rendering pipeline & object modelling

Real-Time Shadows. Last Time? Today. Why are Shadows Important? Shadows as a Depth Cue. For Intuition about Scene Lighting

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

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

Rendering Grass Terrains in Real-Time with Dynamic Lighting. Kévin Boulanger, Sumanta Pattanaik, Kadi Bouatouch August 1st 2006

Computer Graphics I Lecture 11

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

The Traditional Graphics Pipeline

For Intuition about Scene Lighting. Today. Limitations of Planar Shadows. Cast Shadows on Planar Surfaces. Shadow/View Duality.

The Traditional Graphics Pipeline

Last Time. Why are Shadows Important? Today. Graphics Pipeline. Clipping. Rasterization. Why are Shadows Important?

CHAPTER 1 Graphics Systems and Models 3

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 Methods. Chapter? Intro. to Computer Graphics Spring 2008, Y. G. Shin

Intersection Acceleration

Homework #2. Shading, Ray Tracing, and Texture Mapping

Visibility and Occlusion Culling

Subdivision Of Triangular Terrain Mesh Breckon, Chenney, Hobbs, Hoppe, Watts

Effects needed for Realism. Computer Graphics (Fall 2008) Ray Tracing. Ray Tracing: History. Outline

Sung-Eui Yoon ( 윤성의 )

Topics. Ray Tracing II. Intersecting transformed objects. Transforming objects

Advanced 3D-Data Structures

Anti-aliased and accelerated ray tracing. University of Texas at Austin CS384G - Computer Graphics Fall 2010 Don Fussell

Computer Graphics Ray Casting. Matthias Teschner

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

CS451Real-time Rendering Pipeline

Last Time. Reading for Today: Graphics Pipeline. Clipping. Rasterization

Anti-aliased and accelerated ray tracing. University of Texas at Austin CS384G - Computer Graphics

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

Acceleration Data Structures

Universiteit Leiden Computer Science

Pipeline Operations. CS 4620 Lecture 10

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

Accelerated Raytracing

Ray Casting. Outline in Code. Outline. Finding Ray Direction. Heckbert s Business Card Ray Tracer. Foundations of Computer Graphics (Fall 2012)

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

CSE 167: Introduction to Computer Graphics Lecture #18: More Effects. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2016

Rendering. Converting a 3D scene to a 2D image. Camera. Light. Rendering. View Plane

Speeding Up Ray Tracing. Optimisations. Ray Tracing Acceleration

Pipeline Operations. CS 4620 Lecture Steve Marschner. Cornell CS4620 Spring 2018 Lecture 11

CS 465 Program 5: Ray II

Computer Graphics. Lecture 14 Bump-mapping, Global Illumination (1)

Computer Science 426 Midterm 3/11/04, 1:30PM-2:50PM

CS 354R: Computer Game Technology

Physically-Based Laser Simulation

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

More Hidden Surface Removal

Specialized Acceleration Structures for Ray-Tracing. Warren Hunt

Orthogonal Projection Matrices. Angel and Shreiner: Interactive Computer Graphics 7E Addison-Wesley 2015

CMSC427 Advanced shading getting global illumination by local methods. Credit: slides Prof. Zwicker

Pipeline Operations. CS 4620 Lecture 14

Surface Rendering. Surface Rendering

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

Assignment 6: Ray Tracing

Computer Graphics Shadow Algorithms

Point based Rendering

Lecture 13: Reyes Architecture and Implementation. Kayvon Fatahalian CMU : Graphics and Imaging Architectures (Fall 2011)

Topics. Ray Tracing II. Transforming objects. Intersecting transformed objects

Transcription:

Lecture n+1: Recursive Ray Tracer2: Advanced Techniques and Data Structures COMP 175: Computer Graphics April 11, 2018 1/49

Review } Ray Intersect (Assignment 4): questions / comments? } Review of Recursive Ray Tracer: } Two (or three) types of secondary rays } Lighting equation } Blending and texture mapping } The value of Epsilon 2/49

Questions? 3/49

Glowing Ball } Now that you see how complicated (and slow) real rendering is, how do you do some common techniques that appear cool but run in real time? } For example, a glowing floating ball? } https://www.youtube.com/watch?v=kag1mbdedps } Short answer: fake it with texture maps 4/49

Advanced Techniques (Shadows 1/2) } Total hack: Project object on ground plane and render it as black polygon. Eye less sensitive to exact geometry than to contrast of shadow } Projective shadows (shadow mapping) } Use orthographic or perspective matrix as CTM to project object (shadow caster) against another object; render the shadow object as another primitive } Good for single light scenes with shadows cast on planes } Shadow volumes } Extrude silhouette volume from object (shadow caster) to infinity in the direction opposite the light source } Silhouette edge is made up of adjacent polygons, any point within the volume is in shadow Implemented by former cs123 ta Kevin Egan and former PhD student and book co-auther Prof. Morgan McGuire, on nvidiachip 5/49

Advanced Techniques (Shadows 2/2) } Shadow Maps } Transform camera to each directional light source } Render the scene from the light source POV, keeping the same far clipping plane, update z-buffer only } Read the z-buffer back and apply as a texture (shadow map) to the scene projected from the light s POV } Render the scene from the eye point. At each pixel, if distance from light is greater than in the shadow map, the object is in shadow. } Major aliasing problem, but implemented in hardware Light Shadow Map By keeping the same far clipping plane, relative distances in Z are preserved Erik Anderson April 12 12, Recursive 2018 Ray Tracer 2 6 6/49

Advanced Techniques (Environment Mapping) } A way to render reflections (also called reflection mapping) } Simulates reflections with a texture map applied to the enclosing sphere or cube of an object } Texture map can either be an existing image or a rendering of the scene from the object s perspective Shiny metal effect using environment map. } Cube environment map is created by stitching together 6 textures, each generated by rendering the scene from the object s POV } Ray from eye is reflected over surface normal and intersected with the environment map to get texture coordinates. 7/49

Advanced Techniques (Surface Detail) } Overview: There are several hacks to approximate the lighting and shading of complex geometry without actually describing the geometry only used for fine detail Desired Geometry Perturb geometric normals with bump map Approximate geometry at render time with displacement map Replace normals of simpler geometry with normal map 8/49

Surface Detail (Bump Mapping) } Texture mapping a rough surface onto an object doesn t achieve desired effect. Illumination is too uniform } Blinn s technique: Use an array of values (stored in a texture called the bump map ) to perturb the surface normals by calculating gradient of bump map and adding it to the surface normal } Evaluate lighting model with perturbed normals } Effect is convincing, but objects still look smooth at silhouette edges Spherical Surface nvidia 9/49

Bump Mapping Example } The tin foil on this Hershey s Kiss looks too smooth 10/49

Bump Mapping Example } Bump Mapped: Tin foil look with no increase in model complexity. } Edges still don t look quite right 11/49

Normal Mapping } Similar to bump mapping, but better for highly detailed surfaces with drastically varying normals } Bump mapping uses a single channel height field to perturb normals, while normal mapping uses a three channel map to actually replace existing surface normal } x, y, and z components of the desired normal, stored in the r, g, and b channels of an image } Level of detail is now limited by normal map resolution, not number of triangles } Runtime surface normal determination is as easy as a texture lookup } Limitations: } Same as bump map, silhouette edges lack the added detail } Though easy to use at runtime, normal maps are difficult to generate 12/49

Normal Mapping Examples Render showing actual, simple underlying geometry When a normal map is applied, there appears to be much more detail in the model than actually is } Normal mapping can completely alter the perceived geometry of a model Image courtesy of www.anticz.com 13/49

Normal Map Creation (1/3) } While bump maps can be simply drawn, normal maps hold meaningful data in three overlapping channels Normal map for a face. Red, green, and blue channels correspond to x, y, and z normal components www.bitmanagement.com Normal map for brick street www3.telus.net } Normal maps are not visually intuitive like height maps. How are they created? 14/49

Normal Map Creation (2/3) } Normal maps must be generated by specialized software, such as Pixologic s Zbrush (www.pixologic.com) } A high resolution model is created by an artist and its normals are used to generate a normal map for a low resolution model. 3D geometry Low-res mesh (~5,000 polygons) Normal Map High-resolution model (~2 million polygons) Final render with normal map applied to low-res mesh (and lighting and texture maps). This is only 5,000 triangles! 15/49

Normal Mapping Creation (3/3) } How it works: } Artist creates a high resolution model with complex geometry (video) } High resolution model simplified using mesh decimation to a model with much fewer triangles } Normal map generation: } Let M be the complex original mesh and S the simplified mesh } To generate the normal to map to a point P $ on S, find the point P % on M such that the Euclidean distance between P $ and P % is minimal. } P % can be found by having each face of M stored in a grid and indexing into this grid with coordinates collected during mesh simplification. We find the minimum perpendicular distance from P $ to each of M s nearby facets } Compute the normal at P % by averaging normals at surrounding vertices. Place this value in triangular normal map for the single face. } Finally, stitch these triangular normal maps together to create a normal map for the entire simple surface. } Note: The resolution at which normals are sampled is user defined (again, time vs quality tradeoff) 16/49 P $ P % See SIGGRAPH paper: A general method for preserving attribute values on simplified meshes by Cignoni, Montani, Rocchini, Scopigno M S

Other Surface Detail Techniques (1/3) } Displacement Map: } The actual geometric position of points over the surface are displaced along the surface normal according to the values in a texture The displacement map used to render the scene. The intensity value indicates the height at a given point. http://www.creativemac.com/2004/02_feb/tutorials/koc4ddisplace040224.htm 17/49

Other Surface Detail Techniques (2/3) } Parallax Mapping: } Displaces texture coordinates of a surface point by a function of the view angle relative to the surface normal and the value on the height map at that point } Steep Parallax Mapping: } Similar scheme to produce self-occlusion self-shadows of parallax mapped surface; More efficient and reduces swim effect for high frequency maps (Morgan McGuire Ph.D. 06 and Max McGuire) Texture Mapped Texture and Parallax Mapped 18/49

Other Surface Detail Techniques (3/3) Texture Mapped Normal Mapped: Increased depth in rock wall Parallax Mapped: Increased depth of whole texture but unwanted swim effect. Textures look like they should be 3D but they stay embedded in surface, Steep Parallax Mapped: Very realistic depth in whole picture. Lion head, columns cast self shadows unsettling to the eye when moving http://graphics.cs.brown.edu/games/steepparallax/index.h tml 19/49

Questions? 20/49

How to Speed Up My Ray Tracer?! 21/49

What Would You Do? } In the example below, we have to compute 8 intersection tests to find that we intersected with nothing } Is there a way to speed this up? Ray 22/49

Screen-Based Approach } We can project the objects onto the screen, and compute the bounding boxes in 2D. } No need to cast rays where the screen is empty } If we use opengl to render the scene once, we can (roughly) determine what object(s) we need to intersect with! 23/49

What Would You Do? } In the example below, we have to compute 8 intersection tests to find the nearest object } Is there a way to speed this up? Ray 24/49

Bounding Volumes } Use bounding volumes (that are easier/ cheaper to compute intersection tests for) } Spheres and boxes are most common } It s typical to use axis-aligned bounding boxes (makes math easier no coordinate transform) } Works very well for tight bounding boxes } Do this recursively to get a set of hierarchical bounding boxes (bottom-up or top-down) } Can be applied to the scene graph if the objects in the scene are organized spatially 25/49

Creating a Bounding Volume Hierarchy (BVH) } Using a bottom-up approach 26/49

Bounding Volume Hierarchy (BVH) Example 27/49

Different Ways To Partition a Space } Bounding volume hierarchy } Grid } Octree } kd-tree (k-dimensional tree) } BSP-Tree (binary space partitioning trees) 28/49

Grids } Divide the world into uniform cells } Each cell stores the objects contained within it } Use line-scanning algorithm to traverse } Intersect with each cell along the way 0 1 2 3 4 5 6 0 1 2 3 4 5 6 7 8 29/49

Grids } Problems: } Choosing the right number of cells isn t the most obvious } Too many cells -> need to check a lot of each ray } Too few cells -> speed up can be reduced (too many objects in each one) } Some cells could be empty, while others have tons of objects within it } Note that this approach is not hierarchical, which means that we don t get the nice O(log n) benefit } Need to be careful in deciding what objects belong to a cell (vertex, edge, face) } But very useful for many reasons: } Easy to implement in hardware } Good for an animated scene (an object moving to a different cell doesn t affect the other objects or other cells) 30/49

Octree } Basically this is an adaptive grids approach } Generate more cells when needed, but leave the white spaces alone } Cells are still axis-aligned } Cells will no longer have the same size 2-D example (called a quadtree) 31/49

Octree } Constructed using a top-down approach } Recursively split the world into 8 cells } Terminates when the depth is too high, or } Terminates when the number of objects per cell falls below a threshold } Similar problem as grids, need to be careful in determining which objects belong to which cells 32/49

Octree } Start at the root node (cell), if it intersects, recursively check all 8 children (or 4 for quadtrees) } If a leaf node (cell) is empty, terminate. Otherwise, check all objects within the cell 33/49

Octree } For each ray, the expected runtime is O(log n) } Problems: } Updating an octree could be tricky (for an animated scene) } Finding neighbors of a cell isn t trivial } For scenes that have objects distributed non-uniformly, the depth could become very high 34/49

Kd-Tree } Improves upon octrees in that it is a little more intelligent in finding the split points } Skips large swaths of empty spaces early } Zeros in on areas with high complexity (lots of objects) } In the worst case, a kd-tree will be exactly like a quadtree (for k=2), or an octree (for k=3) Octree } Like grids and octrees, kd-trees also use axis-aligned bounding boxes (for checking intersection is fast) } Unlike octrees, kd-trees split in one dimension at a time kd-tree 35/49

kd-tree: Choosing a Split Plane y=1 0 x=1 } (Recursively) splitting a middle results in a quadtree } During traversal, cost of entering the right side is much higher 36/49

kd-tree: Choosing a Split Plane y=1 0 x=1 } Splitting at the medium balances out the cost, but } During traversal, the chance of entering the left hand side is much higher (the area is larger) 37/49

kd-tree: Choosing a Split Plane y=1 0 x=1 } Cost-optimized split: attempts to balance the cost of entering and the probability of entering the two sides } Isolates the complex geometry quickly, creating large, (mostly) empty spaces that can be efficiently computed and discarded 38/49

kd-tree: Choosing a Split Plane y=1 0 x=1 } Further subdivision does not result in big gains (compared to octrees) } But the point is that we isolated the complex geometry in one split (which would have taken octree much longer to find) 39/49

kd-tree: Caution with Edge Cases } Notice the ray from left to right } When it enters F, it will do an intersection test with the green rectangle } You will be tempted to say that you re done and return the green rectangle as the nearest object (because F is in front of G) } However, one can see that the clear nearest object is the yellow rectangle } Solution, check the t-value against the bounding box t-value } Which will show that the t-value for the green rectangle is behind F. 40/49

BVH Cells Octree kd-tree 41/49

Binary Space Partition (BSP) Tree } Not really used for ray tracer, but for visible surface determination } This algorithm replaces the use of z-buffers } Fast to construct. Used in video games (like Quake 3) } Similar to kd-tree, but NOT axis-aligned BSP-0: Initial Scene 42/49

BSP Trees BSP-1: Choose any polygon (e.g., polygon 3) and subdivide others by its plane, splitting polygons when necessary 43/49 43

BSP Trees BSP-2: Process front sub-tree recursively 44/49 44

BSP Trees BSP-3: Process back sub-tree recursively 45/49 45

BSP Trees BSP-4: An alternative BSP tree with polygon 5 at the root 46/49 46

BSP-Trees } Remember that this is used for determining the order in which objects need to be drawn on screen } So the order in which the objects are drawn will be from back to front, but takes into account of the direction of the face and where the eye is (recursively) 47/49

BSP-Trees void BSP_displayTree(BSP_tree* tree) { location = tree->find_location(eye); if ( location > 0 ) //eye in front of object if ( viewer is in front of root ) { BSP_displayTree(tree->backChild); displaypolygon(tree->root); BSP_displayTree(tree->frontChild); } else { //eye behind the object BSP_displayTree(tree->frontChild); // ignore next line if back-face // culling desired displaypolygon(tree->root); BSP_displayTree(tree->backChild); } } } 48/49

Summary } Which data structure would be best to use in the following situations? } An animation where only the camera moves? } kd-tree } A fast-paced video game with lots of interactive, moving objects? } regular grid or BSP-Tree } A very balanced and even scene with objects uniformly distributed throughout the whole scene? } octree } Rendering scenes in a Pixar-like movie? } depends on the shot; most likely a combination of techniques are used } Your ray-tracing assignment if you are really fed up with your rendering speed? } kd-tree is best, but balance your decision with difficulty in implementing the solution 49/49