lecture16

lecture16 - CS 445 645 Introduction to Computer Graphics...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: CS 445 / 645 Introduction to Computer Graphics Lecture 16 Lighting Review We have a model for determining the brightness We (radiance) of a ray rooted at a point on a surface (radiance) and oriented towards the cameraDirect illumination only illumination – Ambient term – Diffuse term – Specular term Combining Everything Simple analytic model: Simple • diffuse reflection + • specular reflection + • emission + • “ambient” Surface The Final Combined Equation Single light source: N Viewer R α θ θ L V I = I E + K A I AL + K D ( N • L) I L + K S (V • R ) n I L What influences these terms? Influencing factors • Light position • Sample point position • Camera position • Surface angle with respect to light vector • Surface angle with respect to camera vector Direct illumination questions • Camera moves from one position to another – Angle between light and surface unchanged – Angle between camera and surface changes • A tracking camera follows object as it moves in scene – Angle between light and surface changes – Angle between camera and surface unchanged • An object moves from on position to another – Both angles have changed Direct Illumination Provides a way to measure radiance at a point in a specific direction specific • What points? – Vertices What do you do for points between vertices? This becomes a problem of “shading” This becomes a problem of “shading” and we’ll discuss it later and we’ll discuss it later Direct Illumination Provides a way to measure radiance at a point in a specific direction specific • What points? – Other points to sample? This is a form of ray casting. This is a form of ray casting. We’ll talk about it next We’ll talk about it next Direct Illumination Provides a way to measure radiance at a point in a Provides specific direction specific • What points? • What directions? – Towards the camera – No secondary effects Overview Direct (Local) Illumination • Emission at light sources • Scattering at surfaces Global illumination • Shadows • Refractions • Inter-object reflections Direct Illumination Global Illumination We’ve glossed over how light really works And we will continue to do so… One step better Global Illumination • The notion that a point is illuminated by more than light from local The lights; it is illuminated by all the emitters and reflectors in the global scene global The ‘Rendering Equation’ Jim Kajiya (Current head of Microsoft Research) developed this in Jim 1986 1986 I ( x, x') = g ( x, x ') ε ( x, x') + ∫ ρ( x, x' , x' ') I ( x' , x' ') dx ' ' S I(x, x’) = total intensity from point x’ to x total g(x, x’) = 0 when x/x’ are occluded when = 1/d2 otherwise (d = distance between x and x’) ε (x, x’) = intensity emitted by x’ to x intensity ρ (x, x’,x’’) = intensity of light reflected from x’’ to x through x’ intensity S = all points on all surfaces all I ( x, x') = g ( x, x ') ε ( x, x') + ∫ ρ( x, x' , x' ') I ( x' , x' ') dx' ' S x g(x, x') x' 1 or 1/d2 depending on visibility I ( x, x') = g ( x, x ') ε ( x, x') + ∫ ρ( x, x' , x' ') I ( x' , x' ') dx' ' S x ε (x, x') emissivity x' R I ( x, x') = g ( x, x ') ε ( x, x') + ∫ ρ( x, x' , x' ') I ( x' , x' ') dx' ' S Ι (x', x'') x Ι (x', x'') ρ (x, x', x'') Ι (x', x'') Ι (x', x'') x' The ‘Rendering Equation’ The light that hits x from x’ is the direct The illumination from x’ and all the light reflected by x’ from all x’’ x’ To implement: • Must handle recursion effectively • Must support diffuse and specular light • Must model object shadowing The ‘Rendering Equation’ What’s really hard about computing this? I ( x, x') = g ( x, x ') ε ( x, x') + ∫ ρ( x, x' , x' ') I ( x' , x' ') dx' ' S The integral… • How can one compute Ι(x, x') for all points x and x'? How (x, • Approximate!!! Approximating the Rendering Equation Don’t integrate over all points, Don’t just a subset just • Ray Tracing – Considered a Monte Carlo Considered approximation approximation Monte Carlo == Random Monte “sampling” of real answer “sampling” Consider pulling colored balls Consider from an urn to approximate the ratio of its contents ratio by Gilles Tran by Approximating the Rendering Equation Group “all points” into sets and consider all sets • Radiosity – Considered a finiteelement approximation What are the models What that approximate light transfer from one finite element to another? element Consider electing the Consider President from the sum of the states rather than the sum of all people the Ray Casting A simple form of Ray Tracing Rays through view plane Simplest method is ray casting View plane Eye position Ray Casting To create each sample … • Construct ray from eye position through view plane • Find first surface intersected by ray through pixel • Compute color sample based on surface radiance Ray Casting For each sample … • Construct ray from eye Construct position through view plane position • Find first surface Find intersected by ray through pixel pixel Rays through view plane • Compute color sample Compute based on surface radiance based Eye position Samples on view plane Ray Casting Simple implementation: Image RayCast(Camera camera, Scene scene, int width, int height) { Image image = new Image(width, height); for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { Ray ray = ConstructRayThroughPixel(camera, i, j); Intersection hit = FindIntersection(ray, scene); image[i][j] = GetColor(hit); } } return image; } Ray Casting Simple implementation: Image RayCast(Camera camera, Scene scene, int width, int height) { Image image = new Image(width, height); for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { Ray ray = ConstructRayThroughPixel(camera, i, j); Intersection hit = FindIntersection(ray, scene); image[i][j] = GetColor(hit); } } return image; } Constructing Ray Through a Pixel Up direction View Plane back towards P0 V right P Ray: P = P0 + tV Constructing Ray Through a Pixel 2D Example P1 right = towards x up Θ P0 2*d*tan(Θ) Θ = frustum half-angle d = distance to view plane towards V d right P P1 = P0 + d*towards – d*tan(Θ)*right P2 = P0 + d*towards + d*tan(Θ)*right P = P1 + (i/width + 0.5) * (P2 - P1) = P1 + (i/width + 0.5) * 2*d*tan (Θ)*right V = (P - P0) / ||P - P0 || P2 Ray: P = P0 + tV Ray Casting Simple implementation: Image RayCast(Camera camera, Scene scene, int width, int height) { Image image = new Image(width, height); for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { Ray ray = ConstructRayThroughPixel(camera, i, j); Intersection hit = FindIntersection(ray, scene); image[i][j] = GetColor(hit); } } return image; } Ray-Scene Intersection Intersections with geometric primitives • Sphere • Triangle • Groups of primitives (scene) Ray-Sphere Intersection Ray: P = P0 + tV Sphere: |P - C|2 - r 2 = 0 P’ P V P0 r C Ray-Sphere Intersection Ray: P = P0 + tV Sphere: |P - C|2 - r 2 = 0 P’ P Substituting for P, we get: |P0 + tV - C|2 - r 2 = 0 V P0 Solve quadratic equation: at2 + bt + c = 0 where: a = |V|2 = 1 b = 2 V • (P0 - C) c = |P0 - C|2 - r 2 P = P0 + tV If ray direction is normalized! r C Ray-Sphere Intersection Need normal vector at intersection Need for lighting calculations for N = (P - C) / ||P - C|| N V P0 P r C Ray-Scene Intersection Intersections with geometric primitives • Sphere » Triangle • Groups of primitives (scene) Ray-Triangle Intersection First, intersect ray with plane Then, check if point is inside triangle P V P0 Ray-Plane Intersection Ray: P = P0 + tV Plane: P • N + d = 0 Substituting for P, we get: (P0 + tV) • N + d = 0 P Solution: t = -(P0 • N + d) / (V • N) N P = P0 + tV V P0 Ray-Triangle Intersectio Check if point is inside triangle parametrically T3 Compute α, β: P = α (T2-T1) + β (T3-T1) Check if point inside triangle. 0 ≤ α ≤ 1 and 0 ≤ β ≤ 1 α+ β≤ 1 T1 V P0 P β α T2 Other Ray-Primitive Intersections Cone, cylinder, ellipsoid: • Similar to sphere Box • Intersect 3 front-facing planes, return closest Convex polygon • Same as triangle (check point-in-polygon algebraically) Concave polygon • Same plane intersection • More complex point-in-polygon test Ray Casting – direct illumination Trace primary rays from camera • Direct illumination from Direct unblocked lights only unblocked I = I E + K A I A + ∑L ( K D ( N • L) + K S (V • R ) n ) S L I L Shadows Shadow term tells if light sources are blocked • Cast ray towards each light Cast source Li source • Si = 0 if ray is blocked, Si = 1 otherwise • 0 < Si < 1 soft shadows (hack) I = I E + K A I A + ∑L ( K D ( N • L) + K S (V • R ) n ) S L I L Recursive Ray Tracing – second-order effects Also trace secondary rays from hit surfaces • Global illumination from mirror reflection and transparency I = I E + K A I A + ∑L ( K D ( N • L ) + K S (V • R ) n ) S L I L + K R I R + K T I T Mirror reflections Trace secondary ray in Trace mirror direction mirror • Evaluate radiance along Evaluate secondary ray and include it into illumination model model Radiance for mirror reflection ray I = I E + K A I A + ∑L ( K D ( N • L ) + K S (V • R ) n ) S L I L + K R I R + K T I T Transparency Trace secondary ray in Trace direction of refraction direction • Evaluate radiance along Evaluate secondary ray and include it into illumination model model Radiance for refraction ray I = I E + K A I A + ∑L ( K D ( N • L ) + K S (V • R ) n ) S L I L + K R I R + K T I T IT Transparency Transparency coefficient is Transparency fraction transmitted fraction • KT = 1 for translucent object, KT = 0 for opaque • 0 < KT < 1 for object that is semi-translucent semi-translucent Transparency Coefficient I = I E + K A I A + ∑L ( K D ( N • L ) + K S (V • R ) n ) S L I L + K R I R + K T I T K Refractive Transparency For thin surfaces, can ignore change in direction • Assume light travels straight through surface N Θi L ηi ηr T Θr Θi T T ≅ −L Refractive Tranparency For solid objects, apply Snell’s law: ηr sin Θr = ηi sin Θi ηi ηr N Θi L T Θr ηi ηi T = ( cos Θi − cos Θr ) N − L ηr ηr Summary Ray casting (direct Illumination) • Usually use simple analytic approximations for Usually light source emission and surface reflectance light Recursive ray tracing (global illumination) • Incorporate shadows, mirror reflections, Incorporate and pure refractions and All of this is an approximation so that it is practical to compute More on global illumination later! ...
View Full Document

This note was uploaded on 01/23/2012 for the course CS 445 taught by Professor Bloomfield,a during the Spring '08 term at UVA.

Ask a homework question - tutors are online