CS Computer Graphics: Ray Tracing Detail, Part 3

Similar documents
CS Computer Graphics: Ray Tracing Detail, Part 3

CS Computer Graphics: Introduction to Ray Tracing

CS Computer Graphics: Introduction to Ray Tracing

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

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

Illumination & Shading I

Illumination in Computer Graphics

CS Computer Graphics: Illumination and Shading I

CS Computer Graphics: Illumination and Shading I

CS 543: Computer Graphics Lecture 10 (Part II): Raytracing (Part II) Emmanuel Agu

Comp 410/510 Computer Graphics. Spring Shading

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

Objectives. Continue discussion of shading Introduce modified Phong model Consider computation of required vectors

Illumination & Shading

Introduction to Computer Graphics 7. Shading

Shading II. Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico

Objectives. Shading II. Distance Terms. The Phong Reflection Model

Graphics and Visualization

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

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

CS452/552; EE465/505. Lighting & Shading

Introduction to Ray-tracing Objectives

Today s class. Simple shadows Shading Lighting in OpenGL. Informationsteknologi. Wednesday, November 21, 2007 Computer Graphics - Class 10 1

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

Photorealism: Ray Tracing

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

Lighting and Shading II. Angel and Shreiner: Interactive Computer Graphics 7E Addison-Wesley 2015

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

Raytracing. COSC 4328/5327 Scott A. King

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

Interactive Real-Time Raycasting

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

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

Supplement to Lecture 16

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

CS 325 Computer Graphics

Assignment 6: Ray Tracing

C O M P U T E R G R A P H I C S. Computer Graphics. Three-Dimensional Graphics V. Guoying Zhao 1 / 65

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

Shading II. CITS3003 Graphics & Animation

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

Ray Tracing. Kjetil Babington

Computer Graphics Tick 1

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

Raytracing CS148 AS3. Due :59pm PDT

Deferred Rendering Due: Wednesday November 15 at 10pm

Reflection and Shading

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

OpenGL Lighting Computer Graphics Spring Frank Palermo

Ray Tracing. Shandong University

CS Illumination and Shading. Slide 1

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

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

Computer Graphics Tick 2

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

Illumination and Shading

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

Assignment 2 Ray Tracing

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

Lessons Learned from HW4. Shading. Objectives. Why we need shading. Shading. Scattering

Three-Dimensional Graphics V. Guoying Zhao 1 / 55

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

A Little Background. Motivation. Motivation

Illumination and Shading

CENG 477 Introduction to Computer Graphics. Ray Tracing: Shading

Lighting and Shading. Slides: Tamar Shinar, Victor Zordon

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

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

COMP371 COMPUTER GRAPHICS

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

CSE 681 Illumination and Phong Shading

CS 4600 Fall Utah School of Computing

Ray Tracing COMP575/COMP770

-=Bui Tuong Phong's Lighting=- University of Utah, but with shaders. Anton Gerdelan Trinity College Dublin

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

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

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

surface: reflectance transparency, opacity, translucency orientation illumination: location intensity wavelength point-source, diffuse source

Rendering. Illumination Model. Wireframe rendering simple, ambiguous Color filling flat without any 3D information

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

Review for Ray-tracing Algorithm and Hardware

Lighting and Shading

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

Photorealistic 3D Rendering for VW in Mobile Devices

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

Ray Tracer Due date: April 27, 2011

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

CPSC GLOBAL ILLUMINATION

Why we need shading?

CG Surfaces: Materials, Shading, and Texturing

CS 488. More Shading and Illumination. Luc RENAMBOT

CS 6958 LECTURE 5 TM ANALYSIS SHADING

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

Photorealism. Photorealism: Ray Tracing. Ray Tracing

Computer Graphics I. Assignment 3

Ray Tracing Basics I. Computer Graphics as Virtual Photography. camera (captures light) real scene. photo. Photographic print. Photography: processing

Illumination and Shading

Recall: Indexing into Cube Map

CS Computer Graphics: Hidden Surface Removal

Graphics for VEs. Ruth Aylett

Transcription:

CS 543 - Computer Graphics: Ray Tracing Detail, Part 3 by Robert W. Lindeman gogo@wpi.edu (with help from Emmanuel Agu ;-)

