Cs 445 645 introduction to computer graphics
Download
1 / 45

CS 445 / 645 Introduction to Computer Graphics - PowerPoint PPT Presentation


  • 139 Views
  • Uploaded on

CS 445 / 645 Introduction to Computer Graphics. Lecture 16 Lighting. Review. We have a model for determining the brightness (radiance) of a ray rooted at a point on a surface and oriented towards the cameraDirect illumination only Ambient term Diffuse term Specular term.

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'CS 445 / 645 Introduction to Computer Graphics' - jela


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
Cs 445 645 introduction to computer graphics

CS 445 / 645Introduction to Computer Graphics

Lecture 16

Lighting


Review
Review

  • We have a model for determining the brightness (radiance) of a ray rooted at a point on a surface and oriented towards the cameraDirect illumination only

    • Ambient term

    • Diffuse term

    • Specular term


Combining everything
Combining Everything

  • Simple analytic model:

    • diffuse reflection +

    • specular reflection +

    • emission +

    • “ambient”

Surface


The final combined equation
The Final Combined Equation

  • Single light source:

N

Viewer

R

q

q

L

a

V


What influences these terms
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
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
Direct Illumination

  • Provides a way to measure radiance at a point in a specific direction

    • What points?

      • Vertices

        • What do you do for points between vertices?

This becomes a problem of “shading”and we’ll discuss it later


Direct illumination1
Direct Illumination

  • Provides a way to measure radiance at a point in a specific direction

    • What points?

      • Other points to sample?

This is a form of ray casting.We’ll talk about it next


Direct illumination2
Direct Illumination

  • Provides a way to measure radiance at a point in a specific direction

    • What points?

    • What directions?

      • Towards the camera

      • No secondary effects


Overview
Overview

  • Direct (Local) Illumination

    • Emission at light sources

    • Scattering at surfaces

  • Global illumination

    • Shadows

    • Refractions

    • Inter-object reflections

Direct Illumination


Global 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 lights; it is illuminated by all the emitters and reflectors in the global scene


The rendering equation
The ‘Rendering Equation’

  • Jim Kajiya (Current head of Microsoft Research) developed this in 1986

  • I(x, x’) = total intensity from point x’ to x

  • g(x, x’) = 0 when x/x’ are occluded = 1/d2 otherwise (d = distance between x and x’)

  • e(x, x’) = intensity emitted by x’ to x

  • r(x, x’,x’’) = intensity of light reflected from x’’ to x through x’

  • S = all points on all surfaces


Cs 445

x'

