Ray Tracing COMP575/COMP770

Similar documents
A Little Background. Motivation. Motivation

Ray tracing idea. Ray Tracing. Ray tracing algorithm. Plane projection in drawing. CS 465 Lecture 3

Ray Tracing: shading

Viewing and Ray Tracing

Viewing and Ray Tracing. CS 4620 Lecture 4

Ray Tracing. CS 4620 Lecture 5

Animation and Ray Tracing

Particle systems, collision detection, and ray tracing. Computer Graphics CSE 167 Lecture 17

The Rasterization Pipeline

CENG 477 Introduction to Computer Graphics. Ray Tracing: Shading

Topics and things to know about them:

Pipeline Operations. CS 4620 Lecture 10

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

Lighting and Shading

Assignment 2 Ray Tracing

Shading I Computer Graphics I, Fall 2008

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

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

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

Supplement to Lecture 16

Raytracing CS148 AS3. Due :59pm PDT

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

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

Lecture 15: Shading-I. CITS3003 Graphics & Animation

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

Illumination & Shading

Shading. Brian Curless CSE 557 Autumn 2017

Comp 410/510 Computer Graphics. Spring Shading

The feature set you are required to implement in your ray tracer is as follows (by order from easy to hard):

Color and Light CSCI 4229/5229 Computer Graphics Fall 2016

Introduction to Ray-tracing Objectives

CS452/552; EE465/505. Intro to Lighting

Photorealism: Ray Tracing

Computer Graphics Tick 1

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

Ray Tracing. Brian Curless CSEP 557 Fall 2016

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

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

Pipeline Operations. CS 4620 Lecture Steve Marschner. Cornell CS4620 Spring 2018 Lecture 11

Pipeline Operations. CS 4620 Lecture 14

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

Intro to Ray-Tracing & Ray-Surface Acceleration

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

Interactive Real-Time Raycasting

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

Color and Light. CSCI 4229/5229 Computer Graphics Summer 2008

Blue colour text questions Black colour text sample answers Red colour text further explanation or references for the sample answers

Simple Lighting/Illumination Models

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

Lighting. Figure 10.1

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

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

w Foley, Section16.1 Reading

The University of Calgary

Computer Graphics. Illumination and Shading

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

Computer Graphics Ray Casting. Matthias Teschner

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

CS 381 Computer Graphics, Fall 2008 Midterm Exam Solutions. The Midterm Exam was given in class on Thursday, October 23, 2008.

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

CS5620 Intro to Computer Graphics

Lets assume each object has a defined colour. Hence our illumination model is looks unrealistic.

Raytracing. COSC 4328/5327 Scott A. King

CS 4620 Program 3: Pipeline

Distributed Ray Tracing

CS 4620 Midterm, March 21, 2017

CS384G Midterm Examination Spring 2008

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

lecture 19 Shadows - ray tracing - shadow mapping - ambient occlusion Interreflections

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

Ray Tracing. Shandong University

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

lecture 18 - ray tracing - environment mapping - refraction

CS 130 Exam I. Fall 2015

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

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

CS354 Computer Graphics Ray Tracing. Qixing Huang Januray 24th 2017

Programming projects. Assignment 1: Basic ray tracer. Assignment 1: Basic ray tracer. Assignment 1: Basic ray tracer. Assignment 1: Basic ray tracer

Introduction Rasterization Z-buffering Shading. Graphics 2012/2013, 4th quarter. Lecture 09: graphics pipeline (rasterization and shading)

Ray Tracing. Kjetil Babington

Ray tracing Tutorial. Lukas Herzberger

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

CS 4620 Midterm 1. Tuesday 22 October minutes

Introduction to Computer Graphics 7. Shading

CSE 681 Illumination and Phong Shading

Review for Ray-tracing Algorithm and Hardware

CS 130 Final. Fall 2015

Shading. Reading. Pinhole camera. Basic 3D graphics. Brian Curless CSE 557 Fall Required: Shirley, Chapter 10

Accelerating Geometric Queries. Computer Graphics CMU /15-662, Fall 2016