hit( ) Function for Sphere Recall that for generic sphere, there are two hit times, t 1 and t 2 corresponding to the solutions 2 B B! AC t h =! ± A A which are the solutions to the quadratic equation At 2 + 2Bt + C = 0, where A = c 2, B = S.c and C = S 2 1 Thus the hit( ) function for a sphere is as follows: Bool Sphere::hit( Ray &r, ntersection inter ) { Ray genray; // need to make the generic ray xfrmray( genray, invtransf, r ); double A, B, C... R.W. Lindeman - WP Dept. of Computer Science 2

hit( ) Function for Sphere A = dot3d( genray.dir, genray.dir ); B = dot3d( genray.start, genray.dir ); C = dot3d( genray.start, genray.start ) 1.0; double discrim = B * B A * C; if( discrim < 0.0 ) { // ray misses return( false ); int num = 0; // the # of hits so far double discroot = sqrt( discrim ); double t1 = ( -B discroot ) / A; // the earlier hit... 2 B B! AC t h =! ± A A R.W. Lindeman - WP Dept. of Computer Science 3

hit( ) Function for Sphere if( t1 > 0.00001 ) { // is hit in front of the eye? inter.hit[0].hittime = t1; inter.hit[0].hitobject = this; inter.hit[0].isentering = true; inter.hit[0].surface = 0; Point3 P(rayPos(genRay, t1)); // hit spot inter.hit[0].hitpoint.set(p); inter.hit[0].hitnormal.set(p); num = 1; // have a hit 2 B B! AC t h =! ± A A R.W. Lindeman - WP Dept. of Computer Science 4

hit( ) Function for Sphere double t2 = ( -B + discroot ) / A; // the later hit if( t2 > 0.00001 ) { // is hit in front of the eye? inter.hit[num].hittime = t2; inter.hit[num].hitobject = this; inter.hit[num].isentering = false; 2 inter.hit[num].surface = 0; B B! t h =! ± Point3 P( raypos( genray, t2 ) ); // hit Aspot A inter.hit[num].hitpoint.set( P ); inter.hit[num].hitnormal.set( P ); num++; // have a hit inter.numhits = num; return( num > 0 ); // true of false AC R.W. Lindeman - WP Dept. of Computer Science 5

Final words on Sphere hit() Function Function xfrmray() inverse-transforms the ray Test for t2 is structured such that if t1 is negative, t2 is returned as first hit time raypos() converts hit time to a 3D point (x, y, z) Point3 raypos( Ray &r, float t ); //returns ray s location at t raypos() is based on equation P hit = eye + dir rc t hit We can finish off a ray tracer for emissive spheres Emissive? Yes no ambient, diffuse, specular f object is hit, set to emissive color (from SDL file), else set to background R.W. Lindeman - WP Dept. of Computer Science 6

Emissive shade( ) Function Color3 Scene::shade( Ray& ray ) { // is hit in front of the eye? Color3 color; ntersection best; getfirsthit(ray, best); if( best.numhits == 0 ) return( background ); Shape* myobj = ( Shape* )best.hit[0].hitobject; // hit object color.set( myobj->mtrl.emissive ); return( color ); Need hit functions for more shapes (cube, square, cylinder, etc.) R.W. Lindeman - WP Dept. of Computer Science 7

Adding Ambient, Diffuse, Specular to shade( ) Function Recall Phong s illumination model s m r v dir P h = Where light vector s = Light positon hit Point View vector v = -dir a k a + & s m # lambert = max$ 0,! % s m " d k d! lambert + k! phong R.W. Lindeman - WP Dept. of Computer Science 8 sp s & h m # phong = max$ 0,! % h m " f

Adding Ambient, Diffuse, Specular to shade( ) Function h is Blinn s halfway vector given by h = s + v To handle colored lights and object surfaces, we separate the equation = a k a + d k d! lambert + k! phong into separate R G and B parts so that = k + k! lambert + k! phong r g b = = ar ag ab ar k k ag ab + + dr dg db dr k k dg db Lambert and phong terms use transformed object normal m at hit point How do we get transformed normal? R.W. Lindeman - WP Dept. of Computer Science 9 sp s spr! lambert + k! phong spg! lambert + k! phong spb sr sb sg f f f f

Finding Normal at Hit Spot How do we get transformed normal? We set generic object normal at hit point E.g., in sphere hit function, set hit point normal = hit point for generic sphere We did inter.hit[0].hitnormal.set(p); So, we have normal for generic object m To get transformed object normal m, simply (see section 6.5.3) m = M!T m' R.W. Lindeman - WP Dept. of Computer Science 10

Adding Ambient, Diffuse, Specular to shade( ) Function You specify ambient, diffuse and specular values of materials in your SDL file Each cylinder, cube, etc. is a GeomObj class GeomObj class has material mtrl as member Your ray tracer can then access ka, kd as mtrl.ambient, mtrl.diffuse and mtrl.specular For more realistic look, can use carefully measure values from McReynolds and Blythe.! first define values def Copper{ ambient 0.19125 0.0735 0.0225 diffuse 0.7038 0.27048 0.0828 specular 0.256777 0.137622 0.086014 exponent 12.8!then use defined values Use Copper sphere R.W. Lindeman - WP Dept. of Computer Science 11

Adding Ambient, Diffuse, Specular to shade( ) Function Can now define full shade function with ambient, diffuse and specular contributions Color3 Scene::shade( Ray& ray ) { // is hit in front of the eye? Get the first hit using getfirsthit( r, best ); Make handy copy h = best.hit[0];// data about first hit Form hitpoint based on h.hittime Form v = -ray.dir; // direction to viewer v.normalize( ); Shape* myobj = ( Shape * )h.hitobject; // point to hit object Color3 color( myobj->mtrl.emissive ); // start with emissive color.add( ambient contribution ); // compute ambient color R.W. Lindeman - WP Dept. of Computer Science 12

Adding Ambient, Diffuse, Specular to shade( ) Function Vector3 normal; & s m # lambert = max$ 0,! % s m " // transform the generic normal to the world normal xfrmnormal( normal, myobj->invtransf, h.hitnormal ); normal.normalize( ); // normalize it for( each light source, L ) { // sum over all sources if(isnshadow(..)) continue; // skip L if it s in shadow Form s = L.pos hitpoint; // vector from hit pt to src s.normalize( ); float mdots = s.dot( normal ); // Lambert term if(mdots > 0.0 ) { // hit point is turned toward the light Form diffusecolor = mdots * myobj->mtrl.diffuse * L.color color.add( diffusecolor ); // add the diffuse part R.W. Lindeman - WP Dept. of Computer Science 13

Adding Ambient, Diffuse, Specular to shade( ) Function Form h = v + s; // the halfway vector h.normalize( ); & h m # phong = max$ 0,! % h m " float mdoth = h.dot( normal ); // part of phong term if( mdoth <= 0 ) continue; // no specular contribution float phong = pow( mdoth, myobj->mtrl.specularexponent ); speccolor = phong * myobj->mtrl.specular * L.color; color.add( speccolor ); return( color ); isnshadow( ) is function to tests if point is in shadow. mplement next! R.W. Lindeman - WP Dept. of Computer Science 14

Adding Shadows to Raytracing Shadows are important visual cues for humans Previously discussed limited shadow algorithms Limited due to OpenGL Raytracing adds shadows with little programming effort So far, all hit points rendered with all shading components (ambient, diffuse, specular, emissive) f hit point is in shadow, render using only ambient (and emissive). Leave out specular and diffuse 3 possible cases A: no other object between hit point and light source B: another object between hit point and light source (occlusion) C: object blocks itself from light source (back face) R.W. Lindeman - WP Dept. of Computer Science 15

Adding Shadows Need routine isnshadow() which tests to see if hit point is in shadow isnshadow() returns true if hit point is in shadow false otherwise isnshadow() spawns new ray called shadow feeler emanating from hit point at time t=0 and reaching light source at t=1 So, parametric equation of shadow feeler is P h + (L P h )t So, shadow feeler is built, and each object in object list is scanned for intersection (just like eye ray) f any valid intersection in time range t=[0,1] isnshadow() returns true, otherwise returns false R.W. Lindeman - WP Dept. of Computer Science 16

Adding Shadows Note: since we made hit function general, takes ray as argument, once we build shadow feeler, reuse hit( ) functions One more sticky point: self-shadowing!! How? Since shadow feeler starts at hit point at t=0, isnshadow() always intersects with object itself (returns true) Can fix this by starting shadow ray slightly away from hit point. E.g., in figure, start shadow feeler starts at P h -ε dir L1 Note: feeler is ε toward eye NOT light P h P h -ε dir R.W. Lindeman - WP Dept. of Computer Science 17

Adding Shadows How to put this back into shade( ) function? After getfirsthit( ) returns closest hit point, add ambient component Next, build shadow feeler (per light source) with start point of P h -ε dir Feeler direction is set to (Light position feeler start) Call isnshadow( feeler ) to determine object intersections (and hit times) f any valid intersections with object (t between 0 and 1), diffuse and specular components are skipped else add them Variable recurselevel is used to control how many times hit( ) function can call itself. Set it to 1 for shadow ray More on recurselevel when we discuss reflection R.W. Lindeman - WP Dept. of Computer Science 18

Shade Function with Shadow Pseudocode feeler.start = hitpoint - ε ray.dir; feeler.recurselevel = 1; color = ambient part; for( each light source, L ) { feeler.dir = L.pos - hitpoint; if( isnshadow( feeler ) ) continue; color.add( diffuse light ); color.add( specular light ); R.W. Lindeman - WP Dept. of Computer Science 19

isnshadow( ) mplementation bool Scene::isnShadow( Ray& f ) { for( GeomObj* p = obj; p; p = p->next ) { if( p->hit( f ) ) { return( true ); return( false ); Above, we use simplified hit( ) function Only tests for hit time between 0 and 1 f valid hit, return, don t fill hit record, hit object, etc R.W. Lindeman - WP Dept. of Computer Science 20

References Hill, chapter 12 R.W. Lindeman - WP Dept. of Computer Science 21