3D Rendering and Ray Casting

Similar documents
3D Rendering and Ray Casting

3D Rendering. Course Syllabus. Where Are We Now? Rendering. 3D Rendering Example. Overview. Rendering. I. Image processing II. Rendering III.

Rendering. Generate an image from geometric primitives II. Rendering III. Modeling IV. Animation. (Michael Bostock, CS426, Fall99)

Ray Casting. Connelly Barnes CS 4810: Graphics

Ray-Tracing. Misha Kazhdan

Modeling Transformations

Indirect Illumination

קורס גרפיקה ממוחשבת 2010/2009 סמסטר א' Rendering 1 חלק מהשקפים מעובדים משקפים של פרדו דוראנד, טומס פנקהאוסר ודניאל כהן-אור

Illumination. Michael Kazhdan ( /657) HB Ch. 14.1, 14.2 FvDFH 16.1, 16.2

Modeling Transformations

Geometric Queries for Ray Tracing

Ray Tracing Part 1. CSC418/2504 Introduction to Computer Graphics. TA: Muhammed Anwar & Kevin Gibson

Indirect Illumination

Ray Tracing I. Internet Raytracing Competition

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

Ray Tracing I. History

Ray casting. Ray casting/ray tracing

Raycasting. Chapter Raycasting foundations. When you look at an object, like the ball in the picture to the left, what do

Supplement to Lecture 16

COMP 175 COMPUTER GRAPHICS. Ray Casting. COMP 175: Computer Graphics April 26, Erik Anderson 09 Ray Casting

Ray Tracing Basics I. Computer Graphics as Virtual Photography. camera (captures light) real scene. photo. Photographic print. Photography: processing

1999, Denis Zorin. Ray tracing

Ray Tracing. CS334 Fall Daniel G. Aliaga Department of Computer Science Purdue University

Last Time? Ray Casting. Administrivia: Lab & Office Hours. Notes on Assignments. Ray Casting. Overview of Today

8.1 Geometric Queries for Ray Tracing

Polygonal Meshes. 3D Object Representations. 3D Object Representations. 3D Polygonal Mesh. 3D Polygonal Mesh. Geometry background

Ray Tracing. Foley & Van Dam, Chapters 15 and 16

Ray Tracing Foley & Van Dam, Chapters 15 and 16

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

Chapter 23. Geometrical Optics (lecture 1: mirrors) Dr. Armen Kocharian

Ray Casting. COS 426, Spring 2015 Princeton University

Lecture 11: Ray tracing (cont.)

Computer Graphics. Si Lu. Fall uter_graphics.htm 11/22/2017

Three Main Themes of Computer Graphics

Questions??? Announcements Assignment 3 due today

Introduction Ray tracing basics Advanced topics (shading) Advanced topics (geometry) Graphics 2010/2011, 4th quarter. Lecture 11: Ray tracing

From Vertices To Fragments-1

Topics and things to know about them:

Viewing and Ray Tracing. CS 4620 Lecture 4

Ray Casting. 3D Rendering. Ray Casting. Ray Casting. Ray Casting. Ray Casting

Viewing and Ray Tracing

Ray Tracing. Last Time? Reading for Today. Reading for Today

INFOGR Computer Graphics. Jacco Bikker - April-July Lecture 3: Ray Tracing (Introduction) Welcome!

Intersecting Simple Surfaces. Dr. Scott Schaefer

Last week. Machiraju/Zhang/Möller

ECE-161C Cameras. Nuno Vasconcelos ECE Department, UCSD

Motivation. Sampling and Reconstruction of Visual Appearance. Effects needed for Realism. Ray Tracing. Outline

So far, we have considered only local models of illumination; they only account for incident light coming directly from the light sources.

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

FROM VERTICES TO FRAGMENTS. Lecture 5 Comp3080 Computer Graphics HKBU

Intro to Modeling Modeling in 3D

