Lecture 11: Recursive Ray Tracer

Slides:



Advertisements
Similar presentations
GR2 Advanced Computer Graphics AGR
Advertisements

13.1 si31_2001 SI31 Advanced Computer Graphics AGR Lecture 13 An Introduction to Ray Tracing.
1 05/10/2014 Computer Graphics Lecture 10 Global Illumination 1: Ray Tracing and Radiosity Taku Komura.
Ray tracing. New Concepts The recursive ray tracing algorithm Generating eye rays Non Real-time rendering.
Week 9 - Friday.  What did we talk about last time?  Area lighting  Environment mapping  Blinn and Newell's method  Sphere mapping  Cubic environmental.
Lecture 14 Illumination II – Global Models
Ray Tracing & Radiosity Dr. Amy H. Zhang. Outline  Ray tracing  Radiosity.
1. What is Lighting? 2 Example 1. Find the cubic polynomial or that passes through the four points and satisfies 1.As a photon Metal Insulator.
Illumination Model & Surface-rendering Method 박 경 와.
Christian Lauterbach COMP 770, 2/11/2009
CS 325 Introduction to Computer Graphics 04 / 09 / 2010 Instructor: Michael Eckmann.
CS 376 Introduction to Computer Graphics 04 / 09 / 2007 Instructor: Michael Eckmann.
Computer Graphics (Fall 2005) COMS 4160, Lecture 21: Ray Tracing
Ray Casting Ray-Surface Intersections Barycentric Coordinates Reflection and Transmission [Shirley, Ch.9] Ray Tracing Handouts Ray Casting Ray-Surface.
1 7M836 Animation & Rendering Global illumination, ray tracing Arjan Kok
CIS 310: Visual Programming, Spring 2006 Western State College 310: Visual Programming Ray Tracing.
Computer Graphics Inf4/MSc Computer Graphics Lecture 11 Texture Mapping.
Ray Tracing Primer Ref: SIGGRAPH HyperGraphHyperGraph.
3D Computer Graphics: Textures. Textures: texels Texture is a way of assigning a diffuse color to a pixel – can be with 1, 2 or 3D- can use maps, interpolation.
COMP 175: Computer Graphics March 24, 2015
Technology and Historical Overview. Introduction to 3d Computer Graphics  3D computer graphics is the science, study, and method of projecting a mathematical.
CS 376 Introduction to Computer Graphics 04 / 11 / 2007 Instructor: Michael Eckmann.
-Global Illumination Techniques
CS 376 Introduction to Computer Graphics 04 / 16 / 2007 Instructor: Michael Eckmann.
Ray Tracing Chapter CAP4730: Computational Structures in Computer Graphics.
Ray Tracing Jian Huang, CS 594, Fall, 2002 This set of slides are used at Ohio State by Prof. Roger Crawfis.
Rendering Overview CSE 3541 Matt Boggus. Rendering Algorithmically generating a 2D image from 3D models Raster graphics.
I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S Andries van Dam, John Alex October 28, 2003 Raytracing 1/42 Raytracing Basics Part 2 of 2.
Graphics Lecture 13: Slide 1 Interactive Computer Graphics Lecture 13: Radiosity - Principles.
Ray Tracer Spring 2008 Help Session. Outline Project Web Resources What do you have to do for this project? Ray Class Isect Class Requirements Tricks.
Ray-tracing.
Ray Tracing Fall, Introduction Simple idea  Forward Mapping  Natural phenomenon infinite number of rays from light source to object to viewer.
CSCE 441: Computer Graphics Ray Tracing
Real-Time Dynamic Shadow Algorithms Evan Closson CSE 528.
Instructor: Mircea Nicolescu Lecture 5 CS 485 / 685 Computer Vision.
RENDERING : Global Illumination
CSE 681 Introduction to Ray Tracing. CSE 681 Ray Tracing Shoot a ray through each pixel; Find first object intersected by ray. Image plane Eye Compute.
David Luebke3/12/2016 Advanced Computer Graphics Lecture 3: More Ray Tracing David Luebke
CS 325 Introduction to Computer Graphics 04 / 07 / 2010 Instructor: Michael Eckmann.
CS552: Computer Graphics Lecture 33: Illumination and Shading.
CS 376 Introduction to Computer Graphics 04 / 13 / 2007 Instructor: Michael Eckmann.
CIS 681 Distributed Ray Tracing. CIS 681 Anti-Aliasing Graphics as signal processing –Scene description: continuous signal –Sample –digital representation.

