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

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

Rasterization, Depth Sorting and Culling

Pipeline implementation II

Implementation III. Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico

Topics. From vertices to fragments

FROM VERTICES TO FRAGMENTS. Lecture 5 Comp3080 Computer Graphics HKBU

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

Incremental Form. Idea. More efficient if we look at d k, the value of the decision variable at x = k

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

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

CS451Real-time Rendering Pipeline

Ulf Assarsson Department of Computer Engineering Chalmers University of Technology

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

The Traditional Graphics Pipeline

CS452/552; EE465/505. Clipping & Scan Conversion

The Traditional Graphics Pipeline

The Traditional Graphics Pipeline

TDA361/DIT220 Computer Graphics, January 15 th 2016

Fondamenti di Grafica 3D The Rasterization Pipeline.

From Vertices To Fragments-1

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

CS 112 The Rendering Pipeline. Slide 1

Spatial Data Structures

Rectangular Coordinates in Space

6.837 Introduction to Computer Graphics Final Exam Tuesday, December 20, :05-12pm Two hand-written sheet of notes (4 pages) allowed 1 SSD [ /17]

Speeding up your game

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

Computer Graphics (CS 543) Lecture 10: Rasterization and Antialiasing

Lesson 05. Mid Phase. Collision Detection

Spatial Data Structures

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

Intersection Acceleration

Bounding Volume Hierarchies

Renderer Implementation: Basics and Clipping. Overview. Preliminaries. David Carr Virtual Environments, Fundamentals Spring 2005

9. Visible-Surface Detection Methods

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

Clipping and Scan Conversion

graphics pipeline computer graphics graphics pipeline 2009 fabio pellacini 1

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

The University of Calgary

graphics pipeline computer graphics graphics pipeline 2009 fabio pellacini 1

Lesson 2: Basic Concepts of Geometry

Collision Detection with Bounding Volume Hierarchies

Ulf Assarsson Department of Computer Engineering Chalmers University of Technology

Computer Graphics Ray Casting. Matthias Teschner

2D rendering takes a photo of the 2D scene with a virtual camera that selects an axis aligned rectangle from the scene. The photograph is placed into

Clipping. Angel and Shreiner: Interactive Computer Graphics 7E Addison-Wesley 2015

Intersecting Simple Surfaces. Dr. Scott Schaefer

Introduction to Visualization and Computer Graphics

Lecture 11: Ray tracing (cont.)

Spring 2009 Prof. Hyesoon Kim

Ray casting. Ray casting/ray tracing

Ray Tracer I: Ray Casting Due date: 12:00pm December 3, 2001

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

CS 465 Program 5: Ray II

Rendering If we have a precise computer representation of the 3D world, how realistic are the 2D images we can generate? What are the best way to mode

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

Triangle Rasterization

Ray tracing. Computer Graphics COMP 770 (236) Spring Instructor: Brandon Lloyd 3/19/07 1

Sung-Eui Yoon ( 윤성의 )

Computer Graphics 10 - Shadows

Elements of 2d Computational Geometry. AI for Gaming Santa Clara, 2016

Computer Graphics 7 - Rasterisation

Spring 2012 Final. CS184 - Foundations of Computer Graphics. University of California at Berkeley

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

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

CS770/870 Spring 2017 Ray Tracing Implementation

Shadow Rendering EDA101 Advanced Shading and Rendering

Topics and things to know about them:

CS 4620 Midterm, March 21, 2017

Spring 2011 Prof. Hyesoon Kim

Two basic types: image-precision and object-precision. Image-precision For each pixel, determine which object is visable Requires np operations

SUMMARY. CS380: Introduction to Computer Graphics Ray tracing Chapter 20. Min H. Kim KAIST School of Computing 18/05/29. Modeling

Ray Tracing I. History

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

Rasterization. MIT EECS Frédo Durand and Barb Cutler. MIT EECS 6.837, Cutler and Durand 1

CHAPTER 1 Graphics Systems and Models 3

Computer Graphics. - Rasterization - Philipp Slusallek

- Rasterization. Geometry. Scan Conversion. Rasterization

Realtime 3D Computer Graphics Virtual Reality

Collision and Proximity Queries

Geometric Queries for Ray Tracing

Multi-level Partition of Unity Implicits

Three-Dimensional Coordinate Systems

improving raytracing speed

1999, Denis Zorin. Ray tracing

Ray Tracing. CPSC 453 Fall 2018 Sonny Chan

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

Collision Detection based on Spatial Partitioning

RASTERIZING POLYGONS IN IMAGE SPACE

Barycentric Coordinates and Parameterization

Computer Graphics. Lecture 9 Environment mapping, Mirroring

Real-Time Rendering. Tomas Möller Eric Haines. A K Peters Natick, Massachusetts

COMP3421. Vector geometry, Clipping

Werner Purgathofer

Ray Tracer Due date: April 27, 2011

Computer Graphics Prof. Sukhendu Das Dept. of Computer Science and Engineering Indian Institute of Technology, Madras Lecture - 24 Solid Modelling

? Which intermediate. Recall: Line drawing algorithm. Programmer specifies (x,y) of end pixels Need algorithm to determine pixels on line path

Pipeline Operations. CS 4620 Lecture 10

Transcription:

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

A tool needed for the graphics people all the time Very important components: Need to make them fast! Finding if (and where) a ray hits an object Picking Ray tracing and global illumination For speed-up techniques Collision detection (treated in a later lecture)

Midtown Madness 3, DICE

Ray: Sphere: Box Axis-aligned (AABB) Oriented (OBB) k-dop

Analytical Geometrical Separating axis theorem (SAT) Dynamic tests Given these, one can derive many tests quite easily However, often tricks are needed to make them fast