Introduction to Visualization and Computer Graphics

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

Assignment 6: Ray Tracing

CHAPTER 1 Graphics Systems and Models 3

Lecture 11: Ray tracing (cont.)

Practical 2: Ray Tracing

CS 130 Exam I. Fall 2015

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

Shadows in the graphics pipeline

Questions??? Announcements Assignment 3 due today

Illumination Models & Shading

Transcription:

Ray Tracing COMP575/COMP770 1

Ray tracing idea 2

Ray Tracing: Example (from [Whitted80])

Ray Tracing: Example

Ray Tracing for Highly Realistic Images Volkswagen Beetle with correct shadows and (multi-)reflections on curved surfaces

Reasons for Using Ray Tracing Flexible Primitive Types Volume visualization using multiple iso-surfaces

Ray tracing algorithm for each pixel { compute viewing ray intersect ray with scene compute illumination at visible point put result into image } 7

Generating eye rays Use window analogy directly 8

Generating eye rays ORTHOGRAPHIC PERSPECTIVE 9

Vector math review Vectors and points Vector operations addition scalar product More products dot product cross product Bases and orthogonality 10

Generating eye rays orthographic Just need to compute the view plane point s: but where exactly is the view rectangle? 11

Generating eye rays orthographic 12

Generating eye rays perspective View rectangle needs to be away from viewpoint Distance is important: focal length of camera still use camera frame but position view rect away from viewpoint ray origin always e ray direction now controlled by s 13

Generating eye rays perspective Compute s in the same way; just subtract dw coordinates of s are (u, v, d) 14

Pixel-to-image mapping One last detail: (u, v) coords of a pixel j j = 2.5 i j =.5 i =.5 i = 3.5 15

Ray intersection 16

Ray: a half line Standard representation: point p and direction d this is a parametric equation for the line lets us directly generate the points on the line if we restrict to t > 0 then we have a ray note replacing d with ad doesn t change ray (a > 0) 17

Ray-sphere intersection: algebraic Condition 1: point is on ray Condition 2: point is on sphere assume unit sphere; see Shirley or notes for general Substitute: this is a quadratic equation in t 18

Ray-sphere intersection: algebraic Solution for t by quadratic formula: simpler form holds when d is a unit vector but we won t assume this in practice (reason later) I ll use the unit-vector form to make the geometric interpretation 19

Ray-sphere intersection: geometric 20

Ray-box intersection Could intersect with 6 faces individually Better way: box is the intersection of 3 slabs 21

Ray-slab intersection 2D example 3D is the same! 22

Intersecting intersections Each intersection is an interval Want last entry point and first exit point Shirley fig. 10.16 23

Ray-triangle intersection Condition 1: point is on ray Condition 2: point is on plane Condition 3: point is on the inside of all three edges First solve 1&2 (ray plane intersection) substitute and solve for t: 24

Ray-triangle intersection In plane, triangle is the intersection of 3 half spaces 25

Inside-edge test Need outside vs. inside Reduce to clockwise vs. counterclockwise vector of edge to vector to x Use cross product to decide 26

Ray-triangle intersection 27

Ray-triangle intersection See book for a more efficient method based on linear systems (don t need this for Ray 1 anyhow but stash away for Ray 2) 28

Image so far With eye ray generation and sphere intersection Surface s = new Sphere((0.0, 0.0, 0.0), 1.0); for 0 <= iy < ny for 0 <= ix < nx { ray = camera.getray(ix, iy); hitsurface, t = s.intersect(ray, 0, +inf) if hitsurface is not null image.set(ix, iy, white); } 29

Intersection against many shapes Group.intersect (ray, tmin, tmax) { tbest = +inf; firstsurface = null; for surface in surfacelist { hitsurface, t = surface.intersect(ray, tmin, tbest); if hitsurface is not null { tbest = t; firstsurface = hitsurface; } } return hitsurface, tbest; } 30