CS 563 Advanced Topics in Computer Graphics Lecture 2: Bare-Bones Raytracer. by Emmanuel Agu

EECS 487, Fall 2005 Exam 2

Temporal Resolution. Flicker fusion threshold The frequency at which an intermittent light stimulus appears to be completely steady to the observer

Effects needed for Realism. Ray Tracing. Ray Tracing: History. Outline. Foundations of Computer Graphics (Spring 2012)

The University of Calgary

Homework #1. Displays, Alpha Compositing, Image Processing, Affine Transformations, Hierarchical Modeling

The Law of Reflection

Ray Tracing. Outline. Ray Tracing: History

A simple method for interactive 3D reconstruction and camera calibration from a single view

Lecture 8 Ray tracing Part 1: Basic concept Yong-Jin Liu.

Homework #2. Shading, Projections, Texture Mapping, Ray Tracing, and Bezier Curves

Ray Tracing. Shandong University

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

Computer Graphics Ray Casting. Matthias Teschner

TEAMS National Competition Middle School Version Photometry Solution Manual 25 Questions

Answer Key: Three-Dimensional Cross Sections

Models and Architectures

Surfaces. Ron Goldman Department of Computer Science Rice University

CS770/870 Spring 2017 Ray Tracing Implementation

Scanline Rendering 1 1/42

Sung-Eui Yoon ( 윤성의 )

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

CS 563 Advanced Topics in Computer Graphics. by Emmanuel Agu

Solution Notes. COMP 151: Terms Test

Moore Catholic High School Math Department

Movie: Geri s Game. Announcements. Ray Casting 2. Programming 2 Recap. Programming 3 Info Test data for part 1 (Lines) is available

Computer Graphics and Image Processing Ray Tracing I

Ray Tracing I: Basics

Illumination. Courtesy of Adam Finkelstein, Princeton University

Ray Casting. Outline. Similar to glulookat derivation. Foundations of Computer Graphics

Implicit Surfaces & Solid Representations COS 426

Lecture 11. More Ray Casting/Tracing

COMP30019 Graphics and Interaction Perspective & Polygonal Geometry

Part Images Formed by Flat Mirrors. This Chapter. Phys. 281B Geometric Optics. Chapter 2 : Image Formation. Chapter 2: Image Formation

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

Projective Geometry and Camera Models

Computer Graphics 7: Viewing in 3-D

Rendering. What is 3D rendering? קורס גרפיקה ממוחשבת 2008 סמסטר ב' מצלמה תאורה. Rendering Scenarios. Rendering Scenarios. 3D Rendering Issues

High-Dimensional Computational Geometry. Jingbo Shang University of Illinois at Urbana-Champaign Mar 5, 2018

LECTURE 7. Announcements

Today. Acceleration Data Structures for Ray Tracing. Cool results from Assignment 2. Last Week: Questions? Schedule

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

Notes on Spherical Geometry

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

LECTURE 6. Announcements

CSC418 / CSCD18 / CSC2504

Today. Part 1: Ray casting Part 2: Lighting Part 3: Recursive Ray tracing Part 4: Acceleration Techniques

Ray-tracing Acceleration. Acceleration Data Structures for Ray Tracing. Shadows. Shadows & Light Sources. Antialiasing Supersampling.

Illumination Models III: Ray Tracing (View Dependent Global Illumination)

Transcription:

3D Rendering and Ray Casting Michael Kazhdan (601.457/657) HB Ch. 13.7, 14.6 FvDFH 15.5, 15.10

Rendering Generate an image from geometric primitives Rendering Geometric Primitives (3D) Raster Image (2D)

3D Rendering Example What issues must be addressed by a 3D rendering system?

Overview 3D scene representation 3D viewer representation What do we see? How does it look?

Overview 3D scene representation 3D viewer representation What do we see? How does it look? How is the 3D scene described in a computer?

3D Scene Representation Scene is usually approximated by 3D primitives Point Line segment Polygon Polyhedron Curved surface Solid object etc.