d Sphere center: c, and radius r Ray: r(t)=o+td Sphere formula: p-c =r Replace p by r(t), and square it: o r c (td + (o c)) (td + (o c)) r 2 = 0

Be a little smart o d Such tests are called rejection tests Other shapes: c Modified by Ulf Assarsson 2004

Boxes and spheres often used as bounding volumes A slab is the volume between two parallell planes: A box is the logical intersection of three slabs (2 in 2D): BOX

Intersect the 2 planes of each slab with the ray Keep max of t min and min of t max If t min < t max then we got an intersection Special case when ray parallell to slab

Two convex polyhedrons, A and B, are disjoint if any of the following axes separate the objects: An axis orthogonal to a face of A An axis orthogonal to a face of B An axis formed from the cross product of one edge from each of A and B axis A and B overlaps on this axis

E.g an axis-aligned box and a triangle 1) test the axes that are orthogonal to the faces of the box That is, x,y, and z

Assume that they overlapped on x,y,z Must continue testing 2) Axis orthogonal to face of triangle axis Triangle seen from side

If still no separating axis has been found 3) Test axis: t=e box x e triangle Example: x-axis from box: e box =(1,0,0) e triangle =v 1 -v 0 Test all such combinations If there is at least one separating axis, then the objects do not collide Else they do overlap

Acceptance and rejection test Try them early on to make a fast exit Postpone expensive calculations if possible Use dimension reduction E.g. 3 one-dimensional tests instead of one complex 3D test, or 2D instead of 3D Share computations between objects if possible Timing!!!

Ray: r(t)=o+td Triangle vertices: v 0, v 1, v 2 A point in the triangle: t(u,v)=v 0 +u(v 1 - v 0 ) +v(v 2 - v 0 )= v 2 -v 0 v 0 v 1 -v 0 = (1-u-v)v 0 +uv 1 +vv 2 [u,v>=0, u+v<=1] Set t(u,v)=r(t), and solve! v 2 v 1

Solve with Cramer s rule: d e 1 e 2 t u v = s A x = b

Solve with Cramer s rule: Share factors to speed up computations d e 1 e 2 t u v = s

Be smart! Compute as little as possible. Then test Examples: Compute Then test valid bounds if (u<0 or u>1) exit;

Insert a point x into plane equation: Negative half space Positive half space origin

Sphere: compute f (c) is the signed distance (n normalized) abs( f (c)) > r no collision abs( f (c)) = r sphere touches the plane abs( f (c)) < r sphere intersects plane Box: insert all 8 corners If all f s have the same sign, then all points are on the same side, and no collision

The smart way (shown in 2D) Find diagonal that is most closely aligned with plane normal Need only test the red points More details in book

Intersect ray with polygon plane Project from 3D to 2D How? Find max( n x, n y, n z ) Skip that coordinate! Then, count crossing in 2D

Used in collision detection Sphere/sphere Compute squared distance between sphere centers, and compare to (r 1 +r 2 ) 2 Axis-Aligned Bounding Box/AABB Test in 1D for x,y, and z max(x,y) max(x,y) Oriented Bounding boxes min(x,y) Use SAT [details in book] min(x,y)

View frustum is 6 planes: Near, far, right, left, top, bottom Create planes from projection matrix Let all positive half spaces be outside frustum Not dealt with here -- p. 773-774, 3rd ed. Sphere/frustum common approach: Test sphere against 6 frustum planes If in positive half space and r distances from plane => no intersection If intersecting plane or in negative half space, continue If not outside after all six planes, then inside or intersecting Example follows

outside frustum intersecting frustum Not exact test, but not incorrect A sphere that is reported to be inside, can be outside Not vice versa Similarly for boxes

Testing is often done every rendered frame, i.e., at discrete time intervals Therefore, you can get quantum effects Frame n Frame n+1 Dynamic testing deals with this Is more expensive Deals with a time interval: time between two frames

t=n r c v s c & s e are signed distances n s c r No collision occur: If they are on the same side of the plane (s c s e >0) Plus s c >r and s e >r Otherwise, sphere can move s c -r Time of collision: Response: reflect v around n, and move (1-t cd )r (r=refl vector) e t=n+1 s e

SAT: tests one axis at a time for overlap Same with DSAT, but: Need to adjust the projection on the axis so that the interval moves on the axis as well Need to test same axes as with SAT Same criteria for overlap/disjoint: If no overlap on axis => disjoint If overlap on all axes => objects overlap

http://graphics.idav.ucdavis.edu/~dcoming/papers/coming_staadt_vriphys05.pdf

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

Scan Line Fill Set active edges to AB and AC For y = A.y, A.y-1,...,C.y If y=b.y exchange AB with BC Compute xstart and xend. Interpolate color, depth, texcoords etc for points (xstart,y) and (xend,y) For x = xstart, xstart+1,...,xend Compute color, depth etc for (x,y) using interpolation. xend This is the modern way to rasterize a triangle

Using Interpolation C 1 C 2 C 3 specified by glcolor or by vertex shading C 4 determined by interpolating between C 1 and C 2 C 5 determined by interpolating between C 2 and C 3 interpolate between C 4 and C 5 along span C 1 scan line C 4 C 2 C 5 span C 3

Rasterizing a Triangle Convex Polygons only Nonconvex polygons assumed to have been tessellated Shades (colors) have been computed for vertices (Gouraud shading) Combine with z-buffer algorithm March across scan lines interpolating shades Incremental work small

Flood Fill Fill can be done recursively if we know a seed point located inside (WHITE) Scan convert edges into buffer in edge/inside color (BLACK) flood_fill(int x, int y) { if(read_pixel(x,y)= = WHITE) { write_pixel(x,y,black); flood_fill(x-1, y); flood_fill(x+1, y); flood_fill(x, y+1); flood_fill(x, y-1); } }