Raytracing. COSC 4328/5327 Scott A. King

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

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

Reflection and Shading

COMP371 COMPUTER GRAPHICS

Ray-Tracing. Misha Kazhdan

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

Photorealism: Ray Tracing

Comp 410/510 Computer Graphics. Spring Shading

Lighting and Shading

Illumination & Shading

Computer Graphics (CS 4731) Lecture 16: Lighting, Shading and Materials (Part 1)

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

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

Computer Graphics (CS 543) Lecture 7b: Intro to lighting, Shading and Materials + Phong Lighting Model

Shading I Computer Graphics I, Fall 2008

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

CS580: Ray Tracing. Sung-Eui Yoon ( 윤성의 ) Course URL:

Lighting affects appearance

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

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

CENG 477 Introduction to Computer Graphics. Ray Tracing: Shading

Illumination. Michael Kazhdan ( /657) HB Ch. 14.1, 14.2 FvDFH 16.1, 16.2

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

Illumination in Computer Graphics

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

Lecture 15: Shading-I. CITS3003 Graphics & Animation

The Rendering Equation. Computer Graphics CMU /15-662

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

Introduction to Computer Graphics 7. Shading

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

All forms of EM waves travel at the speed of light in a vacuum = 3.00 x 10 8 m/s This speed is constant in air as well

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

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

