Computer Graphics. Ray Tracing. Based on slides by Dianna Xu, Bryn Mawr College

Similar documents
Shading I Computer Graphics I, Fall 2008

Comp 410/510 Computer Graphics. Spring Shading

Illumination & Shading

Lecture 15: Shading-I. CITS3003 Graphics & Animation

Shading. Why we need shading. Scattering. Shading. Objectives

Raytracing. COSC 4328/5327 Scott A. King

Computer Graphics. Shading. Based on slides by Dianna Xu, Bryn Mawr College

COMP371 COMPUTER GRAPHICS

Lighting and Shading

WHY WE NEED SHADING. Suppose we build a model of a sphere using many polygons and color it with glcolor. We get something like.

Ray Tracing. CSCI 420 Computer Graphics Lecture 15. Ray Casting Shadow Rays Reflection and Transmission [Ch ]

Introduction to Computer Graphics 7. Shading

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

Ray Tracing. Shandong University

Announcements. Written Assignment 2 out (due March 8) Computer Graphics

Rendering: Reality. Eye acts as pinhole camera. Photons from light hit objects

Supplement to Lecture 16

Topic 12: Texture Mapping. Motivation Sources of texture Texture coordinates Bump mapping, mip-mapping & env mapping

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

Ray-Tracing. Misha Kazhdan

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

CS452/552; EE465/505. Intro to Lighting

Lighting. Figure 10.1

Problem Set 4 Part 1 CMSC 427 Distributed: Thursday, November 1, 2007 Due: Tuesday, November 20, 2007

Photorealism: Ray Tracing

Topic 11: Texture Mapping 11/13/2017. Texture sources: Solid textures. Texture sources: Synthesized

Objectives. Introduce Phong model Introduce modified Phong model Consider computation of required vectors Discuss polygonal shading.

Virtual Reality for Human Computer Interaction

Topic 11: Texture Mapping 10/21/2015. Photographs. Solid textures. Procedural

I have a meeting with Peter Lee and Bob Cosgrove on Wednesday to discuss the future of the cluster. Computer Graphics

CS130 : Computer Graphics Lecture 8: Lighting and Shading. Tamar Shinar Computer Science & Engineering UC Riverside

Reflection and Shading

CS5620 Intro to Computer Graphics

Ø Sampling Theory" Ø Fourier Analysis Ø Anti-aliasing Ø Supersampling Strategies" Ø The Hall illumination model. Ø Original ray tracing paper

Computer Graphics (CS 4731) Lecture 16: Lighting, Shading and Materials (Part 1)

Local Illumination. CMPT 361 Introduction to Computer Graphics Torsten Möller. Machiraju/Zhang/Möller

Lecture 10: Ray tracing

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

Illumination & Shading: Part 1

Ray Tracing. Kjetil Babington

Computer Graphics (CS 543) Lecture 7b: Intro to lighting, Shading and Materials + Phong Lighting Model

Overview. Shading. Shading. Why we need shading. Shading Light-material interactions Phong model Shading polygons Shading in OpenGL

Recursive Ray Tracing. Ron Goldman Department of Computer Science Rice University

Raytracing CS148 AS3. Due :59pm PDT

CENG 477 Introduction to Computer Graphics. Ray Tracing: Shading

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

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

Lecture 17: Recursive Ray Tracing. Where is the way where light dwelleth? Job 38:19

CS 428: Fall Introduction to. Raytracing. Andrew Nealen, Rutgers, /18/2009 1

CS 325 Computer Graphics

Advanced Ray Tracing

Computer Graphics. Lecture 13. Global Illumination 1: Ray Tracing and Radiosity. Taku Komura

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

Recollection. Models Pixels. Model transformation Viewport transformation Clipping Rasterization Texturing + Lights & shadows

ECS 175 COMPUTER GRAPHICS. Ken Joy.! Winter 2014

Visual cues to 3D geometry. Light Reflection and Advanced Shading. Shading. Recognizing materials. size (perspective) occlusion shading

Topic 9: Lighting & Reflection models 9/10/2016. Spot the differences. Terminology. Two Components of Illumination. Ambient Light Source

Introduction to Visualization and Computer Graphics

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

