Projection Matrices and Simple Shadows - PowerPoint PPT Presentation

1 / 48
About This Presentation
Title:

Projection Matrices and Simple Shadows

Description:

This strategy allows us to use standard ... DOP. DOP. near plane. far plane. object. clipping. volume. z = -1. z = 1. x = -1. x = 1. distorted object ... – PowerPoint PPT presentation

Number of Views:45
Avg rating:3.0/5.0
Slides: 49
Provided by: LeeMcC
Category:

less

Transcript and Presenter's Notes

Title: Projection Matrices and Simple Shadows


1
Projection Matrices and Simple Shadows
2
Normalization
  • Rather than derive a different projection matrix
    for each type of projection, we can convert all
    projections to orthogonal projections with the
    default view volume
  • This strategy allows us to use standard
    transformations in the pipeline and makes for
    efficient clipping

3
Pipeline View
modelview transformation
projection transformation
perspective division
4D ? 3D
nonsingular
clipping
projection
3D ? 2D
against default cube
4
Notes
  • We stay in four-dimensional homogeneous
    coordinates through both the modelview and
    projection transformations
  • Both these transformations are nonsingular
  • Default to identity matrices (orthogonal view)
  • Normalization lets us clip against simple cube
    regardless of type of projection
  • Delay final projection until end
  • Important for hidden-surface removal to retain
    depth information as long as possible

5
Orthogonal Normalization
  • glOrtho(left,right,bottom,top,near,far)

normalization ? find transformation to
convert specified clipping volume to default
6
Orthogonal Matrix
  • Two steps
  • Move center to origin
  • T(-(leftright)/2, -(bottomtop)/2,(nearfar)/2))
  • Scale to have sides of length 2
  • S(2/(left-right),2/(top-bottom),2/(near-far))

P ST
7
Final Projection
  • Set z 0
  • Equivalent to the homogeneous coordinate
    transformation
  • Hence, general orthogonal projection in 4D is

Morth
P MorthST
8
Oblique Projections
  • The OpenGL projection functions cannot produce
    general parallel projections such as
  • However if we look at the example of the cube it
    appears that the cube has been sheared
  • Oblique Projection Shear Orthogonal Projection

9
General Shear
top view
  • side view

10
Shear Matrix
  • xy shear (z values unchanged)
  • Projection matrix
  • General case

H(q,f)
P Morth H(q,f)
P Morth STH(q,f)
11
Equivalency
12
Effect on Clipping
  • The projection matrix P STH transforms the
    original clipping volume to the default clipping
    volume

object
top view
z 1
DOP
DOP
x -1
x 1
far plane
z -1
clipping volume
near plane
distorted object (projects correctly)
13
Simple Perspective
  • Consider a simple perspective with the COP at the
    origin, the near clipping plane at z -1, and a
    90 degree field of view determined by the planes
  • x ?z, y ?z

14
Perspective Matrices
  • Simple projection matrix in homogeneous
    coordinates
  • Note that this matrix is independent of the far
    clipping plane

M
15
Generalization
  • N

after perspective division, the point (x, y, z,
1) goes to
x x/z y y/z Z -(ab/z)
which projects orthogonally to the desired point
regardless of a and b
16
Picking a and b
If we pick
a
b
the near plane is mapped to z -1 the far plane
is mapped to z 1 and the sides are mapped to x
? 1, y ? 1
Hence the new clipping volume is the default
clipping volume
17
Normalization Transformation
distorted object projects correctly
  • original clipping
  • volume

original object
new clipping volume
18
Normalization and Hidden-Surface Removal
  • Although our selection of the form of the
    perspective matrices may appear somewhat
    arbitrary, it was chosen so that if z1 gt z2 in
    the original clipping volume then the for the
    transformed points z1 gt z2
  • Thus hidden surface removal works if we first
    apply the normalization transformation
  • However, the formula z -(ab/z) implies that
    the distances are distorted by the normalization
    which can cause numerical problems especially if
    the near distance is small

19
OpenGL Perspective
  • glFrustum allows for an unsymmetrical viewing
    frustum (although gluPerspective does not)

20
OpenGL Perspective Matrix
  • The normalization in glFrustum requires an
    initial shear to form a right viewing pyramid,
    followed by a scaling to get the normalized
    perspective volume. Finally, the perspective
    matrix results in needing only a final orthogonal
    transformation

P NSH
our previously defined perspective matrix
shear and scale
21
Why do we do it this way?
  • Normalization allows for a single pipeline for
    both perspective and orthogonal viewing
  • We stay in four dimensional homogeneous
    coordinates as long as possible to retain
    three-dimensional information needed for
    hidden-surface removal and shading
  • We simplify clipping

22
Simple Shadows
  • A shadow is created when a point is not
    illuminated by any light source
  • Default view assumes the flashlight in the eye
    model
  • Complete physical reality is difficult so
    alternative methods have be created

23
Creating simple shadows
  • Lets assume that the shadow is projected onto a
    surface where y 0
  • The shadow polygon is the projection of the
    original polygon onto the surface where the COP
    is the light source

24
Creating simple shadows
  • A projection from a frame where the light source
    is at the origin will give us the vertices of the
    shadow polygon

25
Creating simple shadows
  • Algorithm
  • Draw polygon
  • Create a projection matrix for the shadow
  • Translate back (from origin)
  • Project
  • Move light to origin
  • Draw polygon again
  • Restore previous state

