Ray tracing Tutorial. Lukas Herzberger

Similar documents
Agenda. Ray(tracing(algorithm( Code(structure( Ray(intersec;ons Sphere Triangle Hints Transforma;ons Debugging How(to(start

Photorealism: Ray Tracing

Raytracing CS148 AS3. Due :59pm PDT

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

Intro to Ray-Tracing & Ray-Surface Acceleration

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

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

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

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

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

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

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

Lighting and Shading

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

Lecture 18: Primer on Ray Tracing Techniques

Raytracing. COSC 4328/5327 Scott A. King

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

Viewing and Ray Tracing

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

Ray Tracer Due date: April 27, 2011

Ray Tracing COMP575/COMP770

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

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

A Little Background. Motivation. Motivation

Viewing and Ray Tracing. CS 4620 Lecture 4

COMPUTER GRAPHICS AND INTERACTION

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

Introduction to Ray-tracing Objectives

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

INFOGR Computer Graphics. J. Bikker - April-July Lecture 10: Ground Truth. Welcome!

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

Assignment 6: Ray Tracing

Ray-Tracing. Misha Kazhdan

Ray Tracing. Last Time? Today. Ray Casting. Durer s Ray Casting Machine. Reading for Today

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

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

Questions??? Announcements Assignment 3 due today

RAYTRACING. Christopher Peters INTRODUCTION TO COMPUTER GRAPHICS AND INTERACTION. HPCViz, KTH Royal Institute of Technology, Sweden

Ray Tracing. Brian Curless CSEP 557 Fall 2016

Topics and things to know about them:

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

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

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

Computer Graphics Tick 2

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

Pipeline Operations. CS 4620 Lecture 14

Raycast Rendering Maya 2013

Lecture 11: Ray tracing (cont.)

COMP371 COMPUTER GRAPHICS

CS 488. More Shading and Illumination. Luc RENAMBOT

CPSC GLOBAL ILLUMINATION

Sung-Eui Yoon ( 윤성의 )

CS-184: Computer Graphics. Administrative

Ray Casting. Outline in Code. Outline. Finding Ray Direction. Heckbert s Business Card Ray Tracer. Foundations of Computer Graphics (Fall 2012)

03 RENDERING PART TWO

LIGHTING AND SHADING

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

Pipeline Operations. CS 4620 Lecture 10

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

Computer Graphics. Lecture 14 Bump-mapping, Global Illumination (1)

Indirect Illumination

Interactive Real-Time Raycasting

CS 130 Exam I. Fall 2015

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

Shading, Advanced Rendering. Week 7, Wed Feb 28

Ray Tracing. Kjetil Babington

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

Ray-tracing Cont. Ray-tracing

CS Computer Graphics: Introduction to Ray Tracing

CS Computer Graphics: Introduction to Ray Tracing

Ray Tracing. CPSC 453 Fall 2018 Sonny Chan

CS5620 Intro to Computer Graphics

Indirect Illumination

Assignment 2 Ray Tracing

Shading. Brian Curless CSE 557 Autumn 2017

CS452/552; EE465/505. Intro to Lighting

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

Ray Tracing. Quiz Discussion. Announcements: Final Projects. Last Time? Durer s Ray Casting Machine. Today

Shadows. COMP 575/770 Spring 2013

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

Comp 410/510 Computer Graphics. Spring Shading

The University of Calgary

Lecture 10: Ray tracing

Ray Tracer. Spring 2017 Help Session

Homework 3: Shading, Raytracing, and Image Processing

Global Illumination. COMP 575/770 Spring 2013

Geometric optics. The University of Texas at Austin CS384G Computer Graphics Don Fussell

COMP 4801 Final Year Project. Ray Tracing for Computer Graphics. Final Project Report FYP Runjing Liu. Advised by. Dr. L.Y.

Graphics 2009/2010, period 1. Lecture 8: ray tracing

CMSC427 Final Practice v2 Fall 2017

Project 1 Simple Ray Tracer

Ray Tracing. Announcements: Quiz. Last Time? Today. Durer s Ray Casting Machine. Ray Casting

Interpolation using scanline algorithm

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

Ray Casting. To Do. Outline. Outline in Code. Foundations of Computer Graphics (Spring 2012) Heckbert s Business Card Ray Tracer

Computer Graphics Tick 1

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

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

Practical 2: Ray Tracing

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

Transcription:

Ray tracing Tutorial Lukas Herzberger

Agenda Ray tracing algorithm (lab 4a) Intersection tests Ray tracing algorithm (lab 4b) Hints & common mistakes

Agenda Ray tracing algorithm (lab 4a) Intersection tests Ray tracing algorithm (lab 4b) Hints & common mistakes

Ray tracing algorithm For each pixel on image: Construct camera ray Find first object hit by ray and its surface normal Set pixel color to value computed from hit point, light and normal

Useful data structures Scene: holds our geometry, camera, light sources Ray: origin + direction (vec3 / vec4) SceneObject: geometry, material, transform implementint an intersection function (could also be in an Intersection class if you want to separate data and functionality) IntersectionRecord: containing information about our intersection tests, like - t distance between ray s origin and intersection point - normal the surface normal at the intersection point - object the object that was hit

Ray tracing algorithm List<SceneObject> objectlist for (y=0; y < image.height; ++y) for (x=0; x < image.width; ++x) ray = camera.constructeyeray(x,y) color = trace(ray, objectlist) image.setcolor(x,y,color)

Constructing camera rays Ray: origin & direction Camera/Eye/Viewing ray: origin = camera s position ray-direction =? For pixel (x,y) find point p on image plane ray-direction = normalize( p - camera.position )

Constructing camera rays Some hints: field of view(fov) is in degrees but most math libraries use radians! Find camera s base vectors: - viewing direction = lookat - position - right = viewing direction X scene.up -!!!up = right X viewing direction Find width/height of our image plane using fov: tan(alpha) = opposite / adjacent opposite = adjacent * tan(alpha)

Ray tracing algorithm List<SceneObject> objectlist for (y=0; y < image.height; ++y) for (x=0; x < image.width; ++x) ray = camera.constructeyeray(x,y) color = trace(ray, objectlist) image.setcolor(x,y,color)

Tracing a ray Find closest intersection Determine color of our intersection point

Tracing a ray trace(ray,objectlist) for(sceneobject object in objectlist) result = object.intersect(ray) //determine smallest result.t > 0! if (no intersection) return backgroundcolor else return result.color

What this will give us:

Adding illumination For each intersection: find exact point & normal use normal, object s material and light direction to shade point using a local illumination model (e.g. Phong, Blinn-Phong, Cook-Torrance, etc.)

Adding illumination trace(ray,objectlist) for(sceneobject object in objectlist) result = object.intersect(ray) //determine smallest result.t > 0! if (no intersection) return backgroundcolor else //determine intersection point Vec4 ip = ray.origin + result.t*ray.direction Vec4 normal = result.normal Vec4 color = shade(ray,object,ip,normal,light) return color

Multiple light sources else //determine intersection point Vec4 ip = ray.origin + result.t*ray.direction Vec4 normal = result.normal Vec4 color; for (LightSource light in lightsources) color += shade(ray,object,ip,normal,light) return color

Shadows For each light source: cast Shadow ray from intersection point to light source if ray hits anything between intersection point and light source the point is not affected by this light source directly -> ignore this light source!

What this will give us:

Agenda Ray tracing algorithm (non-recursive) Intersection tests Ray tracing algorithm (recursive) Hints & common mistakes

Intersection tests A ray is defined as: X = e + t d e origin d direction t > 0 We want to find points that lie on this ray!

Intersection tests: Sphere A sphere is defined as: In vector form: When we plug in our ray we get:

Intersection tests: Sphere Ray plugged into our sphere equation: After rearranging the terms: We can now see that this is a very simple problem:

Intersection tests: Sphere Our problem: in the form of: When we solve after t we get:

Intersection tests: Sphere When we look at our equation once again, we can see that we can still optimize some things: Calculating square roots is quite expensive Just looking at the discriminant will tell us, if the test will be successful or not: disc. > 0 : two intersections disc. = 0 : one intersection disc. < 0 : no intersection > return false!

Intersection tests: Triangle Having a triangle with a, b and c as its vertices, we can say that an intersection will occur when: But only if β > 0, γ > 0 and β + γ < 1 To solve this and get all three unknowns t, β and γ we ll have to set up a system of equations

Intersection tests: Triangle Our problem: Our system of equations: Rewritten as standard linear equations:

Intersection tests: Triangle Our problem: Solution after Cramer s rule (with A being A s determinant):

Intersection tests: Triangle Let s look at this again with some dummy values and see what Cramer s rule gives us: Linear system with dummy values

Intersection tests: Triangles To make our intersection test cheaper, we have to keep all conditions in mind that have to be fulfilled! t > 0 (and t < t from an earlier intersection test) β > 0 γ > 0 β + γ < 1

Agenda Ray tracing algorithm (non-recursive) Intersection tests Ray tracing algorithm (recursive) Hints & common mistakes

Our Raytracer vs recursive Raytracer

What do we need? Recursion! For every intersection point: Create reflected AND refracted rays! Recursively trace those rays! Stop recursion after max. bounces!

Tracing those rays trace(ray,objectlist, depth) //perform intersection and shading as before... if depth >= maxbounces return color //depending on object's material properties, cast new rays if (object.transmittance > 0) ray.origin = ip ray.direction = calculatetransmittancedirection() colortrans = trace(ray,objectlist, depth+1) if (object.reflectance > 0) ray.origin = ip ray.direction = calculatereflectancedirection() colorrefl = trace(ray,objectlist, depth+1) finalcolor = r*colorrefl + t*colortrans + (1-r-t)*color return finalcolor

Agenda Ray tracing algorithm (non-recursive) Intersection tests Ray tracing algorithm (recursive) Hints & common mistakes

Hints and common mistakes Normalize your vectors! Rays should not hit their own origin! Translate the origin in the its own direction by a very small number (epsilon) before testing for intersections! There is only one ambient light source in the scene! For all other light sources only calculate the diffuse and specular term! Make use of homogenous coordinates but make sure that you separate vectors(w=0) from points(w=1)! You can t translate a vector!

Hints and common mistakes Don t transform your objects - transform your rays! Use the inverse of your transformation matrix to transform your ray s origin and direction! Don t normalize your ray s direction after that! Use the inverse transpose to transform the normal!

Hints and common mistakes Check out this awesome book: Peter Shirley, Michael Ashikhmin, Steve Marschner, Fundamentals of Computer Graphics, 3rd edition, AK Peters/CRC Press 2009

Questions?