Shadows via Projection - PowerPoint PPT Presentation

About This Presentation
Title:

Shadows via Projection

Description:

But in 'flying' the translation was in the saved matrix. ... Last time we will look at two mouse-based viewing interfaces. Click-and-drag rotation. ... – PowerPoint PPT presentation

Number of Views:32
Avg rating:3.0/5.0
Slides: 11
Provided by: glenngc
Category:

less

Transcript and Presenter's Notes

Title: Shadows via Projection


1
Shadows via Projection
  • Glenn G. ChappellCHAPPELLG_at_member.ams.org
  • U. of Alaska Fairbanks
  • CS 381 Lecture Notes
  • Wednesday, November 5, 2003

2
ReviewTwo Kinds of Interfaces
  • Now, about that translation
  • In our zoom pan, driving, the translation
    was done in the display function, not the saved
    matrix.
  • But in flying the translation was in the saved
    matrix.
  • Advanced interfaces can be divided into two
    categories
  • View the world interfaces.
  • We look at the scene.
  • Rotation and scaling are centered on the point we
    are looking at.
  • So the translation does not go in the saved
    matrix.
  • Examples
  • Driving from above.
  • Object manipulation.
  • Move in the world interfaces.
  • In these, we are explicitly inside the scene.
  • Rotation is centered on the camera.
  • So the translation goes in the saved matrix.
  • Examples
  • Flying.
  • Driving, where we appear to be inside the car.

3
ReviewMouse-Based Viewing 1/2
  • Last time we will look at two mouse-based viewing
    interfaces.
  • Click-and-drag rotation.
  • View an object and rotate it in an intuitive way
    with the mouse (click-and-drag).
  • Flying with the mouse.
  • Fly forward on mouse-button press.
  • Turn in the direction of the mouse position.
  • The first is a view the world type of
    interface. The second is a move in the world
    type of interface.
  • These facts have ramifications for how the
    interfaces are implemented. (See the previous
    slide.)
  • Both of these involve rotation about a line
    perpendicular to a vector computed from mouse
    positions.
  • First The vector is the difference between the
    current and previous mouse positions. (So we
    needed to save the mouse position.)
  • Second The vector is the difference between the
    current mouse position and the center of the
    screen.

4
ReviewMouse-Based Viewing 2/2
  • The following code was useful in both interfaces,
    for doing the perpendicular rotation.
  • // perprot
  • // Rotates about an axis in the x,y-plane,
    perpendicular to the given
  • // vector (vx, vy). Rotation amount is
    proportional to the length of
  • // the vector and to rotmultiplier.
  • void perprot(double rotmultiplier, double vx,
    double vy)
  • double len sqrt(vxvx vyvy)
  • glPushMatrix()
  • glRotated(rotmultiplierlen, -vy,vx,0.)
  • glMultMatrixd(your_matrix_variable)
  • glGetDoublev(GL_MODELVIEW_MATRIX,
    your_matrix_variable)
  • glPopMatrix()
  • glutPostRedisplay()

5
Shadows via ProjectionIntroduction 1/2
  • Now that we know something about transformation
    matrices, we can use them to draw shadows.
  • Covering shadows before covering lighting is a
    bit odd, of course.
  • This topic is covered in section 5.10 of the
    (blue) text. My presentation differs somewhat
    from that in the text.
  • What is a shadow?
  • Answer 1 A region where light is blocked.
  • Thats a great answer, but to use it, we need to
    know something about lighting. Maybe next week
  • Answer 2 The projection of the shape of an
    object on another object.
  • We say shape here, since we do not want to draw
    the shadow using the same colors as the original
    object.
  • We know (more or less) how to project onto a
    plane. We can use this knowledge to draw the
    shadow of an object on a plane.

6
Shadows via ProjectionIntroduction 2/2
  • We wish to find the matrix that projects onto a
    given plane from a given light position.
  • This is essentially the synthetic-camera model.
    The light is at the center of projection, and the
    plane is the image plane.
  • Does this mean that, with this method, objects
    will still cast shadows when they do not lie
    between the light and the plane? Yes, it does.

7
Shadows via ProjectionThe Math 1/2
  • To compute the proper projection matrix, we need
    the light position and an equation for the plane.
  • We represent the light position as a 4-D vector L
    in homogeneous form, as shown below.
  • The equation of a plane in 3-D space can be
    written as Ax By Cz D 0. We represent
    this with another 4-D vector P, as shown below.
  • A point V (expressed in homogeneous form) lies on
    the plane precisely when VP 0.

Plane EquationAx By Cz D 0P (A, B,
C, D)
Light PositionL (Lx, Ly, Lz , 1)
8
Shadows via ProjectionThe Math 2/2
  • Now, let k PL be the dot product of P and L.
  • The matrix that does the projecting is given
    below. On the left, we use matrix notation (which
    you may not be familiar with).
  • What do we do with this matrix?
  • It does projection, so we might be tempted to put
    it in OpenGLs projection transformation.
  • However, it does not set camera properties it
    places objects in the world. (A shadow is an
    object!)
  • So the matrix goes in model/view, after the
    viewing transformations, and before moving the
    object that casts the shadow.

9
Shadows via ProjectionSome Code
  • Look at shadowproj.cpp, on the web page, for code
    that uses this method to draw a shadow.
  • The light position is stored in the global
    lightpos.
  • The plane is specified by putting the coordinates
    of points in the global planepts.
  • Function findplane computes and returns the plane
    equation (A, B, C, D). This is called from
    init, where these values are stored in the global
    plane_eq.
  • Function makeshadowmatrix computes and returns
    the shadow projection matrix. This is also called
    from init, where the matrix is stored in the
    global shadowmat.
  • The object is drawn by drawobject.
  • The parameter is true if the object is to be
    drawn in normal color, false if it is to be drawn
    in gray.
  • This function is called twice once to draw the
    object, and once to draw the shadow.
  • The shadow matrix is used in function display.

10
Shadows via ProjectionIssues
  • If we draw the shadow on a polygon, then the
    depth test might give us trouble.
  • One solution is to disable the depth test before
    drawing the shadow. This only works if no part of
    the shadow is hidden by any previously drawn
    object.
  • The shadow, being an object, is not confined to
    the polygon it (supposedly) is cast on.
  • We can solve this using stenciling, a method
    for restricting drawing to certain portions of
    the frame buffer.
  • Shadows are not gray they are unlit.
  • To do shadows properly, we draw the unshadowed
    portion with full lighting, and the shadowed
    portion using only ambient light. More on this
    when we cover lighting.
  • Suppose we use this method to draw a shadow
    falling on a more complex object.
  • For each polygon the shadow falls on, we would
    need to compute a separate matrix and draw the
    object casting the shadow.
  • So this method is not recommended for casting
    shadows on complex objects. There are other
    shadowing methods more on these later.
Write a Comment
User Comments (0)
About PowerShow.com