Basic Ray Tracing CMSC 435/634.
© University of Wisconsin, CS559 Spring 2004
Photorealistic Rendering vs. Interactive 3D Graphics
Ray Tracer Spring 2007 Help Session.
Week 2 - Friday CS361.
Distributed Ray Tracing
Ray Tracing Dr. Scott Schaefer.
3D Graphics Rendering PPT By Ricardo Veguilla.
© University of Wisconsin, CS559 Fall 2004
(c) 2002 University of Wisconsin
Lighting.
CSCE 441 Computer Graphics: Radiosity
Distributed Ray Tracing
Image synthesis using classical optics
Monte Carlo Rendering Central theme is sampling:
CS-378: Game Technology Lecture #4: Texture and Other Maps
CSCE 441: Computer Graphics Ray Tracing
Ray Tracer Spring 2004 Help Session.
GR2 Advanced Computer Graphics AGR
Computer Graphics Material Colours and Lighting
Ray Tracer Spring 2008 Help Session.
Illumination Model 고려대학교 컴퓨터 그래픽스 연구실.
Illumination Model 고려대학교 컴퓨터 그래픽스 연구실.
Introduction to Ray Tracing
Distributed Ray Tracing
Ray Tracer Autumn 2005 Help Session.
Ray Tracer Spring 2006 Help Session.
Presentation transcript:

Lecture 11: Recursive Ray Tracer COMP 175: Computer Graphics April 9, 2018

Note on using Libraries C++ STL Does not always have the same performance. Interface is (mostly) the same, but implementations differ and compilations also differ. Generally very good, but you don’t always know what’s happening under the hood. OpenGL: Same idea… The important thing is that interface is the same.

Summary Simple, non-recursive raytracer P = eyePt for each sample of image Compute d for each object Intersect ray P+td with object Select object with smallest non-negative t-value (visible object) For this object, find object space intersection point Compute normal at that point Transform normal to world space for each light Use world space normal for lighting computations

Lighting Equation Recall that: I is intensity (for both light and the “final color”, which appears on the left side of the equation) O is for object constant k is for light constant fatt is for attenuation f is the amount of specular (how broad/narrow the specular region is) n, l, r, v are normal that represent normal, light direction, reflective ray, and view vector respectively The lighting is summed over all lights in the scene (m lights in the equation) in a linear fashion.

Shadows In the intersect assignment, we did the following things: Created rays Intersected rays with objects in the scene Found the nearest object Identified the intersection point and the normal For the intersection point, solved the lighting equation What about shadows? How would you modify your intersect code to render shadows?

Σ Shadows Review our previous lighting equation: objectIntensityλ = ambient + attenuation ∙ lightIntensityλ ∙ [diffuse + specular] Σ numLights light = 1

Shadows Each light in the scene contributes to the color and intensity of a surface, but If and only if it reaches the object! could be occluded by other objects in scene could be self-occluding Construct a ray from the surface intersection to each light Make sure light is first object intersected if first object intersected is light, count light’s full contribution if first object intersected is not light, do not count (ignore) light’s contribution this method causes hard shadows; soft shadows are harder to compute

Recursive Ray Tracing Example Whitted 1980 Ray traced image with recursive ray tracing: transparency and refractions

Recursive Ray Tracing (1/4) Simulating global lighting effects (Whitted, 1979)

Recursive Ray Tracing Simulating global lighting effects (Whitted, 1979) By recursively casting new rays into scene, we can look for more information Start from point of intersection We’d like to send rays in all directions, but that’s too hard/computationally taxing Send rays in directions likely to contribute most: toward lights (blockers to lights create shadows for those lights) specular bounce off other objects to capture specular inter-object reflections use ambient hack to capture diffuse inter-object reflection through object (transparency/refraction) Shadow Ray Recursive Rays Primary Ray November 4, 2010

