COMP 175: Computer Graphics April 8, 2019

Slides:



Advertisements
Similar presentations
Christian Lauterbach COMP 770, 2/16/2009. Overview  Acceleration structures  Spatial hierarchies  Object hierarchies  Interactive Ray Tracing techniques.
Advertisements

CS 352: Computer Graphics Chapter 7: The Rendering Pipeline.
Efficient access to TIN Regular square grid TIN Efficient access to TIN Let q := (x, y) be a point. We want to estimate an elevation at a point q: 1. should.
Exploration of bump, parallax, relief and displacement mapping
Week 10 - Monday.  What did we talk about last time?  Global illumination  Shadows  Projection shadows  Soft shadows.
CS447/ Realistic Rendering -- Solids Modeling -- Introduction to 2D and 3D Computer Graphics.
Chapter 6: Vertices to Fragments Part 2 E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley Mohan Sridharan Based on Slides.
Tomas Mőller © 2000 Speeding up your game The scene graph Culling techniques Level-of-detail rendering (LODs) Collision detection Resources and pointers.
(conventional Cartesian reference system)
Hidden Surface Elimination Wen-Chieh (Steve) Lin Institute of Multimedia Engineering I-Chen Lin’ CG Slides, Rich Riesenfeld’s CG Slides, Shirley, Fundamentals.
10/11/2001CS 638, Fall 2001 Today Kd-trees BSP Trees.
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.
University of Texas at Austin CS 378 – Game Technology Don Fussell CS 378: Computer Game Technology Beyond Meshes Spring 2012.
Computer Graphics Inf4/MSc Computer Graphics Lecture 11 Texture Mapping.
Computer Graphics 2 Lecture x: Acceleration Techniques for Ray-Tracing Benjamin Mora 1 University of Wales Swansea Dr. Benjamin Mora.
1 Perception, Illusion and VR HNRS 299, Spring 2008 Lecture 19 Other Graphics Considerations Review.
1 Computer Graphics Week13 –Shading Models. Shading Models Flat Shading Model: In this technique, each surface is assumed to have one normal vector (usually.
10/29/02 (c) 2002 University of Wisconsin, CS559 Today Hidden Surface Removal Exact Visibility.
Spatial Data Structures Jason Goffeney, 4/26/2006 from Real Time Rendering.
University of Illinois at Chicago Electronic Visualization Laboratory (EVL) CS 426 Intro to 3D Computer Graphics © 2003, 2004, 2005 Jason Leigh Electronic.
Modelling and Simulation Types of Texture Mapping.
COMP 175: Computer Graphics March 24, 2015
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.
09/09/03CS679 - Fall Copyright Univ. of Wisconsin Last Time Event management Lag Group assignment has happened, like it or not.
09/11/03CS679 - Fall Copyright Univ. of Wisconsin Last Time Graphics Pipeline Texturing Overview Cubic Environment Mapping.
CS 638, Fall 2001 Today Project Stage 0.5 Environment mapping Light Mapping.
I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S Andries van Dam October 30, 2003 Shading 1/35 CIS 736 Computer Graphics Lecture 17 of 42 Illumination.
CS-378: Game Technology Lecture #4: Texture and Other Maps Prof. Okan Arikan University of Texas, Austin V Lecture #4: Texture and Other Maps.
Advanced Computer Graphics Advanced Shaders CO2409 Computer Graphics Week 16.
Real-time Graphics for VR Chapter 23. What is it about? In this part of the course we will look at how to render images given the constrains of VR: –we.
1Computer Graphics Implementation II Lecture 16 John Shearer Culture Lab – space 2
Implementation II Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico.
Binary Space Partitioning Trees Ray Casting Depth Buffering
Implementation II.
Review on Graphics Basics. Outline Polygon rendering pipeline Affine transformations Projective transformations Lighting and shading From vertices to.
Ray Tracing Fall, Introduction Simple idea  Forward Mapping  Natural phenomenon infinite number of rays from light source to object to viewer.
Computer Graphics I, Fall 2010 Implementation II.
Real-Time Dynamic Shadow Algorithms Evan Closson CSE 528.
1 CSCE 441: Computer Graphics Hidden Surface Removal Jinxiang Chai.
Ray Tracing Optimizations
David Luebke 3/5/2016 Advanced Computer Graphics Lecture 4: Faster Ray Tracing David Luebke
David Luebke3/12/2016 Advanced Computer Graphics Lecture 3: More Ray Tracing David Luebke
School of Computing Clemson University Fall, 2012
CSE 554 Lecture 5: Contouring (faster)
- Introduction - Graphics Pipeline
Scene Manager Creates and places movable objects like lights and cameras so as to access them efficiently, e.g. for rendering. Loads and assembles world.
Computer Graphics Implementation II
Bounding Volume Hierarchies and Spatial Partitioning
Bounding Volume Hierarchies and Spatial Partitioning
Modeliranje kompleksnih modelov
Real-Time Ray Tracing Stefan Popov.
3D Graphics Rendering PPT By Ricardo Veguilla.
3D Object Representations
The Graphics Rendering Pipeline
CS451Real-time Rendering Pipeline
Jim X. Chen George Mason University
© University of Wisconsin, CS559 Fall 2004
CSCE 441: Computer Graphics Hidden Surface Removal
COMP 175: Computer Graphics April 11, 2018
Implementation II Ed Angel Professor Emeritus of Computer Science
Chapter IX Bump Mapping
Lecture 13 Clipping & Scan Conversion
CS-378: Game Technology Lecture #4: Texture and Other Maps
CS679 - Fall Copyright Univ. of Wisconsin
Introduction to Computer Graphics with WebGL
GR2 Advanced Computer Graphics AGR
Anti-aliased and accelerated ray tracing
Modeliranje kompleksnih modelov
Implementation II Ed Angel Professor Emeritus of Computer Science
Presentation transcript:

COMP 175: Computer Graphics April 8, 2019 Lecture 12: Recursive Ray Tracer2: Advanced Techniques and Data Structures COMP 175: Computer Graphics April 8, 2019

Admin Assignment 5 out today Assignment 4 Grading Sign Up Handout will be posted after class As usual, algorithm due on Friday at noon Code due the following Sunday by midnight Assignment 4 Grading Sign Up Friday afternoon this week. Email me if you cannot attend No grading during lab this week (because we won’t have a lab) Compile your code with optimization In Mac, add a –O2 (that’s big o, not zero) or –O3 In Windows, use release mode

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…

Questions?

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=PCE0k6PcDcw Short answer: fake it with texture maps

Advanced Techniques (Shadows 1/3) Total hack: Project object on ground plane and render it as black polygon. Eyes are less sensitive to exact geometry than to contrast of shadow Projective shadows 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

Advanced Techniques (Shadows 2/3) 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

Advanced Techniques (Shadows 3/3) 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 By keeping the same far clipping plane, relative distances in Z are preserved Shadow Map

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 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. Shiny metal effect using environment map.

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 Perturb geometric normals with bump map Desired Geometry Approximate geometry at render time with displacement map Replace normals of simpler geometry with normal map

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

Bump Mapping Example The tin foil on this Hershey’s Kiss looks too smooth

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

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

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

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

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 Final render with normal map applied to low-res mesh (and lighting and texture maps). This is only 5,000 triangles! High-resolution model (~2 million polygons)

Normal Mapping Creation (3/3) How it works: Artist creates a high resolution model with complex geometry High resolution model simplified using mesh decimation to a model with much fewer triangles Normal map generation: Let 𝑀 be the complex original mesh and 𝑆 the simplified mesh To generate the normal to map to a point 𝑃 𝑆 on 𝑆, find the point 𝑃 𝑀 on 𝑀 such that the Euclidean distance between 𝑃 𝑆 and 𝑃 𝑀 is minimal. 𝑃 𝑀 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 𝑃 𝑆 to each of 𝑀’s nearby facets Compute the normal at 𝑃 𝑀 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) 𝑆 𝑃 𝑆 𝑃 𝑀 𝑀 See SIGGRAPH paper: “A general method for preserving attribute values on simplified meshes” by Cignoni, Montani, Rocchini, Scopigno

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

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 Texture Mapped Texture and Parallax Mapped