3D Point Specifies a location Origin

3D Point Specifies a location Represented by three coordinates Infinitely small struct Point3D { float x, y, z; }; (x, y, z) Origin

3D Vector Specifies a direction and a magnitude

3D Vector Specifies a direction and a magnitude Represented by three coordinates Magnitude Ԧv = dx 2 + dy 2 + dz 2 Has no location struct Vector3D { float dx, dy, dz; }; Ԧv = (dx, dy, dz)

3D Vector Specifies a direction and a magnitude Represented by three coordinates Magnitude Ԧv = dx 2 + dy 2 + dz 2 Has no location Dot product of two 3D vectors Ԧv 1, Ԧv 2 = dx 1 dx 2 + dy 1 dy 2 + dz 1 dz 2 Ԧv 1, Ԧv 2 = Ԧv 1 Ԧv 2 cos θ Cross product of two 3D vectors Ԧv 1 Ԧv 2 = Vector normal to v 1 and v 2 Ԧv 1 Ԧv 2 = Ԧv 1 Ԧv 2 sin θ θ Ԧv 1 = (dx 1, dy 1, dz 1 ) Ԧv 2 = (dx 2, dy 2, dz 2 )

Cross Product: Review Let Ԧv 1 = Ԧv 2 Ԧv 3 : dx 1 = dy 2 dz 3 dz 2 dy 3 dy 1 = dz 2 dx 3 dx 2 dz 3 dz 1 = dx 2 dy 3 dy 2 dx 3 Ԧv w = w Ԧv (remember right-hand rule) We can show: Ԧv w = Ԧv w sin θ n, where n is the unit vector normal to Ԧv and w Ԧv Ԧv = 0

3D Line Segment Linear path between two points Origin

3D Line Segment Use a linear combination of two points Parametric representation:» p t = p 1 + t (p 2 p 1 ), (0 t 1) p 2 struct Segment3D { Point3D p1, p2; }; p 1 Origin

3D Ray Line segment with one endpoint at infinity Parametric representation:» p t = p 1 + t Ԧv, (0 t < ) struct Ray3D { Point3D p1; Vector3D v; }; p 1 Ԧv Origin

3D Line Line segment with both endpoints at infinity Parametric representation:» p t = p 1 + t Ԧv, ( < t < ) struct Line3D { Point3D p1; Vector3D v; }; p 1 Ԧv Origin

3D Plane A linear combination of three points p 2 p 3 p 1 Origin

3D Plane A linear combination of three points Implicit representation:» Φ p = ax + by + cz d = 0» Φ p = p, n d = 0, or struct Plane3D { Vector3D n; float d; }; p 2 n is the plane normal» (May be) unit-length vector» Perpendicular to plane d is the signed (weighted) distance of the plane from the origin. p 1 n = (a, b, c) d p 3 Origin

3D Polygon Area inside a sequence of coplanar points Triangle Quadrilateral Convex Star-shaped Concave Self-intersecting struct Polygon3D { Point3D *points; int npoints; }; Points are in counter-clockwise order Holes (use > 1 polygon struct)

3D Sphere All points at distance r from center point c = (c x, c y, c z ) Implicit representation:» Φ p = p c 2 r 2 = 0 Parametric representation:» x φ, θ = r cos φ sin θ + c x» y φ, θ = r cos φ sin θ + c y» z θ, φ = r sin φ + c z c r struct Sphere3D { Point3D center; float radius; }; Origin

Other 3D primitives Cone Cylinder Ellipsoid Box Etc.

3D Geometric Primitives More detail on 3D modeling later in course Point Line segment Polygon Polyhedron Curved surface Solid object etc.

Overview 3D scene representation 3D viewer representation What do we see? How does it look? How is the viewing device described in a computer?

Camera Models The most common model is pin-hole camera All captured light rays arrive along paths toward focal point without lens distortion (everything is in focus) View plane Other models consider... Depth of field Motion blur Lens distortion Eye position (focal point)

