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

Similar documents
3D Rendering and Ray Casting

Ray Tracing Part 2. CSC418/2504 Introduction to Computer Graphics. TA: Muhammed Anwar

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

3D Rendering and Ray Casting

Assignment 6: Ray Tracing

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

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

INFOGR Computer Graphics

Computer Graphics Tick 1

CS 130 Final. Fall 2015

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

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

Ray Tracing. CPSC 453 Fall 2018 Sonny Chan

Assignment 2 Ray Tracing

Lighting and Shading

Intro to Ray-Tracing & Ray-Surface Acceleration

Photorealism: Ray Tracing

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

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

Computer Graphics and Image Processing Ray Tracing I

Raytracing CS148 AS3. Due :59pm PDT

Ray tracing Tutorial. Lukas Herzberger

Topics and things to know about them:

Ray Tracer Due date: April 27, 2011

Lecture 11. More Ray Casting/Tracing

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

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

Shadows. COMP 575/770 Spring 2013

Computer Graphics. Lecture 02 Graphics Pipeline. Edirlei Soares de Lima.

CPSC GLOBAL ILLUMINATION

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

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

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

Parallelization. Memory coherency helps when distributing rays to various threads/processors

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

CS Computer Graphics: Introduction to Ray Tracing

CS Computer Graphics: Introduction to Ray Tracing

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

1999, Denis Zorin. Ray tracing

Computer Graphics Tick 2

Interactive Real-Time Raycasting

COMPLETION OF Z-buffer Graphics Pipeline

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

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

COMP371 COMPUTER GRAPHICS

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

Lecture 15: Shading-I. CITS3003 Graphics & Animation

Supplement to Lecture 16

EDAN30 Photorealistic Computer Graphics. Seminar 1, Whitted Ray Tracing (And then some!) Magnus Andersson, PhD student

CS 130 Exam I. Fall 2015

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

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

Homework #2. Hidden Surfaces, Projections, Shading and Texture, Ray Tracing, and Parametric Curves

The University of Calgary

Ray-Tracing. Misha Kazhdan

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

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]

CS 4620 Midterm, March 21, 2017

Ray Tracing. Kjetil Babington

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

DH2323 DGI13. Lab 2 Raytracing

Ray Tracing. Outline. Ray Tracing: History

CS Simple Raytracer for students new to Rendering

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

Ray tracing. EECS 487 March 19,

Pipeline Operations. CS 4620 Lecture 14

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

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

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

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

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

Computer Graphics Ray Casting. Matthias Teschner

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

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

Ray Tracing. Shandong University

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

Today. Rendering algorithms. Rendering algorithms. Images. Images. Rendering Algorithms. Course overview Organization Introduction to ray tracing

Lecture 18: Primer on Ray Tracing Techniques

Hidden Surface Elimination Raytracing. Pre-lecture business. Outline for today. Review Quiz. Image-Space vs. Object-Space

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

CS Computer Graphics: Ray Tracing Detail, Part 3

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

THE AUSTRALIAN NATIONAL UNIVERSITY Final Examinations(Semester 2) COMP4610/COMP6461 (Computer Graphics) Final Exam

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

A Little Background. Motivation. Motivation

CS 4204 Computer Graphics

Movie: For The Birds. Announcements. Ray Tracing 1. Programming 2 Recap. Programming 3 Info Test data for part 1 (Lines) is available

Lecture 11: Ray tracing (cont.)

Sung-Eui Yoon ( 윤성의 )

To Shading and Beyond. CS 6965 Fall 2011

Distributed Ray Tracing

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

Computer Graphics 1. Chapter 7 (June 17th, 2010, 2-4pm): Shading and rendering. LMU München Medieninformatik Andreas Butz Computergraphik 1 SS2010

Today. Rendering algorithms. Rendering algorithms. Images. Images. Rendering Algorithms. Course overview Organization Introduction to ray tracing

The Traditional Graphics Pipeline

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

CMSC427 Final Practice v2 Fall 2017

Raycast Rendering Maya 2013

TDA361/DIT220 Computer Graphics, January 15 th 2016

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

Transcription:

Ray Tracing Part 1 CSC418/2504 Introduction to Computer Graphics TA: Muhammed Anwar & Kevin Gibson Email: manwar@cs.toronto.edu

Overview Introduction / Motivation Rasterization vs Ray Tracing Basic Pseudocode Camera and Ray Casting Calculating Intersections Shading (Lighting, Shadows, Reflections) Assignment Examples

Ray Tracing Let s us create beautiful images by simulating how light travels through a scene Image generated at https://benedikt-bitterli.me/tantalum/tantalum.html

Drawing a Scene

Ray Tracing - Overview for each pixel in image: - compute and construct viewing ray - find the 1st hit object by the ray and compute an intersection - set pixel colour from the intersection

Shooting a Ray Suppose we have a camera at the origin, looking down the z-axis. We set an image plane a distance f away, and limit our view to a certain width and height. We slice up this image plane into pixelsized squares Shoot a ray from the origin through each square, collect color from whatever it hits.