Image so far With eye ray generation and scene intersection for 0 <= iy < ny for 0 <= ix < nx { ray = camera.getray(ix, iy); c = scene.trace(ray, 0, +inf); image.set(ix, iy, c); } Scene.trace(ray, tmin, tmax) { surface, t = surfs.intersect(ray, tmin, tmax); if (surface!= null) return surface.color(); else return black; } 31

Shading Compute light reflected toward camera Inputs: eye direction light direction (for each of many lights) surface normal surface parameters (color, shininess, ) 32

Diffuse reflection Top face of cube receives a certain amount of light Top face of 60º rotated cube intercepts half the light In general, light per unit area is proportional to cos θ = l n 33

Lambertian shading illumination from source diffusely reflected light diffuse coefficient 34

Lambertian shading Produces matte appearance [Foley et al.] 35

Diffuse shading 36

Image so far Scene.trace(Ray ray, tmin, tmax) { surface, t = hit(ray, tmin, tmax); if surface is not null { point = ray.evaluate(t); normal = surface.getnormal(point); return surface.shade(ray, point," normal, light); } else return backgroundcolor; } Surface.shade(ray, point, normal, light) { v = normalize(ray.direction); l = normalize(light.pos point); // compute shading } 37

Shadows Surface is only illuminated if nothing blocks its view of the light. With ray tracing it s easy to check just intersect a ray with the scene! 38

Image so far Surface.shade(ray, point, normal, light) { shadray = (point, light.pos point); if (shadray not blocked) { v = normalize(ray.direction); l = normalize(light.pos point); // compute shading } return black; } 39

Shadow rounding errors Don t fall victim to one of the classic blunders: What s going on? hint: at what t does the shadow ray intersect the surface you re shading? 40

Shadow rounding errors Solution: shadow rays start a tiny distance from the surface Do this by moving the start point, or by limiting the t range 41

Multiple lights Important to fill in black shadows Just loop over lights, add contributions Ambient shading black shadows are not really right one solution: dim light at camera alternative: add a constant ambient color to the shading 42

Image so far shade(ray, point, normal, lights) { result = ambient; for light in lights { if (shadow ray not blocked) { result += shading contribution; } } return result; } 43

Specular shading (Blinn-Phong) Intensity depends on view direction bright near mirror configuration 44

Specular shading (Blinn-Phong) Close to mirror half vector near normal Measure near by dot product of unit vectors 3 specularly reflected light specular coefficient 45

Phong model plots Increasing n narrows the lobe [Foley et al.] 46

Specular shading [Foley et al.] 47

Diffuse + Phong shading 48

Ambient shading Shading that does not depend on anything add constant color to account for disregarded illumination and fill in black shadows ambient coefficient reflected ambient light 49

Putting it together Usually include ambient, diffuse, Phong in one model The final result is the sum over many lights 50

Mirror reflection Consider perfectly shiny surface there isn t a highlight instead there s a reflection of other objects Can render this using recursive ray tracing to find out mirror reflection color, ask what color is seen from surface point in reflection direction already computing reflection direction for Phong Glazed material has mirror reflection and diffuse where L m is evaluated by tracing a new ray 51

Mirror reflection Intensity depends on view direction reflects incident light from mirror direction 3 52

Diffuse + mirror reflection (glazed) (glazed material on floor) 53

Ray tracer architecture 101 You want a class called Ray point and direction; evaluate(t) possible: tmin, tmax Some things can be intersected with rays individual surfaces groups of surfaces (acceleration goes here) the whole scene make these all subclasses of Surface limit the range of valid t values (e.g. shadow rays) Once you have the visible intersection, compute the color may want to separate shading code from geometry separate class: Material (each Surface holds a reference to one) its job is to compute the color 54

Architectural practicalities Return values surface intersection tends to want to return multiple values t, surface or shader, normal vector, maybe surface point in many programming languages (e.g. Java) this is a pain typical solution: an intersection record a class with fields for all these things keep track of the intersection record for the closest intersection be careful of accidental aliasing (which is very easy if you re new to Java) Efficiency what objects are created for every ray? try to find a place for them where you can reuse them. Shadow rays can be cheaper (any intersection will do, don t need closest) but: First Get it Right, Then Make it Fast 55