Parallax Mapping Video on Wiki: https://en.wikipedia.org/wiki/Parallax_mapping Start with a displacement map (red line below) Compute texture (and normal) based on the displacement Assume that a view vector looking at point A (yellow line) Normally one would render point A’s texture and normal The trick to Parallax mapping is to make sure that B is drawn

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, unsettling to the eye when moving Steep Parallax Mapped: Very realistic depth in whole picture. Lion head, columns cast self shadows http://graphics.cs.brown.edu/games/SteepParallax/index.html

High-level Takeaway Computing using real geometry can be very slow (e.g. Ray tracing). As a tradeoff, it produces gorgeous results and can simulate lots of different effects Also, it is accurate and representative of the actual scene and geometry In cases where speed is more important than accuracy (e.g. games), 2D maps are used Starts with low number of polygons Height map / displacement map Normal map Shadow map Texture map, etc

Questions?

How to Speed Up My Ray Tracer?!

Is there a way to speed this up? 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

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!

Is there a way to speed this up? 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

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

Creating a Bounding Volume Hierarchy (BVH) Using a bottom-up approach

Bounding Volume Hierarchy (BVH) Example

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

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 1 2 3 4 5 6 0 1 2 3 4 5 6 7 8

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 𝑂( log 𝑛 ) 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)

Basically this is an adaptive grids approach 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)

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

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

Octree For each ray, the expected runtime is 𝑂( log 𝑛 ) 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

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) 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 Octree kd-Tree

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

kd-Tree: Choosing a Split Plane x=1 y=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)

kd-Tree: Choosing a Split Plane x=1 y=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

kd-Tree: Choosing a Split Plane x=1 y=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)

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.

BVH Cells Octree kd-Tree

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

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

BSP Trees BSP-2: Process front sub-tree recursively

BSP Trees BSP-3: Process back sub-tree recursively

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

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)

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 // ignore next line if back-face // culling desired

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…