04b Lighting Full

download 04b Lighting Full

of 48

Transcript of 04b Lighting Full

  • 7/27/2019 04b Lighting Full

    1/48

    ThomasFunkhouser2000

    ()

    Thomas Funkhouser

    Princeton University

    C0S 426, Fall 2000

  • 7/27/2019 04b Lighting Full

    2/48

    ThomasFunkhouser2000

    Ray Casting

    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(scene, ray, hit);

    }

    }

    return image;}

    Wireframe

  • 7/27/2019 04b Lighting Full

    3/48

    ThomasFunkhouser2000

    Ray Casting

    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(scene, ray, hit);

    }

    }

    return image;}

    Without Illumination

  • 7/27/2019 04b Lighting Full

    4/48

    ThomasFunkhouser2000

    Ray Casting

    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(scene, ray, hit);

    }

    }

    return image;}

    With Illumination

  • 7/27/2019 04b Lighting Full

    5/48

    ThomasFunkhouser2000

    Illumination

    How do we compute radiance for a sample ray?

    Angel Figure 6.2

    image[i][j] = GetColor(scene, ray, hit);

  • 7/27/2019 04b Lighting Full

    6/48

    ThomasFunkhouser2000

    Goal

    Must derive computer models for ... Emission at light sources

    Scattering at surfaces

    Reception at the camera

    Desirable features Concise

    Efficient to compute

    Accurate

  • 7/27/2019 04b Lighting Full

    7/48

    ThomasFunkhouser2000

    Overview

    Direct Illumination Emission at light sources

    Scattering at surfaces

    Global illumination Shadows

    Refractions

    Inter-object reflections

    Direct Illumination

    Shadows

  • 7/27/2019 04b Lighting Full

    8/48

    ThomasFunkhouser2000

    Modeling Light Sources

    IL(x,y,z,q,f,l) ... describes the intensity of energy,

    leaving a light source,

    arriving at location(x,y,z), ...

    from direction (q,f), ... with wavelength l (x,y,z)

    Light

  • 7/27/2019 04b Lighting Full

    9/48

    ThomasFunkhouser2000

    Empirical Models

    Ideally measure irradiant energy for all situations Too much storage

    Difficult in practice

    l

  • 7/27/2019 04b Lighting Full

    10/48

    ThomasFunkhouser2000

    OpenGL Light Source Models

    Simple mathematical models: Point light

    Directional light

    Spot light

  • 7/27/2019 04b Lighting Full

    11/48

    ThomasFunkhouser2000

    Point Light Source

    Models omni-directional point source (e.g., bulb) intensity (I0),

    position (px, py, pz),

    factors (kc, kl, kq) for attenuation with distance (d)

    2

    qlc

    0

    kkk

    I

    ddI

    L

    d

    Light

    (px, py, pz)

  • 7/27/2019 04b Lighting Full

    12/48

    ThomasFunkhouser2000

    Directional Light Source

    Models point light source at infinity (e.g., sun) intensity (I0),

    direction (dx,dy,dz)

    0IIL

    (dx, dy, dz)

    No attenuationwith distance

  • 7/27/2019 04b Lighting Full

    13/48

    ThomasFunkhouser2000

    Spot Light Source

    Models point light source with direction (e.g., Luxo) intensity (I0),

    position (px, py, pz),

    direction D=(dx, dy, dz)

    attenuation

    2

    qlc

    0

    kkk

    )(I

    dd

    LDI

    L

    d

    Light

    (px, py, pz)

    D

    L g

  • 7/27/2019 04b Lighting Full

    14/48

    ThomasFunkhouser2000

    Overview

    Direct Illumination Emission at light sources

    Scattering at surfaces

    Global illumination Shadows

    Refractions

    Inter-object reflections

    Direct Illumination

  • 7/27/2019 04b Lighting Full

    15/48

    ThomasFunkhouser2000

    Modeling Surface Reflectance

    Rs(q,f,g,y,l) ... describes the amount of incident energy,

    arriving from direction (q,f), ...

    leaving in direction (g,y),

    with wavelength l

    Surface

  • 7/27/2019 04b Lighting Full

    16/48

    ThomasFunkhouser2000

    Empirical Models

    Ideally measure radiant energy forall combinations of incidentangles Too much storage

    Difficult in practice

    Example BRDF (Bidirectional reflectance

    distribution function)

    Surface

    (q,f)

    (y,l)

    l

  • 7/27/2019 04b Lighting Full

    17/48

    ThomasFunkhouser2000

    OpenGL Reflectance Model

    Simple analytic model: diffuse reflection +

    specular reflection +

    emission +

    ambient

    Surface

    Based on model

    proposed by Phong inhis PhD dissertation

    1973

  • 7/27/2019 04b Lighting Full

    18/48

    ThomasFunkhouser2000

    Diffuse Reflection

    Diffuse: Spread Out / To pass byspreading every way / To extendin all directions

    Assume surface reflects equally

    in all directions Examples: chalk, clay

    Surface

  • 7/27/2019 04b Lighting Full

    19/48

    ThomasFunkhouser2000

    Diffuse Reflection

    How much light is reflected? Depends on angle of incident light

    Surface

    dL

    cosdAdL

    dA

    q

  • 7/27/2019 04b Lighting Full

    20/48

    ThomasFunkhouser200

    0

    Diffuse Reflection

    Lambertian model cosine law (dot product)

    Surface

    N

    Lq

    cos

    cos

    ( )D D L

    N L N L

    N L

    I K N L I

  • 7/27/2019 04b Lighting Full

    21/48

    ThomasFunkhouser200

    0

    OpenGL Reflectance Model

    Simple analytic model: diffuse reflection +

    specular reflection +

    emission +

    ambient

    Surface

  • 7/27/2019 04b Lighting Full

    22/48

    ThomasFunkhouser200

    0

    Specular Reflection

    Reflection is strongest near mirror angle Examples: mirrors, metals

    N

    LR qq

  • 7/27/2019 04b Lighting Full

    23/48

    ThomasFunkhouser200

    0

    Specular Reflection

    How much light is seen? Depends on angle of incident light and angle to viewer

    N

    LR

    V

    Viewer

    a

    qq

  • 7/27/2019 04b Lighting Full

    24/48

    ThomasFunkhouser200

    0

    Specular Reflection

    Phong Model cos(a)n

    L

    n

    SSIRVKI )(

    N

    LR

    V

    Viewer

    a

    qq

    Phong exponent: apparentsmoothness of the surface

  • 7/27/2019 04b Lighting Full

    25/48

    ThomasFunkhouser200

    0

    Specular Reflection

    Phong Examples

    Direction of light source and shininess exponent is varied

  • 7/27/2019 04b Lighting Full

    26/48

    ThomasFunkhouser200

    0

    OpenGL Reflectance Model

    Simple analytic model: diffuse reflection +

    specular reflection +

    emission +

    ambient

    Surface

  • 7/27/2019 04b Lighting Full

    27/48

    ThomasFunkhouser200

    0

    Emission

    Emission 0 Represents light eminating directly from polygon

  • 7/27/2019 04b Lighting Full

    28/48

    ThomasFunkhouser200

    0

    OpenGL Reflectance Model

    Simple analytic model: diffuse reflection +

    specular reflection +

    emission +

    ambient

    Surface

  • 7/27/2019 04b Lighting Full

    29/48

    ThomasFunkhouser200

    0

    Ambient Term

    This is a total hack (avoids complexity of global illumination)!

    Represents reflection of all indirect illumination

  • 7/27/2019 04b Lighting Full

    30/48

    ThomasFunkhouser200

    0

    OpenGL Reflectance Model

    Simple analytic model: diffuse reflection +

    specular reflection +

    emission +

    ambient

    Surface

  • 7/27/2019 04b Lighting Full

    31/48

    ThomasFunkhouser200

    0

    OpenGL Reflectance Model

    Simple analytic model: diffuse reflection +

    specular reflection +

    emission +

    ambient

    Surface

  • 7/27/2019 04b Lighting Full

    32/48

    ThomasFunkhouser200

    0

    Surface Illumination Calculation

    Single light source:

    L

    n

    SLDALAEIRVKILNKIKII )()(

    N

    LR

    V

    Viewera

    qq

  • 7/27/2019 04b Lighting Full

    33/48

    ThomasFunkhouser200

    0

    Surface Illumination Calculation

    Multiple light sources:

    ))()(( i in

    iSiiDALAEIRVKILNKIKII

    N

    L2

    V

    Viewer L1

  • 7/27/2019 04b Lighting Full

    34/48

    ThomasFunkhouser200

    0

    Overview

    Direct Illumination Emission at light sources

    Scattering at surfaces

    Global illumination Shadows

    Transmissions

    Inter-object reflections

    Global Illumination

  • 7/27/2019 04b Lighting Full

    35/48

    ThomasFunkhouser200

    0

    Global Illumination

    Greg Larson

  • 7/27/2019 04b Lighting Full

    36/48

    ThomasFunkhouser200

    0

    Shadows

    Shadow terms tell which light sources are blocked Cast ray towards each light source Li Si = 0 if ray is blocked, Si = 1 otherwise

    Angel Figure 6.44

    L LLn

    SDAAEISRVKLNKIKII ))()((

    ShadowTerm

  • 7/27/2019 04b Lighting Full

    37/48

    ThomasFunkhouser200

    0

    Ray Casting

    Trace primary rays from camera Direct illumination from unblocked lights only

    L LLn

    SDAAEISRVKLNKIKII ))()((

  • 7/27/2019 04b Lighting Full

    38/48

    ThomasFunkhouser200

    0

    TTRSL LL

    n

    SDAAEIKIKISRVKLNKIKII ))()((

    Recursive Ray Tracing

    Also trace secondary rays from hit surfaces Global illumination from mirror reflection and

    transparency

  • 7/27/2019 04b Lighting Full

    39/48

    ThomasFunkhouser200

    0

    Mirror reflections

    Trace secondary ray in direction of mirror reflection Evaluate radiance along secondary ray and

    include it into illumination model

    TTRSL LL

    n

    SDAAEIKIKISRVKLNKIKII ))()((

    Radiancefor mirror

    reflection ray

    IR

  • 7/27/2019 04b Lighting Full

    40/48

    ThomasFunkhouser200

    0

    Transparency

    Trace secondary ray in direction of refraction Evaluate radiance along secondary ray and

    include it into illumination model

    TTRSL LL

    n

    SDAAEIKIKISRVKLNKIKII ))()((

    Radiance forrefraction ray

    IT

  • 7/27/2019 04b Lighting Full

    41/48

    ThomasFunkhouser200

    0

    TTRSL LL

    n

    SDAAEIKIKISRVKLNKIKII ))()((

    Transparency

    Transparency coefficient is fraction transmitted KT = 1 if object is translucent, KT = 0 if object is opaque

    0 < KT < 1if object is semi-translucent

    TransparencyCoefficient

    KT

  • 7/27/2019 04b Lighting Full

    42/48

    ThomasFunkhouser200

    0

    Refractive Transparency

    For thin surfaces, can ignore change in direction Assume light travels straight through surface

    N

    Li

    T

    r

    hr

    hi

    i

    TLT

  • 7/27/2019 04b Lighting Full

    43/48

    ThomasFunkhouser200

    0

    Refractive Transparency

    N

    L

    i

    Tr

    hr

    hi

    LNT

    r

    i

    ri

    r

    i

    h

    h

    h

    h )coscos(

    For solid objects, apply Snells law:

    iirr sinsin hh

  • 7/27/2019 04b Lighting Full

    44/48

    ThomasFunkhouser2000

    Recursive Ray Tracing

    Ray tree represents illumination computation

    Ray traced through scene Ray tree

    TTRSL LL

    n

    SDAAEIKIKISRVKLNKIKII ))()((

  • 7/27/2019 04b Lighting Full

    45/48

    ThomasFunkhouser2000

    Recursive Ray Tracing

    Ray tree represents illumination computation

    Ray traced through scene Ray tree

    TTRSL LL

    n

    SDAAEIKIKISRVKLNKIKII ))()((

  • 7/27/2019 04b Lighting Full

    46/48

    ThomasFunkhouser2000

    Recursive Ray Tracing

    Image RayTrace(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(scene, ray, hit);

    }}

    return image;

    }

    GetColorcalls RayTrace recursively

  • 7/27/2019 04b Lighting Full

    47/48

    ThomasFunkhouser2000

    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

    More on global illumination later!

    All of this is an approximationso that it is practical to compute

  • 7/27/2019 04b Lighting Full

    48/48

    ThomasFunkhouser2000

    Illumination Terminology

    Radiant power [flux] (F) Rate at which light energy is transmitted (in Watts).

    Radiant Intensity (I) Power radiated onto a unit solid angle in direction (in Watts/sr)

    e.g.: energy distribution of a light source (inverse square law)

    Radiance (L) Radiant intensity per unit projected surface area (in Watts/m2sr)

    e.g.: light carried by a single ray (no inverse square law)

    Irradiance (E) Incident flux density on a locally planar area (in Watts/m2 )

    e.g.: light hitting a surface along a

    Radiosity (B) Exitant flux density from a locally planar area (in Watts/ m2 )