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

Similar documents
Ray tracing Tutorial. Lukas Herzberger

Photorealism: Ray Tracing

Assignment 6: Ray Tracing

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

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

Lecture 11: Ray tracing (cont.)

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

Lecture 10: Ray tracing

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

A Little Background. Motivation. Motivation

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

Deferred Rendering Due: Wednesday November 15 at 10pm

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

CPSC GLOBAL ILLUMINATION

Ray Tracing COMP575/COMP770

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

Lighting and Shading

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

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

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

Intro to Ray-Tracing & Ray-Surface Acceleration

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

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

Ray Tracing. CPSC 453 Fall 2018 Sonny Chan

Introduction to Ray-tracing Objectives

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

Photorealism. Photorealism: Ray Tracing. Ray Tracing

CENG 477 Introduction to Computer Graphics. Ray Tracing: Shading

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

Assignment 2 Ray Tracing

Ray-Tracing. Misha Kazhdan

Photorealistic 3D Rendering for VW in Mobile Devices

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

Raytracing. COSC 4328/5327 Scott A. King

Shadow Algorithms. CSE 781 Winter Han-Wei Shen

03 RENDERING PART TWO

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

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

Graphics for VEs. Ruth Aylett

CS 4620 Midterm, March 21, 2017

Review for Ray-tracing Algorithm and Hardware

Ray Tracing. Kjetil Babington

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

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

Computer Graphics Tick 2

Transformations in Ray Tracing. MIT EECS 6.837, Durand and Cutler

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

Textures and normals in ray tracing

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

Ray Tracing CSCI 4239/5239 Advanced Computer Graphics Spring 2018

Introduction to Computer Graphics. Ray Tracing Review

Metal for Ray Tracing Acceleration

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

Shading, Advanced Rendering. Week 7, Wed Feb 28

Global Illumination. COMP 575/770 Spring 2013

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

CS Computer Graphics: Introduction to Ray Tracing

CS Computer Graphics: Introduction to Ray Tracing

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

CS 488. More Shading and Illumination. Luc RENAMBOT

Lecture 11. More Ray Casting/Tracing

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

Shadows. COMP 575/770 Spring 2013

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

CS5620 Intro to Computer Graphics

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

COMPUTER GRAPHICS AND INTERACTION

Today. Anti-aliasing Surface Parametrization Soft Shadows Global Illumination. Exercise 2. Path Tracing Radiosity

Ray Tracing. Outline. Ray Tracing: History

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

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

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

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

Topics and things to know about them:

Lecture 18: Primer on Ray Tracing Techniques

Raytracing CS148 AS3. Due :59pm PDT

lecture 18 - ray tracing - environment mapping - refraction

Computer Graphics and Image Processing Ray Tracing I

Ray Tracer Due date: April 27, 2011

Homework #2. Shading, Ray Tracing, and Texture Mapping

SUMMARY. CS380: Introduction to Computer Graphics Ray tracing Chapter 20. Min H. Kim KAIST School of Computing 18/05/29. Modeling

CS 184: Assignment 4 Simple Raytracer

Indirect Illumination

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

Recall: Basic Ray Tracer

CS Simple Raytracer for students new to Rendering

Photorealism. Ray Tracing Texture Mapping Radiosity

Computer Graphics Tick 1

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

CS384G Midterm Examination Spring 2008

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

Ray Tracing Foley & Van Dam, Chapters 15 and 16

Last week. Machiraju/Zhang/Möller

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

CS 465 Program 5: Ray II

Computer Graphics. - Introduction to Ray Tracing - Philipp Slusallek

Practical 2: Ray Tracing

Viewing and Ray Tracing. CS 4620 Lecture 4

The Rasterization Pipeline

Introduction to Visualization and Computer Graphics

Transcription:

