Last Time - PowerPoint PPT Presentation

About This Presentation
Title:

Last Time

Description:

Flat shading. Gouraud interpolation. Phong interpolation. New hardware ... Flat shading. Compute shading at a representative point and apply to whole polygon ... – PowerPoint PPT presentation

Number of Views:39
Avg rating:3.0/5.0
Slides: 24
Provided by: Stephen787
Category:
Tags: flat | last | time

less

Transcript and Presenter's Notes

Title: Last Time


1
Last Time
  • Local Shading
  • Diffuse term
  • Specular term
  • All together
  • OpenGL brief overview

2
Today
  • Shading Interpolation
  • More on light sources
  • Texture Mapping
  • Homework 4 due

3
Shading so Far
  • So far, we have discussed illuminating a single
    point
  • We have assumed that we know
  • The point
  • The surface normal
  • The viewer location (or direction)
  • The light location (or direction)
  • But commonly, normal vectors are only given at
    the vertices
  • It is also expensive to compute lighting for
    every point

4
Shading Interpolation
  • Several options
  • Flat shading
  • Gouraud interpolation
  • Phong interpolation
  • New hardware provides other options

5
Flat shading
  • Compute shading at a representative point and
    apply to whole polygon
  • OpenGL uses one of the vertices
  • Advantages
  • Fast - one shading computation per polygon, fill
    entire polygon with same color
  • Disadvantages
  • Inaccurate
  • What are the artifacts?

6
Gouraud Shading
  • Shade each vertex with its own location and
    normal
  • Linearly interpolate the color across the face
  • Advantages
  • Fast - incremental calculations when rasterizing
  • Much smoother - use one normal per shared vertex
    to get continuity between faces
  • Disadvantages
  • What are the artifacts?
  • Is it accurate?

7
Phong Interpolation
  • Interpolate normals across faces
  • Shade each pixel
  • Advantages
  • High quality, narrow specularities
  • Disadvantages
  • Expensive
  • Still an approximation for most surfaces
  • Not to be confused with Phongs specularity model

8
(No Transcript)
9
Shading and OpenGL
  • OpenGL defines two particular shading models
  • Controls how colors are assigned to pixels
  • glShadeModel(GL_SMOOTH) interpolates between the
    colors at the vertices (the default, Gouraud
    shading)
  • glShadeModel(GL_FLAT) uses a constant color
    across the polygon

10
The Current Generation
  • Current hardware allows you to break from the
    standard illumination model
  • Programmable Vertex Shaders allow you to write a
    small program that determines how the color of a
    vertex is computed
  • Your program has access to the surface normal and
    position, plus anything else you care to give it
    (like the light)
  • You can add, subtract, take dot products, and so
    on

11
The Full Story
  • We have only touched on the complexities of
    illuminating surfaces
  • The common model is hopelessly inadequate for
    accurate lighting (but its fast and simple)
  • Consider two sub-problems of illumination
  • Where does the light go? Light transport
  • What happens at surfaces? Reflectance models
  • Other algorithms address the transport or the
    reflectance problem, or both
  • Much later in class, or a separate course

12
Light Sources
  • Two aspects of light sources are important for a
    local shading model
  • Where is the light coming from (the L vector)?
  • How much light is coming (the I values)?
  • Various light source types give different answers
    to the above questions
  • Point light source Light from a specific point
  • Directional Light from a specific direction
  • Spotlight Light from a specific point with
    intensity that depends on the direction
  • Area light Light from a continuum of points
    (later in the course)

13
Point and Directional Sources
  • Point light L(x) plight - x
  • The L vector depends on where the surface point
    is located
  • Must be normalized - slightly expensive
  • To specify an OpenGL light at 1,1,1
  • Directional light L(x) Llight
  • The L vector does not change over points in the
    world
  • OpenGL light traveling in direction 1,1,1 (L is
    in opposite direction)