26
Creating simple shadows
  • GLfloat m16
  • for(i0ilt15i) mi0.0
  • m0m5m101.0
  • m7 -1.0/y1
  • glColor3fv(polygon_color)
  • glBegin(GL_POLYGON)
  • drawStuffHere()
  • glEnd()
  • glMatrixMode(GL_MODELVIEW)
  • glPushMatrix()
  • glTranslatef(x1,y1,z1)
  • glMultMatrixf(m)
  • glTranslate(-x1,-y1,-z1)
  • glColor3f(shadow_color)
  • glBegin(GL_POLYGON)
  • drawStuffHere()
  • glEnd()
  • glPopMatrix()

27
Why we need shading
  • Suppose we build a model of a sphere using many
    polygons and color it with glColor. We get
    something like
  • But we want

28
Shading
  • Why does the image of a real sphere look like
  • Light-material interactions cause each point to
    have a different color or shade
  • Need to consider
  • Light sources
  • Material properties
  • Location of viewer
  • Surface orientation

29
Scattering
  • Light strikes A
  • Some scattered
  • Some absorbed
  • Some of scattered light strikes B
  • Some scattered
  • Some absorbed
  • Some of this scattered
  • light strikes A
  • and so on

30
Rendering Equation
  • The infinite scattering and absorption of light
    can be described by the rendering equation
  • Cannot be solved in general
  • Ray tracing is a special case for perfectly
    reflecting surfaces
  • Rendering equation is global and includes
  • Shadows
  • Multiple scattering from object to object

31
Global Effects
shadow
multiple reflection
translucent surface
32
Local vs Global Rendering
  • Correct shading requires a global calculation
    involving all objects and light sources
  • Incompatible with pipeline model which shades
    each polygon independently (local rendering)
  • However, in computer graphics, especially real
    time graphics, we are happy if things look
    right
  • Exist many techniques for approximating global
    effects

33
Light-Material Interaction
  • Light that strikes an object is partially
    absorbed and partially scattered (reflected)
  • The amount reflected determines the color and
    brightness of the object
  • A surface appears red under white light because
    the red component of the light is reflected and
    the rest is absorbed
  • The reflected light is scattered in a manner that
    depends on the smoothness and orientation of the
    surface

34
Light Sources
  • General light sources are difficult to work with
    because we must integrate light coming from all
    points on the source

35
Simple Light Sources
  • Point source
  • Model with position and color
  • Distant source infinite distance away
    (parallel)
  • Spotlight
  • Restrict light from ideal point source
  • Ambient light
  • Same amount of light everywhere in scene
  • Can model contribution of many sources and
    reflecting surfaces

36
Surface Types
  • The smoother a surface, the more reflected light
    is concentrated in the direction a perfect mirror
    would reflected the light
  • A very rough surface scatters light in all
    directions

rough surface
smooth surface
37
Phong Model
  • A simple model that can be computed rapidly
  • Has three components
  • Diffuse
  • Specular
  • Ambient
  • Uses four vectors
  • To source
  • To viewer
  • Normal
  • Perfect reflector

38
Ideal Reflector
  • Normal is determined by local orientation
  • Angle of incidence angle of reflection
  • The three vectors must be coplanar

r 2 (l n ) n - l
39
Lambertian Surface
  • Perfectly diffuse reflector
  • Light scattered equally in all directions
  • Amount of light reflected is proportional to the
    vertical component of incoming light
  • reflected light cos qi
  • cos qi l n if vectors normalized
  • There are also three coefficients, kr, kb, kg
    that show how much of each color component is
    reflected

40
Specular Surfaces
  • Most surfaces are neither ideal diffusers nor
    perfectly specular (ideal reflectors)
  • Smooth surfaces show specular highlights due to
    incoming light being reflected in directions
    concentrated close to the direction of a perfect
    reflection

specular highlight
41
Modeling Specular Relections
  • Phong proposed using a term that dropped off as
    the angle between the viewer and the ideal
    reflection increased

Ir ks I cosaf
f
shininess coef
reflected intensity
incoming intensity
absorption coef
42
The Shininess Coefficient
  • Values of a between 100 and 200 correspond to
    metals
  • Values between 5 and 10 give surface that look
    like plastic

cosa f
90
f
-90
43
Ambient Light
  • Ambient light is the result of multiple
    interactions between (large) light sources and
    the objects in the environment
  • Amount and color depend on both the color of the
    light(s) and the material properties of the
    object
  • Add ka Ia to diffuse and specular terms

reflection coef
intensity of ambient light
44
Distance Terms
  • The light from a point source that reaches a
    surface is inversely proportional to the square
    of the distance between them
  • We can add a factor of the
  • form 1/(ad bd cd2) to
  • the diffuse and specular
  • terms
  • The constant and linear terms soften the effect
    of the point source

45
Light Sources
  • In the Phong Model, we add the results from each
    light source
  • Each light source has separate diffuse, specular,
    and ambient terms to allow for maximum
    flexibility even though this form does not have a
    physical justification
  • Separate red, green and blue components
  • Hence, 9 coefficients for each point source
  • Idr, Idg, Idb, Isr, Isg, Isb, Iar, Iag, Iab

46
Material Properties
  • Material properties match light source properties
  • Nine absorbtion coefficients
  • kdr, kdg, kdb, ksr, ksg, ksb, kar, kag, kab
  • Shininess coefficient a

47
Adding up the Components
  • For each light source and each color component,
    the Phong model can be written (without the
    distance terms) as
  • I kd Id l n ks Is (v r )a ka Ia
  • For each color component
  • we add contributions from
  • all sources

48
Example
Only differences in these teapots are the
parameters in the Phong model
Write a Comment
User Comments (0)
About PowerShow.com