Magdalena(Schwarzl 1

Agenda Ray(tracing(algorithm( Code(structure( Ray(intersec;ons Sphere Triangle Hints Transforma;ons Debugging How(to(start Magdalena(Schwarzl 2

Basic algortihm For each pixel: 1. Construct ray 2. Test intersection with objects Nearest intersection point visible on image 3. Perform Shading 2

Components Scene: Objects, lights, viewpoint, materials,... xml scene format, see course website Camera: For ray construction Image: 2D Array of Vec3's (for r,g,b), represents pixels Rays: For intersection tests Shading: Illumination models 3

Ray Consists of origin + direction (both Vec3) dir Normalize direction! o Every point p on ray = o+ λ*dir Object Needs intersection routine, returning λ, normal, etc. Additional: Parameters for material properties,... For this lab: Spheres and triangle meshes Scene Arrange objects for easy intersection (for example in a list) 4

Implementation List<SceneObjects> objectlist for (y=0; y<width; y++) iterate over all pixels for (x=0; x<height; x++) ray = camera.constructrayforpixel(x,y) color = trace(ray,objectlist) image.setcolor(x,y,color) 5

Implementation List<SceneObjects> objectlist List<SceneObjects> objectlist for (y=0; y<width; y++) for (y=0; y<width; y++) for (x=0; x<height; x++) for (x=0; x<height; x++) ray = camera.constructrayforpixel(x,y) ray = camera.constructrayforpixel(x,y) color = trace(ray,objectlist) color = trace(ray,objectlist) image.setcolor(x,y,color) image.setcolor(x,y,color) trace(ray,objectlist) for(s=0; s < objectlist.size(); s++) object = objectlist.at(s) result = object.intersect(ray) //determine smallest result.t > 0! if (no intersection) return backgroundcolor else return result.color 6

So far: 7

Shading Extend trace method to use local illumination models: trace(ray,objectlist) for(s=0; s < objectlist.size(); s++) object = objectlist.at(s) result = object.intersect(ray) //determine smallest result.t > 0! if (no intersection) return backgroundcolor else //determine intersection point Vec3 ip = ray.origin + result.t*ray.direction Vec3 normal = result.normal Vec3 light Vec3 color = shade(ray, object, ip, normal, light) return color 8

Shading More than one light source: trace(ray,objectlist) for(s=0; s < objectlist.size(); s++) object = objectlist.at(s) result = object.intersect(ray) //determine smallest result.t > 0! if (no intersection) return backgroundcolor else //determine intersection point Vec3 ip = ray.origin + result.t*ray.direction Vec3 normal = result.normal Vec3 overallcolor; for (l = 0; l < lightsinscene; l++) Vec3 light overallcolor += shade(ray, object, ip, normal, light) return overallcolor 9

Shadows Point is in shadow if not directly illuminated by light Test by creating shadow ray from intersection point to light source Intersect with all objects again if (intersection in front of light) return darkcolor else //perform shading as before 10

So far, only direct illumination: 11

So far, only direct illumination: VS Recursion needed! 12

Recursion For every intersection point: Create new rays for reflection/refraction Trace those rays! Stop recursion after reaching max. bounces 13

Recursion trace(ray,objectlist, depth) //perform intersection and shading as before... if depth >= maxbounces return overallcolor stop after max bounces //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) return finalcolor = //combine colors 14

Combine colors Coefficients for reflectance, transmittance are defined in scene file Reflectance + Transmittance + own Color = 1 finalcolor = r*reflectedcolor + t*transmittedcolor + (1-r-t)*ownColor 15

Agenda Ray(tracing(algorithm( Code(structure( Ray(intersec;ons Sphere Triangle Hints Transforma;ons Debugging How(to(start Magdalena(Schwarzl 3

Ray(intersec;on A(ray(is(defined(as X = P + λ! d! d P Where(X(is(any(point(on(the(line( Magdalena(Schwarzl 4

Sphere A(sphere(is(defined(as r 2 = ( X C) 2 C r Where X is any point on the sphere Magdalena(Schwarzl 5

Intersect Ray-Sphere We(want(to(find(a(point(on(both! d r 2 = ( X C) 2 X = P + λ! d S 1 Compute lambda C r 2 = ((P + λ d) C! ) 2 P S 2 r r 2 = ((P + λ d) C! )((P + λ d) C! ) Magdalena(Schwarzl 6

Intersect Ray-Sphere r 2 = ((P + λ d) C! )((P + λ d) C! ) 0 = d 2 λ 2 + λ ( 2P d! 2C d! ) + ( P C) 2 r 2 A = d 2 B = ( 2P d! 2C d! ) C = ( P C) 2 r 2 λ 1,2 = B ± B2 4AC 2A Magdalena(Schwarzl 7

Intersect Ray-Sphere λ 1,2 = B ± B2 4AC 2A Magdalena(Schwarzl 8

Intersect Ray-Sphere λ 1,2 = B ± B2 4AC 2A <(0( no(intersec;on( =(0( tangent( >(0( two(intersec;on(points(! d S 1! d P r C P! d S 1 r C P S 2 r C Magdalena(Schwarzl 9

Barycentric coordinates V 2 A(triangle(is(defined(as e 12 V 1 e 23 e 13 V 3 Where X is any point inside the triangle Magdalena(Schwarzl 10

Barycentric coordinates V 2 A(triangle(is(defined(as 1 u v = A 1 e 12 u = A 2 A 1 + A 2 + A 3 A 1 + A 2 + A 3 V 1 A 3 A 2 X A 1 e 23 v = A 3 A 1 + A 2 + A 3 e 13 V 3 Where X is any point inside the triangle Magdalena(Schwarzl 11

Barycentric coordinates V 2 A(triangle(is(defined(as 1 u v = A 1 e 12 u = A 2 A 1 + A 2 + A 3 A 1 + A 2 + A 3 V 1 A 3 A 2 X A 1 e 23 v = A 3 A 1 + A 2 + A 3 e 13 X ( u, v) = ( 1 u v)v 1 + uv 2 + vv 3 u, v 0 V 3 Where X is any point inside the triangle u + v 1 Magdalena(Schwarzl 12

Triangle A triangle is defined by: X ( u, v) = ( 1 u v)v 1 + uv 2 + vv 3 u, v 0 u + v 1 V 1 e 12 V 2 e 13 e 23 V 3 3 points define a plane: Magdalena(Schwarzl 13

Triangle A triangle is defined by: X ( u, v) = ( 1 u v)v 1 + uv 2 + vv 3 u, v 0 u + v 1 V 1 e 12 V 2 e 13 e 23 V 3 3 points define a plane: n = e 13 e 12 e 13 e 12 nx = nv 1 Magdalena(Schwarzl 14

Intersect Ray-Triangle We(want(the(intersec;on ( ) = 1 u v X u, v ( )V 1 + uv 2 + vv 3 V 1 e 12 S 1 V 2 e 23 nx = nv 1 X = P + λ! d! d e 13 Compute lambda P V 3 n( P + λ d! ) = nv 1 Magdalena(Schwarzl 15

Intersect Triangle-Sphere 1) ray-plane λ = nv 1 np n! d Magdalena(Schwarzl 16

Intersect Triangle-Sphere 1) ray-plane λ = nv 1 np n! d!= 0 One intersection = 0 No intersection with plane S 1 S 1 = P + λ! d parallel Inside plane Magdalena(Schwarzl 17

Intersect Ray-Triangle 2) Inside triangle? P + λ d! = ( 1 u v)v 1 + uv 2 + vv 3 Use x,y,z to get linear system of 3 equations Solve for v & u Magdalena(Schwarzl 18

Intersect Ray-Triangle 2) Inside triangle? P + λ d! = ( 1 u v)v 1 + uv 2 + vv 3 Use x,y,z to get linear system of 3 equations Solve for v & u u,v <=1 AND u,v >=0 intersection u,v > 1 OR u,v < 0 no intersection Magdalena(Schwarzl 19

Agenda Ray(tracing(algorithm( Code(structure( Ray(intersec;ons Sphere Triangle Hints Transforma;ons Debugging How(to(start Magdalena(Schwarzl 20

Transformations Think about transformations early! Magdalena(Schwarzl 21

Transformations Think about transformations early! Two approaches: transform object inverse transform ray Precompute inv.-transfomations No translation on vectors Inverse-transpose for normals Magdalena(Schwarzl 22

Precision Problems? Magdalena(Schwarzl 23

Precision Problems? Shadow ray hit its source (collision at distance ==0) Offset the ray cast source a small amount in the direction of the ray. Do never test for == 0 Test for between 0 ± ε Magdalena(Schwarzl 24

Normals, Texures Visual debugging Output textures, normals, reflection vectors as color to see problems 0 ±ε Magdalena(Schwarzl 25

Agenda Ray(tracing(algorithm( Code(structure( Ray(intersec;ons Sphere Triangle Hints Transforma;ons Debugging How(to(start Magdalena(Schwarzl 26

How to start Plan code structure Classes, methods, Decide on libraries xml-parsing, images Error messages!! Create a black image Read in xml scene Compute intersections Use only object color Compute shading ambient, diffuse, specular Test on PC labs Include readme!! compile command If it might take longer ;) Magdalena(Schwarzl 27

Questions Any questions? Magdalena(Schwarzl 28