Glfloat light_position 1.0, 1.0, 1.0, 1.0
glLightfv(GL_LIGHT0, GL_POSITION,
light_position)
Glfloat light_position 1.0, 1.0, 1.0, 0.0
glLightfv(GL_LIGHT0, GL_POSITION,
light_position)
14
Spotlights
cut-off
direction
  • Point source, but intensity depends on L
  • Requires a position the location of the source
  • Requires a direction the center axis of the
    light
  • Requires a cut-off how broad the beam is
  • Requires and exponent how the light tapers off
    at the edges of the cone
  • Intensity scaled by (LD)n

glLightfv(GL_LIGHT0, GL_POSITION, light_posn)
glLightfv(GL_LIGHT0, GL_SPOT_DIRECTION,
light_dir)
glLightfv(GL_LIGHT0, GL_SPOT_CUTOFF, 45.0)
glLightfv(GL_LIGHT0, GL_SPOT_EXPONENT, 1.0)
15
Mapping Techniques
  • Consider the problem of rendering a soup can
  • The geometry is very simple - a cylinder
  • But the color changes rapidly, with sharp edges
  • With the local shading model, so far, the only
    place to specify color is at the vertices
  • To do a soup can, would need thousands of
    polygons for a simple shape
  • Same thing for an orange simple shape but
    complex normal vectors
  • Solution Mapping techniques use simple geometry
    modified by a mapping of some type

16
Texture Mapping
  • The soup tin is easily described by pasting a
    label on the plain cylinder
  • Texture mapping associates the color of a point
    with the color in an image the texture
  • Soup tin Each point on the cylinder get the
    labels color
  • Question to address Which point of the texture
    do we use for a given point on the surface?
  • Establish a mapping from surface points to image
    points
  • Different mappings are common for different
    shapes
  • We will, for now, just look at triangles
    (polygons)

17
Basic Mapping
  • The texture lives in a 2D space
  • Parameterize points in the texture with 2
    coordinates (s,t)
  • These are just what we would call (x,y) if we
    were talking about an image, but we wish to avoid
    confusion with the world (x,y,z)
  • Define the mapping from (x,y,z) in world space to
    (s,t) in texture space
  • To find the color in the texture, take an (x,y,z)
    point on the surface, map it into texture space,
    and use it to look up the color of the texture
  • With polygons
  • Specify (s,t) coordinates at vertices
  • Interpolate (s,t) for other points based on given
    vertices

18
Example Mappings
19
Texture Interpolation
  • Specify where the vertices in world space are
    mapped to in texture space
  • Linearly interpolate the mapping for other points
    in world space
  • Straight lines in world space go to straight
    lines in texture space

t
s
Texture map
Triangle in world space
20
Interpolating Coordinates
(x3, y3), (s3, t3)
(x1, y1), (s1, t1)
(x2, y2), (s2, t2)
21
Pipelines and Texture Mapping
  • Texture mapping is done in canonical screen space
    as the polygon is rasterized
  • When describing a scene, you assume that texture
    interpolation will be done in world space
  • Which property of perspective projection means
    that the wrong thing will happen if we apply
    our simple interpolations from the previous
    slide?
  • Perspective correct texture mapping does the
    right thing, but at a cost
  • Is it a problem with orthographic viewing?

22
Basic OpenGL Texturing
  • Specify texture coordinates for the polygon
  • Use glTexCoord2f(s,t) before each vertex
  • Eg glTexCoord2f(0,0) glVertex3f(x,y,z)
  • Create a texture object and fill it with texture
    data
  • glGenTextures(num, indices) to get identifiers
    for the objects
  • glBindTexture(GL_TEXTURE_2D, identifier) to bind
    the texture
  • Following texture commands refer to the bound
    texture
  • glTexParameteri(GL_TEXTURE_2D, , ) to specify
    parameters for use when applying the texture
  • glTexImage2D(GL_TEXTURE_2D, .) to specify the
    texture data (the image itself)

MORE
23
Basic OpenGL Texturing (cont)
  • Enable texturing glEnable(GL_TEXTURE_2D)
  • State how the texture will be used
  • glTexEnvf()
  • Texturing is done after lighting
  • Youre ready to go
Write a Comment
User Comments (0)
About PowerShow.com