Camera Parameters What are the parameters of a camera?

Camera Parameters Position Eye position: Point3D eye Orientation View direction: Vector3D view Up direction: Vector3D up Aperture Field of view angle: float xfov, yfov Film plane (View plane normal) back Up direction View Plane Look at Point right Eye Position

Other Models: Depth of Field Close Focused Distance Focused P. Haeberli

Other Models: Motion Blur Mimics effect of open camera shutter Gives perceptual effect of high-speed motion Generally involves temporal super-sampling Brostow & Essa

Traditional Pinhole Camera The film sits behind the pinhole of the camera. Rays come in from the outside, pass through the pinhole, and hit the film plane. Film Plane Pinhole

Traditional Pinhole Camera The film sits behind the pinhole of the camera. Rays come in from the outside, pass through the pinhole, and hit the film plane. Photograph is upside down Film Plane Pinhole

Virtual Camera The film sits in front of the pinhole of the camera. Rays come in from the outside, pass through the film plane, and hit the pinhole. Pinhole Film Plane

Virtual Camera The film sits in front of the pinhole of the camera. Rays come in from the outside, pass through the film plane, and hit the pinhole. Photograph is right side up Pinhole Film Plane

Overview 3D scene representation 3D viewer representation Ray Casting Where are we looking? What do we see? How does it look?

Ray Casting For each sample Where: Construct ray from eye through view plane What: Find first surface intersected by ray through pixel How: Compute color sample based on surface radiance

Ray Casting Simple implementation: Image RayCast( Camera camera, Scene scene, int width, int height) { Image image = new Image( width, height ); for( int i=0 ; i<width ; i++ ) for( int j=0 ; j<height ; j++ ) { Ray ray = ConstructRayThroughPixel( camera, i, j ); Intersection hit = FindIntersection( ray, scene ); image[i][j] = GetColor( hit ); } } return image; }

Ray Casting Where? Image RayCast( Camera camera, Scene scene, int width, int height) { Image image = new Image( width, height ); for( int i=0 ; i<width ; i++ ) for( int j=0 ; j<height ; j++ ) { Ray ray = ConstructRayThroughPixel( camera, i, j ); Intersection hit = FindIntersection( ray, scene ); image[i][j] = GetColor( hit ); } } return image; }

Constructing a Ray Through a Pixel Up direction View Plane back p 0 right v p i [j]

Constructing a Ray Through a Pixel Up direction View Plane back p 0 right v The ray originates at p 0 (the position of the camera). So the equation for the ray is: Ray t = p 0 + t Ԧv p i [j]

Constructing a Ray Through a Pixel Up direction View Plane back p 0 right v If the ray passes through the point p i [j], then the solution for Ԧv is: Ԧv = p i [j] p 0 p i [j] p 0 p i [j]

Constructing a Ray Through a Pixel Up direction View Plane back p 0 right v p i [j] If p i [j] represents the (i, j)-th pixel of the image, what is its position?

Constructing Ray Through a Pixel 2D Example: Side view of camera at p 0 Where is the i-th pixel, p[i]? (i [0, height)) θ = frustum half-angle (given), or field of view d = distance to view plane (arbitrary = you pick) up p 0 θ towards d

Constructing Ray Through a Pixel 2D Example: Side view of camera at p 0 Where is the i-th pixel, p[i]? (i [0, height)) θ = frustum half-angle (given), or field of view d = distance to view plane (arbitrary = you pick) p 2 p 1 = p 0 + d towards d tan θ up p 2 = p 0 + d towards + d tan θ up p 0 up θ towards d 2 d tan θ p 1

Constructing Ray Through a Pixel 2D Example: Side view of camera at p 0 Where is the i-th pixel, p[i]? (i [0, height)) θ = frustum half-angle (given), or field of view d = distance to view plane (arbitrary = you pick) p 2 p 1 = p 0 + d towards d tan θ up p 2 = p 0 + d towards + d tan θ up p 0 up θ towards d 2 d tan θ p i = p 1 + i + 0.5 height p 2 p 1 p[i] p 1