g(x, x')

x

1 or 1/d2depending on visibility


Cs 445

x'

e(x, x')

x

emissivity


Cs 445

I(x', x'')

I(x', x'')

I(x', x'')

I(x', x'')

x'

x

r(x, x', x'')


The rendering equation1
The ‘Rendering Equation’

  • The light that hits x from x’ is the direct illumination from x’ and all the light reflected by x’ from all x’’

  • To implement:

    • Must handle recursion effectively

    • Must support diffuse and specular light

    • Must model object shadowing


The rendering equation2
The ‘Rendering Equation’

  • What’s really hard about computing this?

  • The integral…

    • How can one compute I(x, x') for all points x and x'?

    • Approximate!!!


Approximating the rendering equation
Approximating the Rendering Equation

  • Don’t integrate over all points, just a subset

    • Ray Tracing

      • Considered a Monte Carlo approximation

        • Monte Carlo == Random “sampling” of real answerConsider pulling colored balls from an urn to approximate the ratio of its contents

by Gilles Tran


Approximating the rendering equation1
Approximating the Rendering Equation

  • Group “all points” into sets and consider all sets

    • Radiosity

      • Considered a finite-element approximation

        • What are the models that approximate light transfer from one finite element to another?Consider electing the President from the sum of the states rather than the sum of all people


Ray casting
Ray Casting

  • A simple form of Ray Tracing

Rays

through

view plane

Simplest method

is ray casting

View plane

Eye position


Ray casting1
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 casting2
Ray Casting

  • For 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

Rays

through

view plane

Samples on

view plane

Eye position


Ray casting3
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 casting4
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
Constructing Ray Through a Pixel

Up direction

View

Plane

back

towards

P0

V

right

P

Ray: P = P0 + tV


Constructing ray through a pixel1

P1

2*d*tan(Q)

P1 = P0 + d*towards – d*tan(Q)*right

P2 = P0 + d*towards + d*tan(Q)*right

P2

Constructing Ray Through a Pixel

  • 2D Example

Q = frustum half-angle

d = distance to view plane

towards

P0

Q

right = towards x up

d

V

right

P

Ray: P = P0 + tV

P = P1 + (i/width + 0.5) * (P2 - P1)

= P1 + (i/width + 0.5) * 2*d*tan (Q)*right

V = (P - P0) / ||P - P0 ||


Ray casting5
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
Ray-Scene Intersection

  • Intersections with geometric primitives

    • Sphere

    • Triangle

    • Groups of primitives (scene)


Ray sphere intersection
Ray-Sphere Intersection

Ray: P = P0 + tV

Sphere: |P - C|2 - r 2 = 0

P’

P

V

r

C

P0


Ray sphere intersection1

P’

P

V

r

C

P0

Ray-Sphere Intersection

Ray: P = P0 + tV

Sphere: |P - C|2 - r 2 = 0

Substituting for P, we get:

|P0 + tV - C|2 - r 2 = 0

Solve quadratic equation:

at2 + bt + c = 0

where:

a = |V|2 = 1

b = 2 V • (P0 - C)

c = |P0 - C|2 - r 2

If ray direction

is normalized!

P = P0 + tV


Ray sphere intersection2
Ray-Sphere Intersection

  • Need normal vector at intersection for lighting calculations

N = (P - C) / ||P - C||

N

r

V

P

C

P0


Ray scene intersection1
Ray-Scene Intersection

  • Intersections with geometric primitives

    • Sphere

    • Triangle

    • Groups of primitives (scene)


Ray triangle intersection
Ray-Triangle Intersection

  • First, intersect ray with plane

  • Then, check if point is inside triangle

P

V

P0


Ray plane intersection
Ray-Plane Intersection

Ray: P = P0 + tV

Plane: P • N + d = 0

Substituting for P, we get:

(P0 + tV) • N + d = 0

Solution:

t = -(P0 • N + d) / (V • N)

P

N

P = P0 + tV

V

P0


Ray triangle intersectio
Ray-Triangle Intersectio

  • Check if point is inside triangle parametrically

T3

Compute a, b:

P = a (T2-T1) + b (T3-T1)

Check if point inside triangle.

0 a  1 and 0 b  1

a + b  1

P

b

T1

a

T2

V

P0


Other ray primitive intersections
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
Ray Casting – direct illumination

  • Trace primary rays from camera

    • Direct illumination from unblocked lights only


Shadows
Shadows

  • Shadow term tells if light sources are blocked

    • Cast ray towards each light source Li

    • Si = 0 if ray is blocked, Si = 1 otherwise

    • 0 < Si < 1  soft shadows (hack)


Recursive ray tracing second order effects
Recursive Ray Tracing – second-order effects

  • Also trace secondary rays from hit surfaces

    • Global illumination from mirror reflection and transparency


Mirror reflections
Mirror reflections

  • Trace secondary ray in mirror direction

    • Evaluate radiance along secondary ray and include it into illumination model

Radiance

for mirror

reflection ray

IR


Transparency
Transparency

  • Trace secondary ray in direction of refraction

    • Evaluate radiance along secondary ray and include it into illumination model

Radiance for

refraction ray

IT


Transparency1
Transparency

  • Transparency coefficient is fraction transmitted

    • KT = 1 for translucent object, KT = 0 for opaque

    • 0 < KT < 1 for object that is semi-translucent

Transparency

Coefficient

KT


Refractive transparency
Refractive Transparency

  • For thin surfaces, can ignore change in direction

    • Assume light travels straight through surface

N

Qi

L

hi

hr

T

Qr

Qi

T


Refractive tranparency
Refractive Tranparency

For solid objects, apply Snell’s law:

N

Qi

L

hi

hr

T

Qr


Summary
Summary

  • Ray casting (direct Illumination)

    • Usually use simple analytic approximations for light source emission and surface reflectance

  • Recursive ray tracing (global illumination)

    • Incorporate shadows, mirror reflections, and pure refractions

All of this is an approximation

so that it is practical to compute

More on global illumination later!


ad