Consider a partially transparent object that is illuminated with two lights, one visible from each side of the object. Start with a ray from the eye

Topic 9: Lighting & Reflection models. Lighting & reflection The Phong reflection model diffuse component ambient component specular component

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

OpenGl Pipeline. triangles, lines, points, images. Per-vertex ops. Primitive assembly. Texturing. Rasterization. Per-fragment ops.

Reflection and Refraction

Waves-Refraction. 5. A change in the speed of a wave as it enters a new medium produces a change in 1. frequency 2. period 3. wavelength 4.

EECS 487: Interactive Computer Graphics

Reflection and Refraction

Simple Lighting/Illumination Models

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

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

Illumination Models & Shading

Complex Shading Algorithms

CSE 167: Lecture #7: Color and Shading. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2011

Lecture 11: Ray tracing (cont.)

Ray Tracer Due date: April 27, 2011

w Foley, Section16.1 Reading

Lighting and Shading Computer Graphics I Lecture 7. Light Sources Phong Illumination Model Normal Vectors [Angel, Ch

Today. Global illumination. Shading. Interactive applications. Rendering pipeline. Computergrafik. Shading Introduction Local shading models

Three-Dimensional Graphics V. Guoying Zhao 1 / 55

Global Illumination. CSCI 420 Computer Graphics Lecture 18. BRDFs Raytracing and Radiosity Subsurface Scattering Photon Mapping [Ch

Today. Global illumination. Shading. Interactive applications. Rendering pipeline. Computergrafik. Shading Introduction Local shading models

Sung-Eui Yoon ( 윤성의 )

Global Illumination. Global Illumination. Direct Illumination vs. Global Illumination. Indirect Illumination. Soft Shadows.

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

Specular reflection. Lighting II. Snell s Law. Refraction at boundary of media

Computer Graphics. Lecture 10. Global Illumination 1: Ray Tracing and Radiosity. Taku Komura 12/03/15

Local vs. Global Illumination & Radiosity

Implementation Issues

Ray Tracing. Local Illumination. Object Space: Global Illumination. Image Space: Backward Ray Tracing. First idea: Forward Ray Tracing

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

Refraction of Light. c = m / s. n = c v. The index of refraction is never less than 1. Some common indices of refraction are listed below.

Global Illumination. Global Illumination. Direct Illumination vs. Global Illumination. Indirect Illumination. Soft Shadows.

COMP environment mapping Mar. 12, r = 2n(n v) v

Objectives. Shading II. Distance Terms. The Phong Reflection Model

The Rendering Equation. Computer Graphics CMU /15-662

Lighting and Shading. Slides: Tamar Shinar, Victor Zordon

TEAMS National Competition High School Version Photometry 25 Questions

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

The V-Ray installer will automatically remove any previous installations. This will allow you to seamlessly upgrade from previous versions.

Chapter 32 Light: Reflection and Refraction. Copyright 2009 Pearson Education, Inc.

Transcription:

Computer Graphics Ray Tracing Based on slides by Dianna Xu, Bryn Mawr College

Ray Tracing Example Created by Anto Matkovic

Ray Tracing Example

Ray Tracing Example

Ray Tracing Most light rays do not reach the eye Start from eye point Cast one ray through each pixel Each ray either intersects or not If no intersection assign background color If intersection trace reflected, refracted, and shadow rays.

Simple Ray Tracing Algorithm Color trace(point p, Vector d, int step) { Color local, reflected, transmitted; Point q; Vector normal; if (step > max) return (background_color); q = intersect(p, d, status); if (status == no_intersection) return (background_color); normal = do_normal(q); Vector reflectdir = reflect(q, normal); Vector transdir = transmit(q, normal);

Simple Ray Tracing Algorithm // must check shadow ray local = phong(q, normal, reflectdir); reflected = trace(q, reflectdir, step+1); transmitted = trace(q, transdir, step+1); } return(local+reflected+trasmitted);

Ray Tracing with Several Ray Effects

Ray Tracing Necessary to Render Superellipsoids

Ray-Sphere Intersection A sphere is described by its center c and radius r. A point p on sphere: A ray is described by its origin o, and a direction vector d. A point on a ray has the form:

Ray-Sphere Substituting into sphere equation: Squaring both sides we get:

Quadratic Equation Rewrite as quadratic quation: where Number of solutions depends on discriminant:

The Discriminant 1. ==> no solution (ray misses) 2. ==> one solution (ray tangent) 3. ==> two solutions (ray punctures) Ray extends only in one direction (positive t) want closest intersection solution with least non-negative t.

The Result In case 1, report no insersection In case 2, report no intersection if t<0 ==> B>0, otherwise return solution (-B/ 2A) for t In case 3, return the least positive of the two solutions for t. If both negative, report no intersection If there is intersection, then the intersection point is o+td.

Ray-Triangle Intersection Compute intersection point of ray and the plane of the given triangle. If there is intersection, decide if the intersection point lies inside or outside of the triangle.

Ray-Plane Given vertices a1, a2, a3. Normal: A point p on the plane of triangle: Substituting Solves to

Point inside Triangle Check the cross product: If this cross product has the same direction as the normal then point p is on the same side of a1a2 as a3 Repeat for the other two edges.

Point inside Triangle boolean SameSide(Point p,point a1,point a2,point a3) { Vector cp1 = cp(a2-a1, p-a1); Vector cp2 = cp(a2-a1, a3-a1); if (dp(cp1, cp2)) >= 0 return true; else return false; } boolean PointInTriangle(Point p,point a,point b,point c) { if (SameSide(p,a,b,c)&& SameSide(p,b,a,c) && SameSide(p,c,a,b)) return true; else return false; }

Viewing Geometry for a Simple Ray Tracer Screen described by a point l its lower left corner. Two vectors (h and v) used to iterate over the raster positions on the target NDC space. Eye is given by e. Compute ray direction from eye to pixel (i,j)

Ray Direction To reach the lower left corner of desired pixel (i,j) from l : The move to the center of the pixel: Direction of ray is a vector from eye to center of desired pixel:

Simple Viewing Geometry P=(i/m,j/n) (1,1) U V l (0,0) H e

The Rays and the Outer Loops Iterate this for each pixel (integer) coordinate pair. for pixel(x,y) x = 0 to width-1 for pixel(x,y) y = 0 to height-1 { } R=(l+(i+0.5)/m*h+(j+0.5)/n*v)-e; color = raytrace(e, R, 0) pixel(x,y) = color;

Antialiasing Ray tracing is a sampling method, and is thus subject to aliasing errors. Over sample and then average Instead of one ray through the center of the pixel, shoot multiple rays just slightly off the original center (left, right, up, down), and average the results as the final output.

Antialiased Ray Tracing Adaptive Supersampling (Weighted sub-pixel averaging) D E F A B C Cast rays through pixel corners (not centers) Take average of corner values If one corner differs significantly from average, Subdivide, adding 5 corners Repeat for each sub-area, averaging to obtain area value D E F E K F E K F Value for pixel BCEF = A B C H I J B G C H I P J M N O B G C L

Local Reflection Model A simple model that can be computed rapidly The intensity of the reflected light as a function of: the orientation of the surface with respect to the position of a point light source and surface properties. Physical phenomena simulated Perfect specular reflection Imperfect specular reflection Perfect diffuse reflection

The Phong Model Has three components Diffuse Specular Ambient Uses four vectors To source (l) To viewer (v) Normal (n) Perfect reflector (r)

Ideal Reflector Normal is determined by local orientation Angle of incidence = angle of reflection The three vectors must be coplanar

Perfectly Diffuse Reflector Matte/Lambertian surface Light scattered equally in all directions Amount of light reflected is proportional to the vertical component of incoming light reflected light depends on cos θ cos θ = l n if vectors normalized

Specular Surfaces Most surfaces are neither ideal diffusers nor perfectly specular (ideal reflectors) Smooth surfaces show specular highlights due to incoming light being reflected in directions concentrated close to the direction of a perfect reflection specular highlight

Modeling Specular Reflections Phong proposed using a term that dropped off as the angle φ between the viewer and the ideal reflection increased I r ~ k s I s cos α φ reflected shininess coef intensity incoming intensity reflection coef φ

Specular Bump Adds to Diffuse Component Diffuse component (Viewer independent) Specular component (Viewer dependent)

The Shininess Coefficient As α increases, the reflected light is concentrated over a narrower region. Values of α between 100 and 200 correspond to metals, smaller values give surface that look like plastic cos α φ -90 φ 90

Ambient Light Ambient light is the result of multiple interactions between (large) light sources and the objects in the environment Appears to be uniform all over. Add k a I a to diffuse and specular terms reflection coef amount of ambient light

Distance Terms The amount of light from a point source that reaches a surface is inversely proportional to the square of the distance between them We can add a factor to the diffuse and specular terms The constant and linear terms soften the effect of the point source

Light Sources In the Phong Model, we add the results from each light source Each light source has separate diffuse, specular, and ambient terms Separate red, green and blue components Hence, 9 coefficients for each point light source

Material Properties Material properties match light source properties 9 reflection coefficients Shininess coefficient α

Adding up the Components For each light source and each color component, the Phong model can be written (without the distance terms) as For each color component we add contributions from all sources

Shadow Ray Trace ray from point of intersection back towards light source. If blocked by another surface before reaching light, then original point is in shadow only lit with ambient term If some surfaces are highly reflective (mirrors) Shadow ray will bounce off and continue This is usually done recursively

Reflection and Transmission If a ray hits a surface not in shadow Do reflection calculation according to Phong model Cast ray in direction of perfect reflection Cast ray in direction of transmitted ray

Transmission Vector

Transmission Vector (cont.) 1 We now have two equations and two unknowns! Some algebra and a look at the geometry gives us:

Ray Tracing with Recursion Add shadow rays to light sources. Stop at diffuse surface, or when maximum number of recursive steps exceeded. Color at visible point is established by recursively combining the shades computed at the end of each ray which depends of course, on what, if anything, it hits.

Recursive Ray Tracing If an eye ray intersects an object: Cast shadow rays to each light source. diffuse illumination shadows Cast reflection ray, search for object intersection. ambient illumination Cast transmission ray, search for object intersection. Transparency For each new reflection and transmission ray, repeat. Until no intersection Until N intersections (recursion depth) (3 N 7)

Ray Tracing Diagram (Diffuse) Yellow light Eye and pixel P Diffuse surface Solid surface Translucent surface Red light P is visible; illuminated by yellow light; but not by red light

Ray Tracing Diagram (Reflective) Yellow light Eye and pixel P Reflective surface Solid surface Translucent surface Red light P is visible; illuminated by yellow light; but not by red light

Typical Ray Traced Image

Refracted Ray Geometry Transmitting surface I N = Index of refraction of substance 1 Snell s Law: (I and T are coplanar) -N T = Index of refraction of substance 2

Refraction and the Critical Angle Different effect at the critical angle N Transmitting surface I T -N

Refraction and the Critical Angle Internal reflection effect beyond the critical angle N Transmitting surface I T -N

Index of Refraction Medium Water 1.33 Ethyl Alcohol 1.36 Carbon Bisulfide 1.63 Air 1.0003 Methylene Iodide 1.74 Fused Quartz 1.46 Glass, Crown 1.52 Glass, Dense Flint 1.66 Sodium Chloride 1.53 Index of Refraction Note: These are approximations. The index of refraction actually differs with each wavelength of light.

Reflection and Refraction

Closer to Real Glass

Ray Tracing Cost Considerations COST = X Y 2 a (m + 1) (2 n - 1) P X = number of pixels horizontally Y = number of pixels vertically a = anti-aliasing super-sampling factor m = number of (point) light sources n = tree (recursion) depth P = number of primitives tested for ray intersections if X=Y=1000, a=0, m=1, n=10, P=1000 then COST ~ 2,046,000,000,000 ray-primitive intersection tests!

Problems With Ray Tracing Ray/object intersection calculations become expensive with complex objects and more objects. Light from other objects (other than pure reflection) is not modeled. Still use the constant ambient light component. Shadows often appear too sharp Surfaces appear too glossy or smooth Images take a long time to render, must recalculate for each new view Have to tweak illumination model constants to get desired effect