Constructing Ray Through a Pixel 2D Example: The ray passing through the i-th pixel is defined by: Ray t = p 0 + t Ԧv p 0 : camera position Ԧv: direction to the i-th pixel: Ԧv = p i p 0 p i p 0 p 0 θ p[i]: i-th pixel location: i + 0.5 p i = p 1 + p height 2 p 1 p 1 and p 2 are the endpoints of the view plane: p 1 = p 0 + d towards d tan θ up p 2 = p 0 + d towards + d tan θ up up towards d p[i] p 2 p 1 2 d tan θ

Constructing Ray Through a Pixel Figuring out how to do this in 3D is assignment 2 p 2 p 0 up θ towards d 2 d tan θ p[i] p 1

Ray Casting Where? Image RayCast( Camera camera, Scene scene, int width, int height) { Image image = new Image( width, height ); for( int i=0 ; i<width ; i++ ) for( int j=0 ; j<height ; j++ ) { Ray ray = ConstructRayThroughPixel( camera, i, j ); Intersection hit = FindIntersection( ray, scene ); image[i][j] = GetColor( hit ); } } return image; }

Ray Casting What? Image RayCast( Camera camera, Scene scene, int width, int height) { Image image = new Image( width, height ); for( int i=0 ; i<width ; i++ ) for( int j=0 ; j<height ; j++ ) { Ray ray = ConstructRayThroughPixel( camera, i, j ); Intersection hit = FindIntersection( ray, scene ); image[i][j] = GetColor( hit ); } } return image; }

Ray-Scene Intersection Intersections with geometric primitives Sphere Triangle

Ray-Sphere Intersection Ray: p t = p 0 + t Ԧv, (0 t < ) Sphere: Φ p = p c 2 r 2 = 0 p p p 0 v r c

Ray-Sphere Intersection Ray: p t = p 0 + t Ԧv, (0 t < ) Sphere: Φ p = p c 2 r 2 = 0 Substituting for p(t), we get: Φ t = p 0 t Ԧv c 2 r 2 = 0 Solve quadratic equation: a t 2 + b t + c = 0 where: a = 1 b = 2 Ԧv, p 0 c c = p 0 c 2 r 2 p 0 v p r c p

Ray-Sphere Intersection Ray: p t = p 0 + t Ԧv, (0 t < ) Sphere: Φ p = p c 2 r 2 = 0 Substituting for p(t), we get: Φ t = p 0 t Ԧv c 2 r 2 = 0 Solve quadratic equation: a t 2 + b t + c = 0 where: a = 1 b = 2 Ԧv, p 0 c p 0 v Generally, there are two solutions to the c = quadratic p 0 c 2 equation, r 2 giving rise to points p and p. Want to return the first positive hit. p r c p

Ray-Sphere Intersection Need normal vector at intersection for lighting calculations: p c n = p c n p 0 Ԧv p r c

Ray-Scene Intersection Intersections with geometric primitives Sphere» Triangle

Ray-Triangle Intersection First, intersect ray with plane Then, check if point is inside triangle p Ԧv p 0

Ray-Plane Intersection Ray: p t = p 0 + t Ԧv, (0 t < ) Plane: Φ p = p, n d = 0 Substituting for P, we get: Φ t = p 0 + t Ԧv, n d = 0 Algebraic Method Solution: t = p 0, n d Ԧv, n Ԧv p n p 0 What are the implications of Ԧv, n = 0?

Ray-Triangle Intersection I Check if point is inside triangle algebraically: Generate planes through the ray source and each edge Check if the point of intersection is above each of these planes For each plane Ԧv 1 = T 1 p 0 Ԧv 2 = T 2 p 0 n 1 = v 2 v 1 if ( p p 0, n 1 < 0 ) return FALSE; Ԧv 1 T 1 n 1 Ԧv 2 p T 3 T 2 p 0