Lighting and Shading Computer Graphics I Lecture 7. Light Sources Phong Illumination Model Normal Vectors [Angel, Ch

Simple Lighting/Illumination Models

CS 5625 Lec 2: Shading Models

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

CPSC 314 LIGHTING AND SHADING

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

Graphics for VEs. Ruth Aylett

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

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

Topic 9: Lighting & Reflection models 9/10/2016. Spot the differences. Terminology. Two Components of Illumination. Ambient Light Source

Illumination & Shading: Part 1

Lighting and Reflectance COS 426

Computer Graphics. Illumination and Shading

Topic 9: Lighting & Reflection models. Lighting & reflection The Phong reflection model diffuse component ambient component specular component

CS 325 Computer Graphics

Illumination. Courtesy of Adam Finkelstein, Princeton University

LECTURE 15 REFLECTION & REFRACTION. Instructor: Kazumi Tolich

LIGHT. Speed of light Law of Reflection Refraction Snell s Law Mirrors Lenses

CMSC427 Shading Intro. Credit: slides from Dr. Zwicker

Illumination and Shading

Ray Tracing. Kjetil Babington

CSE 681 Illumination and Phong Shading

Ray Tracing. Local Illumination. Object Space: Global Illumination. Image Space: Backward Ray Tracing. First idea: Forward Ray Tracing

Indirect Illumination

EECS 487: Interactive Computer Graphics

Today we will start to look at illumination models in computer graphics

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

Ray Tracing. Johns Hopkins Department of Computer Science Course : Rendering Techniques, Professor: Jonathan Cohen

CS230 : Computer Graphics Lighting and Shading. Tamar Shinar Computer Science & Engineering UC Riverside

Sung-Eui Yoon ( 윤성의 )

Lighting affects appearance

Lecture 10: Ray tracing

Lighting and Shading. Slides: Tamar Shinar, Victor Zordon

CS 4600 Fall Utah School of Computing

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

Ray Tracer Due date: April 27, 2011

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

Computer Graphics. Illumination Models and Surface-Rendering Methods. Somsak Walairacht, Computer Engineering, KMITL

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

Chapter 10. Surface-Rendering Methods. Somsak Walairacht, Computer Engineering, KMITL

CS5620 Intro to Computer Graphics

Supplement to Lecture 16

Light Transport Baoquan Chen 2017

Objectives. Introduce Phong model Introduce modified Phong model Consider computation of required vectors Discuss polygonal shading.

SESSION 5: INVESTIGATING LIGHT. Key Concepts. X-planation. Physical Sciences Grade In this session we:

Ray Tracing: Special Topics CSCI 4239/5239 Advanced Computer Graphics Spring 2018

The Rendering Equation. Computer Graphics CMU /15-662, Fall 2016

Introduction to Visualization and Computer Graphics

Indirect Illumination

Illumination & Shading I

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

Raytracing CS148 AS3. Due :59pm PDT

ECS 175 COMPUTER GRAPHICS. Ken Joy.! Winter 2014

OpenGl Pipeline. triangles, lines, points, images. Per-vertex ops. Primitive assembly. Texturing. Rasterization. Per-fragment ops.

Ray Tracing: shading

Graphics for VEs. Ruth Aylett

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

S U N G - E U I YO O N, K A I S T R E N D E R I N G F R E E LY A VA I L A B L E O N T H E I N T E R N E T

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

Raytracing & Epsilon. Today. Last Time? Forward Ray Tracing. Does Ray Tracing Simulate Physics? Local Illumination

Global Illumination. Global Illumination. Direct Illumination vs. Global Illumination. Indirect Illumination. Soft Shadows.

Recall: Basic Ray Tracer

Chapter 32 Light: Reflection and Refraction. Copyright 2009 Pearson Education, Inc.

Ray Optics. Lecture 23. Chapter 23. Physics II. Course website:

Overview. Shading. Shading. Why we need shading. Shading Light-material interactions Phong model Shading polygons Shading in OpenGL

CS452/552; EE465/505. Intro to Lighting

03 RENDERING PART TWO

Transcription:

Raytracing COSC 4328/5327 Scott A. King

Basic Ray Casting Method pixels in screen Shoot ray p from the eye through the pixel. Find closest ray-object intersection. Get color at intersection

Basic Ray Casting Method pixels in screen Shoot ray p from the eye through the pixel. Find closest ray-object intersection. Get color at intersection

Basic Ray Casting Method pixels in screen Shoot ray p from the eye through the pixel. Find closest ray-object intersection. Get color at intersection

Basic Ray Casting Method pixels in screen Shoot ray p from the eye through the pixel. Find closest ray-object intersection. Get color at intersection Illumination Model

Basic Ray Model Let s treat a ray as a vector. Namely we can represent a ray by the vector form: p = u + vt

Reflectance: BRDF Light arriving at a surface can scatter in many directions Intensity for a given outgoing direction is dependent on incoming direction and material properties Model or measurement of reflectance is called the bidirectional reflectance distribution function (BRDF): for any incoming light ray how much energy is reflected for any outgoing light ray can measure or model Diffuse Reflections = + Specular Reflections Total Scattering Distribution (BRDF) BRDF for simple model of diffuse + specular reflection, e.g., the Phong Lighting Model

Simple Reflectance Models ω r n ω Mirror light scatters in a single direction, ω r = ω 2 ω n n Lambertian light scatters equally (output radiance is equal) in all outgoing directions (i.e. viewer independent) Diffuse light scatters (possibly unevenly) in all outgoing directions, e.g., rug, paper, unvarnished wood Specular light scatters tightly around a particular direction (shiny objects with sharp highlights) Glossy light scatters weakly around a particular direction

A Perfect Reflector The angle between the normal and incoming ray is maintained for the outgoing ray ω r n ω

Diffuse Reflection An ideal diffuse reflector (a Lambertian Reflector, e.g. chalk) is the simplest to model. Incoming light is scattered equally in all directions, so brightness does not depend on the viewing direction. Reflected brightness depends on the direction and brightness of illumination (cos of light/normal angle L n n

Lambertian Reflection Use Lambert's law, which says the Intensity of the reflected energy (light) depends upon the angle between the incoming light and the surface normal. The intensity is view independent! I = I dir k d cos θ = I dir k d N L where I dir is the intensity (color) of the incident light (parallel to L), k d is the diffuse constant of the surface (0-1) (wavelength dependant) As angle between light and normal increases, light s energy spreads across a larger area N θ L

Specular Reflection Shiny surfaces reflect light coherently in a narrow beam (expanding cone) in the specular direction. L n The specular direction is the angle of incident light reflected about the surface normal. If your eye is in that cone, the surface looks brighter (a highlight) that reduces away from the center N θ L The cone s width is dependent on smoothness of surface

Phong Illumination Ambient Non-specific constant global lighting (hack) Diffuse use Lambert s model to handle viewer independent diffuse reflections Specular Highlights on shiny objects (hack) Ik s Proportional to R V α so a larger α gives in a more concentrated highlight V I a k a Ik d N L R R V p NumLights I = I a k a + I j k d N L +k s R V p j N θ θ L Only lights not in shadow

Shadow Rays Light Only want to add contribution from lights that aren t in shadow, that is visible from the surface. How do we figure this out? Where does the ray start? What is the direction of the ray? Should direction be unit? Opaque object Should we intersect ray with all objects? Shadow Rays S 2 R 1 P Eye S 1 S 3 Transparent object Primary Ray

Reflection Rays If the object is reflective, shoot a reflection ray. The ray starts at the intersection point and has a direction V 2N N V Notice: unit vectors! What is V? u v n(n.v) v v n n(n.v) n n(n.v) v v -n(n.v) -n(n.v) -n(n.v) -n(n.v) n p v-2n(n.v)

Cancer Numerical issues cause you to think reflection rays intersect with object when it doesn t. Move position off of surface by small amount

Transmission Rays u n p

Refraction u n Why does refraction occur? Different velocities through different materials. Rays bend toward the normal when going from sparser to denser materials (air to water), and away for the opposite case. We treat all light as bending the same amount. Is this accurate? p

Refract Snell s Law: i sin i = t sin t Let = i / t = sin t / sin i Let m = (cos i n - i) / sin i Then t = sin t m - cos t n = (sin t / sin i ) (cos i n - i) - cos t n = ( cos i - cos t )n - i t 2 2 ( n i) 1 (1 ( n i) n i ) n cos i n - i i cos t i -n t 1 sin cos i n m 2 2 1 sin t =? t 2 i Can be negative for grazing angles when >1, say when going from glass to air, resulting in total internal reflection (no refraction). Ray refract(ray r) { double ni = dot(n,-r.d); double eta = current_index/new_index; return Ray((x,eta*ni - sqrt(1 - eta*eta*(1-ni*ni)))*n + eta*r.d); }

Refraction Refractive index: Light travels at speed c/n in a material with a refractive index n. Use Snell s law, n1 sin 1 = n2 sin 2, to calculate the refracted ray. Common values for index of refraction: air 1.000293 water - 1.33 glass 1.5 diamond 2.419 http://en.wikipedia.org/wiki/list_of_re fractive_indices

Refraction Demos http://lectureonline.cl.msu.edu/ mmp/kap25/snell/app.htm http://micro.magnet.fsu.edu/primer/jav a/refraction/index.html stwww.weizmann.ac.il/lasers/laserwe b/java/twoangles2.htm

Recursive Raytracer Ray.start = camera; for each pixel: Ray.direction = normalize(pixelcenter Ray.start); for each object: Intersect Ray with object Select object with smallest positive t (visible object) if no object with a positive t, then use backgroud color and go to next pixel pixelcolor = getillumination(ray, ObjectHit) getillumination(ray, Hit) transform ObjectSpace Normal to world space get world space Hitpoint, and V for each visible light: calculate, R, L and local lighting using Phong Illumination model if object transparent, shoot refraction ray starting at hit, using Snell s law for dir if object shiny, shoot reflection ray starting at hit and reflect V about N add all light contributions and return value

Recursive Ray Tracing RayCast(screen) for all pixels (x,y) in screen: trace(rayfromeyethrough(x,y)) Shade(point, ray) Color = background; for each light if!shadow(point, ray, light) Color += PhongIllumination(point, ray, light) if specularmaterial Color+=ks*trace(reflect(point, ray)) if refractive Color+=kt*trace(refraction(point,ray)) return Color trace(ray) if (intersection= closestintersection(ray)) return Shade(intersection, ray) else return backgroundcolor closestintersection(ray) for all objects find intersection for closest intersection return the intersection point, surface normal, surface, surface attributes, etc.

File Format Command description # A line that begins with a # is a comment line, ignore the entire line. view n d sphere scale sx sy sz move x y z The scene is nxn pixels. d is the distance to the corner of the image plane. The perspective camera at (0,0,1) and points toward the origin with (0,1,0) being the up vector. The image plane therefore runs from (-d,-d,0) to (d,d,0). draw a sphere using the current material and transformed by the current transformation. Adds a scale by sx sy sz to the current transformation. Adds a translate to x y z to the current transformation. rotate angle x y z Adds a rotate angle degrees about the axis defined by the vector (x y z) light r g b x y z Define a light located at (x y z) with color (r g b) background r g b Set the scene background color to (r g b), the default is black (0,0,0) ambient r g b group groupend material dr dg db sr sg sb p refraction r g b i Set the scene ambient light to (r g b). group the following objects, transforms and materials together. Signifies the end of a group. Sets the current material value to have a diffuse color of (dr,dg,db) a specular color of (sr,sg,sb) and a phong highlight coefficient of p. The material becomes part of the state and all subsequent objects are of this material. Sets the refraction coefficients for the current material. Default is (0 0 0 1.0002926). The default index for the scene will be 1.0002926 (air). This becomes part of the state, just like material.