Recursive Ray Tracing (2/4) Trace “secondary” rays at intersections: light: trace a ray to each light source. If light source is blocked by opaque an object, it does not contribute to lighting specular reflection: trace reflection ray (i.e. about normal vector at surface intersection) refractive transmission/transparency: trace refraction ray (following Snell’s law) recursively spawn new light, reflection, and refraction rays at each intersection until contribution negligible / max recursion depth reached Limitations recursive inter-object reflection is strictly specular diffuse inter-object reflection is handled differently Oldies-but-goodies Ray Tracing Silent Film, A Long Ray’s Journey into Light (http://www.youtube.com/watch?v=b_UqzLBFz4Y)

Recursive Ray Tracing Your new lighting equation: 𝐼 𝑟 is the light intensity that comes from the secondary reflective ray Finding the value of 𝐼 𝑟 is the “recursive” part of a recursive ray tracer You stop the recursion when either: Maximum recursive level is reached (defined by the user, e.g., 3) The global contribution falls below a threshold (notice that 𝐼 𝑟 is multiplied by 𝐾 𝑠 , which is the light’s specular constant and should be <= 1) 𝐼 𝑡 is for transmitted rays (for refraction)

Transparent Surfaces (Transmitted Rays) For a partially transparent surface 𝐼 𝜆 = 1− 𝑘 𝑡1 𝐼 𝜆1 + 𝑘 𝑡1 𝐼 𝜆2 𝐼 𝜆 = the final intensity (𝜆 denotes a color channel, r, g, or b) 𝑘 𝑡1 = the transparency value of surface 1 (0 = opaque, 1=fully transparent) 𝐼 𝜆1 = the intensity calculated at surface 1 𝐼 𝜆2 = the intensity calculated at surface 2 Iλ2 Iλ1 Surface 1 Surface 2

Transparent Surface (Refraction) Refraction is modeled using Snell’s Law sin 𝜃 𝑟 sin ( 𝜃 𝑖 ) = 𝜂 𝑟 𝜂 𝑖 r = refraction, i = incident 𝜂 𝑟 =index of refraction for medium 2 𝜂 𝑖 =index of refraction for medium 1 Note that we need to model each color channel (R, G, B) independently, so we could re-write the equation as: sin 𝜃 𝑟 sin ( 𝜃 𝑖 ) = 𝜂 𝑟 𝜆 𝜂 𝑖 𝜆 medium 1 medium 2 r

Reflection + Transparency isect2 isect1 Remember that both 𝐼 𝑅 and 𝐼 𝑇 contribute to the final intensity of the light (𝐼)

Reflection + Transparency + Direct Illumination isect2 isect1 L1 L2 With direct illumination, be mindful of potential shadows That is, remember to compute if a light source can reach the intersection point (isect 1)

Reflection + Transparency + Direct Illumination + Recursion isect2 isect1 L1 L2 In this particular case, if we examine the contribution of 𝐼 𝑅 at the recursive depth of 1 (that is, no more secondary rays), 𝐼 𝑅 should contribute no light

Recap of Recursive Ray Tracing Again, there are 3 types of secondary rays: “Shadow Check”, Reflection, Refraction Controlling the recursion: Recursively spawn secondary rays until lighting contribution falls below a certain threshold OR a max recursive depth is reached Skip reflection rays if the material properties of the object is not reflective Skip refraction rays if the object is opaque

“Tree of Light Rays” (Note we’re not showing the “shadow checks” in these images) T is for Transmitted Rays (refraction), and R is for Reflective Rays (reflection)

Programming Tip! Once we find an intersection (P) and cast “shadow check” rays against light sources (L1 and L2), we need to intersect the rays with the object of which P is on. In checking with L1, this works great. We find that there is an intersection between P and L1, and the intersection occurs at t=0 (where P is, that is, starting point of the ray) In checking with L2, this approach falls apart. We will also find that an intersection occurs at t=0!! Solution: move the intersection out by epsilon amount… n P L1 L2

Questions?

Texture Mapping with Ray Tracer Texture mapping is supported by OpenGL. The general idea is to “wrap” a texture around a geometric surface It can be incorporated into a Ray Tracer, which will allow for additional lighting effects (diffuse, ambient, specular, transparency, shadows, etc.)

Texture Mapping with Ray Tracer

This is typically done in two steps: Texture Mapping In general, we can think of texture mapping as a function that “maps” between two domains, position on the surface of an object (domain), and a pixel value from the texture image (co-domain) This is typically done in two steps: Map a point on the geometry to a point on a unit square Map the unit square onto a texture image

2. Map from Unit Square to Texture Image Map a point in the unit (u, v) square to a texture of arbitrary dimension This can be done by linear interpolation between the coordinate space of the unit square to the texture Unit Square coordinate: u is from 0.0-1.0, v is also from 0.0-1.0 Texture coordinate: w is from 0-width pixels, and h is from 0-height pixels (1.0, 1.0) 𝑣 (0.0, 0.0) unit texture square (200, 100) (0, 0) texture map 𝑢 In the above example: (0.0, 0.0)->(0, 0); (1.0, 1.0)->(200, 100); (0.7, 0.45)->(140, 45) Note that the coordinates in (u, v) might not map perfectly to integer values that correspond to pixels. Need to do some interpolation (filter)

1. Map a point on the geometry to a point on a unit square We have 4 geometric objects to consider in our ray tracer: Cube Sphere Cone Cylinder Cube is pretty easy… The faces of the cube map nicely to a unit square

Mapping a Cube - Tiling 𝑤 𝑡𝑒𝑥𝑡𝑢𝑟𝑒 , ℎ 𝑡𝑒𝑥𝑡𝑢𝑟𝑒 (0, 0) texture map Note that we can allow for tiling if the face of a cube is too large If we map a single texture, it could stretch and look terrible So a possible alternative is to use tiling

Tiling Example Without Tiling Texture With Tiling

Mapping a Cylinder / Cone Recall: the goal is to map a point in (x, y, z) into (u, v) For a cylinder, we can break down the object into two parts: The cap, which we will treat as a square surface The body, which we will unroll into a square (see below) Cone is a special case of a cylinder, need to interpolate as we go up from the base to the tip 𝑣 𝑢 P x 𝑢= .85 z P x y z 𝑣= .4

Mapping a Cylinder / Cone x 𝑢= .85 z Mapping a Cylinder / Cone Help on computing the u value: We need to map all points on the surface to [0, 1] The easiest way is to say 𝑢= 𝜃 2𝜋 , and use the dot product to find 𝜃, but it’s hard to determine the signs (e.g. acos returns a value between 0 and 𝜋, same for atan) For example, atan (1, 1) = atan (-1, -1) = 𝜋 2 So instead we use atan2 (x, y), which returns a values between −𝜋 and 𝜋. (Notice the discontinuity at 𝑢=0.5)

Mapping a Sphere Find (u, v) coordinate for P Find u the same way as before for cylinders v maps to the “latitude” of the sphere between 0 and 1 (the two caps) At v=0 and v=1, there is a singularity. So set u = a pre- defined value (e.g., 0.5) v is a function of the latitude of P: 𝜙= sin −1 𝑃 𝑦 𝑟 − 𝜋 2 ≤𝜙< 𝜋 2 𝑟 = radius 𝑣= 𝜙 𝜋 +.5

Questions?

Texture Mapping Complex Geometry Sometimes, texture mapping the polygons of an object doesn’t get what you are looking for Original Geometry Texture each face separately (notice discontinuities) Texture the object as a continuous object

Basic Idea Use a bounding sphere… Find the ray’s intersection (in object space) with a bounding sphere, called P Find P’s coordinate in the texture map’s (u, v) coordinate Apply the texture to the point on the underlying geometry (the house)

Slightly More Advanced Turns out that we don’t have to use the bounding sphere at all. Just intersect the geometry (house) at point P’, and assume that P’ lies on a sphere. Same result, but need to find the radius at different parts of the geometry Compute a new radius for each intersected point by finding the center of the geometry (house) and connect the center to the intersection point

Slightly More Advanced Turns out that you don’t have to use a sphere as a bounding surface You can use a cylinder or planar mappings for complex objects. Each has drawbacks: Sphere: warping at the “poles” of the object Cylinder: discontinuities between cap and body of the cylinder Planar: one dimension needs to be ignored But can do cool tricks with this… The problem is kind of hard. Since the object is in 3D, mapping it to 2D usually means some drawback

Questions?

Supersampling Notice the jaggies in this (recursively) ray-traced image What’s wrong with it? How can we fix it?

Supersampling Left image: one ray per pixel (through pixel center) Right image: 5 rays per pixel (corners + center) Do weighted average of the rays to color in the pixel Adaptive sampling Supersampling: more samples where we need it (e.g., where geometry or lighting changes drastically) Subsampling: fewer samples where we don’t need detail (faster computation) Beam tracing: track a bundle of neighboring rays together

Supersampling With Supersampling Without Supersampling