Ray-Triangle Intersection II Check if point is inside triangle parametrically A point p is inside the triangle iff. it can be expressed as the weighted average of the corners: p = α T 1 + β T 2 + γ T 3 where: 0 α, β, γ 1 α + β + γ = 1 α T 1 p γ T 3 β T2

Ray-Triangle Intersection II Check if point is inside triangle parametrically Solve for α, β, γ such that: p = α T 1 + β T 2 + γ T 3 And α + β + γ = 1 γ T 3 Check if the point is in the triangle: 0 α, β, γ 1 T 1 α p β Ԧv T2 p 0

Ray-Triangle Intersection II Check if point is inside triangle parametrically In general, given p R 3 and given three points T 1, T 2, T 3 R 3 (in general position) we can solve for α, β, γ R such that: p = αt 1 + βt 2 + γt 3 T 1 α p γ T 3 β If p is in the plane spanned by T 1, T 2, T 3 : α + β + γ = 1 If p is inside the triangle with vertices {T 1, T 2, T 3 }: α, β, γ 0 T2

Ray-Triangle Intersection II Check if point is inside triangle parametrically In general, given p R 3 and given three points T 1, T 2, T 3 R 3 (in general position) we can solve for α, β, γ R such that: p = αt 1 + βt 2 + γt 3 T 1 α p γ T 3 β To get α, β, γ, solve the system: T 1 x T 2 x T 3 x T 1 y T 2 y T 3 y T 1 z T 2 z T 1 1 α β γ = p x p y p z T2

Ray-Triangle Intersection II Check if point is inside triangle parametrically In general, given p R 3 and given three points T 1, T 2, T 3 R 3 (in general position) we can solve for α, β, γ R such that: p = αt 1 + βt 2 + γt 3 This will fail if the vertices T 1, T 2, T 3 lie in a plane through the Torigin. 1 α p γ T 3 β To get α, β, γ, solve the system: T 1 x T 2 x T 3 x T 1 y T 2 y T 3 y T 1 z T 2 z T 1 1 α β γ = p x p y p z T2

Ray-Triangle Intersection II Check if point is inside triangle parametrically In general, given p R 3 and given three points T 1, T 2, T 3 R 3 (in general position) we can solve for α, β, γ R such that: p = αt 1 + βt 2 + γt 3 If p is in the plane spanned by T 1, T 2, T 3 we can translate so that T 1 is at the origin and solve for β, γ: T x x 2 T 1 T y y 2 T 1 T z z 2 T 1 T x x 3 T 1 T y y 3 T 1 T z z 3 T 1 T 1 x β px T 1 γ = p y y T 1 p z z T 1 α p γ T 3 β T2

Ray-Triangle Intersection II Check if point is inside triangle parametrically In general, given p R 3 and given three points T 1, T 2, T 3 R 3 (in general position) we can γ solve for α, β, γ R such that: p = αt 1 + βt 2 + γt 3 This is an over-constrained system but p α a solution If pexists in the since plane p is in spanned the plane spanned T 1 by {T β 1, T 2, T 3 }. by T 1, T 2, T After 3 we solving can translate for β and γ, we can set: so that T 1 is at the origin α = 1 and β solve γ for β, γ: x T x x 2 T 1 T y y 2 T 1 T z z 2 T 1 T x x 3 T 1 T y y 3 T 1 T z z 3 T 1 β px T 1 γ = p y y T 1 p z z T 1 T 3 T2

Other Ray-Primitive Intersections Cone, cylinder, ellipsoid: Similar to sphere Box Intersect 3 front-facing planes, return closest Convex polygon» Find the intersection of the ray with the plane» Check that the intersection is above every triangle generated by the ray source and polygon edge. Concave polygon Same plane intersection More complex point-in-polygon test