VIEWS: 7 PAGES: 29

computer graphics and its application

• pg 1
```									1/26/2011 02:41
1

Graphics II 91.547

Session 4

UML
1/26/2011 02:41
2

The General Lighting Situation
Light
Source
Objects

Proj. Plane
COP

UML
1/26/2011 02:41
3

The Simplified OpenGL Model
Light
Source
Objects

Proj. Plane
For each object (or primitive)
For each light source enabled
Compute color at pixel
based on:
Source properties
Angle, distance to source
Angle to observer (COP)
Material properties
COP

UML
1/26/2011 02:41
4

Vectors Used by
Phong Lighting Model
COP

n

v
l
r
p

p  is an arbitrary point on a surface.
n  is the unit normal to the surface at p.
l  is a unit vector in the direction of the light source.
r is a unit vector in the direction of a perfectly (specular)
reflection
v is a unit vector in the direction of the viewer.

UML
1/26/2011 02:41
5

The Complete Phong Model

Specular term
Diffuse term

1
I                 (k d Ld (l  n)  ks Ls (r  v) )  ka La
a  bd  cd 2

Distance term                                       Ambient term

UML
1/26/2011 02:41
6

Rendered with Phong Model

UML
1/26/2011 02:41
7

Rendered with Ray Tracing

UML
1/26/2011 02:41
8

Where are the balls?

UML
1/26/2011 02:41
9

Where are the balls?

UML
1/26/2011 02:41
10

Shadows: How do we get them?*

1. Integration of shadow calculation with scan-line hidden
surface removal

2. Projection and clipping

5. Recursive ray tracing

*Classification due to Bergeron, 1986, quoted in Watt & Watt   UML
1/26/2011 02:41
11

Light Source

Object (polygon)

Plane of projection

UML
1/26/2011 02:41
12

Why is this model a simplification?

Penumbra

Umbra

Finite size
light source
object

UML
1/26/2011 02:41
13

 xL 
y 
 L                                xS 
Light Source
 zL                              y      Object (polygon)
1                                 S
                                  zS 
1
 
Projected point.

Plane of projection:   ax  by  cz  d  0
UML
1/26/2011 02:41
14

Calculating the projection matrix

 x L  0
 y  0       Light source moved to origin.
 L   
 z L  0
 1  1
                    pS

p   pS

a ( x  x L )  b ( y  y L )  c( z  z L )  d  0
UML
1/26/2011 02:41
15

Calculating the projection matrix
Substituting parametric expression for projection line into plane equation:

a (xS  x L )  b(yS  y L )  c(zS  z L )  d  0
 (axS  byS  czS )  (ax L  by L  cz L  d )  0
ax L  by L  cz L  d           dot
                          
 axS  byS  czS         axS  byS  czS
Substituting  back into line equation gives the following transformation:

dot 0    0                0
 0 dot 0                  0
                           
 0   0 dot                0
 a  b  c               0
                                                      UML
1/26/2011 02:41
16

Calculating the projection matrix:
Transform to frame where light is at origin, then transform back:

1   0 0 x L  dot 0  0                         0 1      0 0  xL 
0   1 0 y L   0 dot 0                         0 0      1 0  yL 
                                                                
0   0 1 zL   0   0 dot                        0 0      0 1  zL 
0   0 0 1   a  b  c                        0 0           1 
                                                       0 0      
Performing the matrix multiplication gives:

dot  ax L            bx L            cx L          dx L 
  ay             dot  by L           cy L          dy L 
      L

  az L               bz L         dot  cz L         dz L 
 a                   b               c           dot  d 
                                                            
UML
1/26/2011 02:41
17

1. Render all objects

2. For each light source
Clip to dimension of shadowed polygon

UML
1/26/2011 02:41
18

The Clipping Issue

Light
Plane 1

Plane 2

UML
1/26/2011 02:41
19

Using the stencil buffer

Color Planes        Z-buffer       Stencil
Planes         Planes

glEnable(GL_STENCIL_TEST);

Fragments will be drawn only if the stencil test passes.

UML
1/26/2011 02:41
20

Using the stencil buffer, contd.
void glStencilFunct(Glenum func, Glint ref,

func is one of:

GL_NEVER, GL_ALWAYS, GL_LESS, GL_LEQUAL,
GL_EQUAL, GL_GEQUAL, GL_GREATER, GL_NOTEQUAL

compares the stencil buffer value with the reference value.

Void glStencilOp(Glenum fail, Glenum zfail,
Glenum zpass);

specifies the action to take when a fragment passes or fails the
stencil test. Arguments are:

GL_KEEP, G_ZERO, GL_REPLACE,
GL_INCR, GL_DECR, GL_INVERT
UML
1/26/2011 02:41
21

Code example.

120 goto 240

UML
1/26/2011 02:41
22

0 N x N problem
0 Difficult to shadow onto anything other than flat surfaces
- Polygonal objects ok, but have to project onto the plane
of each polygon and clip to its edges.
0 Difficult to show shadow’s color
- Shadow is a “squashed” version of object doing the

UML
1/26/2011 02:41
23

Light Source

UML
1/26/2011 02:41
24

Determining whether a fragment is from an

Volume       Volume

COP

UML
1/26/2011 02:41
25

Determining whether a fragment is from an

Volume                 Volume

COP

For each fragment: Number of front facing shadow volume polygons minus
number of back facing shadow volume polygons (that pass depth test)
= zero if object is not in shadow.

UML
1/26/2011 02:41
26

The algorithm (for a single light source)

1. Enable color buffer and depth buffer for writing. Enable
depth testing

2. Set attributes for drawing in shadow. Turn off light source.

3. Render the entire scene.

4. Compute the polygons enclosing the shadow volume.

5. Disable color and depth buffer for writing. Leave depth test.

6. Clear the stencil buffer to zero.

7. Set the stencil function to always pass

UML
1/26/2011 02:41
27

The algorithm (for a single light source)
8. Set the stencil operation to increment if depth passes

9. Turn on back face culling

11. Set the stencil operation to decrement if depth passes

12. Turn on front face culling

14. Set the stencil function to test for zero and the stencil
operation to do nothing.

15. Enable the color and depth buffer for writing.
UML
16. Turn on the light and render the entire scene.
1/26/2011 02:41
28

0 Difficult if the shadowing object is a complex shape.
- Can project a separate shadow volume from each polygon
but this is very inefficient
- Ideally, shadow volume should be generated from vertices
forming silhouette of the object. This is a non-trivial
computation (see Watt & Watt for one algorithm).
0 If polygon renderer does not handle adjacent polygons
correctly, the stencil count can get mixed up resulting in

UML
1/26/2011 02:41
29

Let’s see if
they are
still awake

120 goto 240
240 goto 120

UML

```
To top