Shooting a Ray In camera coordinates, if pixel coordinates are d = u, v, f, then the ray we shoot is a line of the form r t = 0 + t d For simplicity later on, we usually convert this to world coordinates by multiplying by our constructed basis. M cw = u x v x view x eye x u y v y view y eye y u z v z view z eye z 0 0 0 1

Ray Casting Pseudo-Code for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { // Pixel in Camera Coordinates Point3D origin(0, 0, 0); Point3D imageplane; imageplane[0] = (-width/2 + i + 0.5) imageplane[1] = (-height/2 + j + 0.5) imageplane[2] = -1; //Ray Direction Vector3D direction = imageplane - origin; //Convert to world-space direction = viewtoworld * direction; origin = viewtoworld * origin; Ray3D ray = Ray3D(origin, direction); } } pixelcolour = cast_ray(ray)

I Shot a Ray, Now What? Intersections! A ray shot into the scene can intersect with objects. An intersection is made up of the following elements: struct Intersection { // 3D Location of intersection. Point3D point; // Normal vector at the intersection. Vector3D normal; // Material at the intersection. Material* mat; // The t value in r(t) = O + td along the ray where intersection happened double t_value; // Set to true when no intersection has occured. bool none; };

Calculating Intersections Intersection in World Coordinates Intersection in Model Coordinates Difficult to do intersections with arbitrary objects in world space. Do intersections in Model Space (inverse of World to Model), and transform the result back to world space. M r t = M 0 + t d = M0 + tm d O + t d the ray in object coordinates Focus on unit primitives, such as unit planes, spheres, cylinders etc.

Ray Plane Intersection Intersection of Ray with x-y Plane (z=0) centered at 0. Can find t of the ray at the intersection, if one exists. 2 Cases: What if t<0? Behind camera What if d z = 0? Ray doesn t intersect plane (parallel to it) Equation of ray: r t = O + t d Equation of Plane n p p 0 = 0 Notice: p 0 is 0 and n = 0,0,1,0 Intersection Point: t = O z d z

Ray Unit Plane Intersection The previous result will return an intersection along an infinite x-y plane. What if we want to bound it to a unit plane (i.e x 0.5, 0.5 y 0.5,0.5 Simple. Find the 3D intersection point, and make sure its within the range. If not, no intersection occurred. p=(1.2,-0.25,0) Out of bounds, NO Intersection p=(-0.25,-0.25,0) Within bounds, Intersection

Ray Unit Plane Intersection Pseudocode bool intersect(ray, worldtomodel,modeltoworld) { //Transform the ray (origin, direction) to object space origin = worldtomodel * ray.origin; direction = worldtomodel * ray.dir; double t = -origin[2] / direction[2]; //invalid intersection if (t < 0 direction[2] ==0){ return false; } Point3D p = origin + t * direction; Vector3D normal = Vector3D(0,0,1); if (p[0] >= -0.5 && p[0] <= 0.5 && p[1] >= -0.5 && p[1] <= 0.5) { ray.intersection.t_value = t; ray.intersection.point = modeltoworld * p; ray.intersection.normal = TransformNormal(worldToModel, normal) return true; } } return false;

Wait, How do you Transform Normals? Unit Circle Incorrect Normals Correct Normals Can t just apply the same transformation to convert normals from model to world space here is the dot-product, not cross-product. Therefore, to transform the normal correctly, we need to the Inverse Transpose of the model to world matrix.

Ray Shading Okay, so we know how to cast a ray, calculate intersections. Now we need to color our pixels! We have the information we need to calculate Phong Illumination at the intersection point.

Phong Illumination Model k a I a + k d max 0, N L I d + k s max 0, V R α I s I a, I d, I s are properties of the light R = 2 L N N L Note: Normalize these vectors before doing calculations Note: The viewing direction here is the direction of the ray (specifically the ve of the ray direction).

Global Specular Illumination Up until now, our ray tracer would have produced the same images as a rasterizing renderer (OpenGL) With ray tracing, we can easily extend it to include more global illumination properties (e.g Reflections). Just cast another ray from the intersection.

Reflections One Reflection Two Reflections No Reflection

Shadows Even shadows are easy in ray tracers. How do we know if a light reaches a point? Use a ray! If a ray from our intersection point reaches the light before intersecting any other objects, then add the contribution of the light to the color Otherwise, the object is shadowed by an object

Pseudocode of Ray Shading Color shaderay(ray, depth) { findintersections(ray); Colour color(0, 0, 0); if (!ray.intersection.none) { for (light in scene) { shadowray = create ray from intersection to light; findintersections(shadowray); if (shadowray.intersection.none) { color += phongillumination(light, ray); } } } if (depth > 0) { reflectray = create a reflected ray at the intersection; color += shaderay(reflectray, --depth); } } return color;

Assignment 3/4 Should have enough knowledge now to get a good start on A3. Tips: Test render small resolutions first, cause raytracing takes a while! Have a solid understanding of the math behind intersections, debugging them can be cumbersome at times Next week, will go over more advanced ray tracing

Past A3 Submissions