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

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

Modeling Transformations

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

Modeling Transformations

Indirect Illumination

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

Indirect Illumination

Geometric Queries for Ray Tracing

Ray Tracing I. History

Ray Tracing I. Internet Raytracing Competition

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

Supplement to Lecture 16

Ray casting. Ray casting/ray tracing

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

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

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

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

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

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

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

1999, Denis Zorin. Ray tracing

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

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

8.1 Geometric Queries for Ray Tracing

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

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

Ray Tracing Foley & Van Dam, Chapters 15 and 16

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

Three Main Themes of Computer Graphics

Lecture 11: Ray tracing (cont.)

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

Intersecting Simple Surfaces. Dr. Scott Schaefer

Topics and things to know about them:

Illumination. Courtesy of Adam Finkelstein, Princeton University

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

Viewing and Ray Tracing. CS 4620 Lecture 4

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

Viewing and Ray Tracing

From Vertices To Fragments-1

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

Questions??? Announcements Assignment 3 due today

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

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

Models and Architectures

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

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

Surfaces. Ron Goldman Department of Computer Science Rice University

CS 563 Advanced Topics in Computer Graphics. by Emmanuel Agu

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

Ray Tracing I: Basics

EECS 487, Fall 2005 Exam 2

The University of Calgary

Implicit Surfaces & Solid Representations COS 426

Ray Tracing. Outline. Ray Tracing: History

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

FROM VERTICES TO FRAGMENTS. Lecture 5 Comp3080 Computer Graphics HKBU

The Law of Reflection

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

Projective Geometry and Camera Models

COMP30019 Graphics and Interaction Perspective & Polygonal Geometry

Intro to Modeling Modeling in 3D

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

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

TEAMS National Competition Middle School Version Photometry Solution Manual 25 Questions

Scanline Rendering 1 1/42

CS770/870 Spring 2017 Ray Tracing Implementation

Answer Key: Three-Dimensional Cross Sections

Sung-Eui Yoon ( 윤성의 )

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

Ray Tracing. Shandong University

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

Moore Catholic High School Math Department

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

Ray Casting. COS 426, Spring 2015 Princeton University

Introduction to Computer Graphics with WebGL

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

Solution Notes. COMP 151: Terms Test

Computer Graphics and Image Processing Ray Tracing I

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

Ray scene intersections

MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question.

CS452/552; EE465/505. Geometry Transformations

9. Three Dimensional Object Representations

Models and The Viewing Pipeline. Jian Huang CS456

Lecture 11. More Ray Casting/Tracing

CPSC GLOBAL ILLUMINATION

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

Input Nodes. Surface Input. Surface Input Nodal Motion Nodal Displacement Instance Generator Light Flocking

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

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

C O M P U T E R G R A P H I C S. Computer Graphics. Three-Dimensional Graphics I. Guoying Zhao 1 / 52

Algebra Based Physics

Precalculus 2 Section 10.6 Parametric Equations

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

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 plane v 1, 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 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: float xfov, yfov Film plane (View plane normal) back right Up direction Eye Position View Plane Look at Point

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 has to originate 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 + = p 1 + i + 0.5 height i + 0.5 height p 2 p 1 2 d tan θ up 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 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 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

Ray-Triangle Intersection I Check if point is inside triangle algebraically: Generate triangles by connecting the ray source to each edge Check if the point of intersection is above each of these triangles For each side of triangle 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