Docsity

Shading Algorithms: Ron Goldman's Lecture Notes on Illumination and Shading, Study notes of Computer Graphics

Partial preview of the text

Download Shading Algorithms: Ron Goldman's Lecture Notes on Illumination and Shading and more Study notes Computer Graphics in PDF only on Docsity!

Shading Algorithms

Ron Goldman

Department of Computer Science

Rice University

Illumination and Shading

Standard Assumptions

  • Curved surfaces are approximated by planar polygons.
  • All light sources are point light sources (at infinity).

Illumination Models

  • Ambient Light
  • Diffuse Reflection (Scattering)
  • Specular Reflection

Shading Models

  • Uniform (Flat)
  • Gouraud
  • Phong

Uniform Shading

Assumptions

  1. The surfaces really are polygonal.
    • N = surface normal = constant
  2. Light source at infinity
    • L = vector to light source = constant
    • L • N = constant
    • R = 2( L • N ) N − L = constant
  3. Eye at infinity
    • V = vector to eye = constant
    • N • V = constant
    • R • V = constant

Polygon Normals

Normal to a Polygon

• N = ( P

k

− O ) × ( P

k + 1

− O ) = P

k

× P

k + 1

− P

k

× O + P

k + 1

× O

Newell’s Formula

• N = P

k

× P

k + 1

k = 0

m

| N |= 2 × Area ( Polygon ) (Green’s Theorem)

  • Avoids problem of collinear vertices

O

P

2 P 1

P

3

Gouraud Shading

Purpose

  • To Reduce Mach Bands

Method

  • Linear Interpolation of Intensities
  • Incremental Computations -- Only One Addition per Pixel (Fast!)

Strategy

  1. Compute intensity at vertices, using an average unit normal vector.

N

vertex

N

polygon vertex ∈ Polygon

N

vertex ∈ Polygon polygon

(Normalized Average)

  1. Interpolate intensity along edges.
  2. Interpolate intensity along scan lines.

Observation

  • Polygon intensities agree along common edges.
  • Integrates well with hidden surface scan line algorithm.

Polygon

Scan Line

Vertex

Vertex

Edge

Vertex Vertex

Vertex

Vertex

Edge

Edge

Edge

Edge

Edge

Scan Line

Incremental Intensity Computation

Along a Scan Line

P

1

= ( x 1

, y 1

, z 1

) P

2

= ( x 2

, y 2

, z 2

( x , y , z ) ( x^ +^ Δ x ,^ y^ +^ Δ y ,^ z^ +^ Δ z )

  • • • •

Δ x = 1

}

I

1

I

2

Δ x = 1 ⇒ Δ t = 1 /( x 2

− x 1

Δ I = ( I

2

− I

1

)Δ t = ( I 2

− I

1

) /( x 2

− x 1

Next Scan Line

P

1

= ( x 1

, y 1

, z 1

P

2

= ( x 2

, y 2

, z 2

( x , y , z )

( x + Δ x , y + Δ y , z + Δ z )

Δ y = 1

I

2

I

1

Δ y = 1 ⇒ Δ t = 1 /( y 2

− y 1

Δ I = ( I

2

− I

1

)Δ t = ( I 2

− I

1

) /( y 2

− y 1

Orientation Dependence and Independence

Problem

  • Gouraud (Phong) Shading is Orientation Dependent

Solution

  • Subdivide the Polygons into Triangles
  • Gouraud (Phong) Shading for Triangles is Orientation Independent

Note

  • Shading Algorithm Depends on the Particular Triangular Subdivision
  • Shading Algorithm Gives Different Results for Different Subdivisions

Barycentric Coordinates and Coordinate Independence

( 1 − t ) I 1

  • tI 2

I

1

I

2

I

3 €

I

( 1 − s ) I 1

  • sI 3

I

1

I

2

I

3 €

I

β 1

β 2

β 3

I = ( 1 − u ) ( 1 − t ) I 1

  • tI 2
  • u ( 1 − s ) I 1

  • sI 3

I = β 1

I

1

  • β 2

I

2

  • β 3

I

3

I = ( 1 − u )( 1 − t ) + u ( 1 − s )

β 1

I

1

  • ( 1 − u ) t

β 2

I

2

  • ( us )

β 3

I

3

Barycentric Coordinates

β 1

  • β 2

  • β 3

P = β 1

P

1

  • β 2

P

2

  • β 3

P

3

= P

1

  • β 2

( P

2

− P

1

) + β 3

( P

3

− P

1

β 1

,β 2

,β 3

unique

Naive Phong Shading

Purpose

  • To Reduce Mach Bands
  • To Mimic Curved Surfaces

Method

  • Linear Interpolation of Normal Vectors
  • Incremental Computation of Normal Vectors

Strategy

  1. Compute unit normals at vertices by averaging the unit normals of the

polygons to which the vertex belongs.

N

vertex

N

polygon vertex ∈ Polygon

N

vertex ∈ Polygon polygon

(Normalized Average)

  1. Interpolate normals along edges. (Renormalize)
  2. Interpolate normals along scan lines. (Renormalize)
  3. Use normals to calculate intensities.

Incremental Normal Computation

Along a Scan Line

P

1

= ( x 1

, y 1

, z 1

) P

2

= ( x 2

, y 2

, z 2

( x , y , z ) ( x^ +^ Δ x ,^ y^ +^ Δ y ,^ z^ +^ Δ z )

  • • • •

Δ x = 1

}

N

1

N

2

Δ x = 1 ⇒ Δ t = 1 /( x 2

− x 1

Δ N = ( N

2

− N

1

)Δ t = ( N 2

− N

1

) /( x 2

− x 1

Next Scan Line

P

1

= ( x 1

, y 1

, z 1

P

2

= ( x 2

, y 2

, z 2

( x , y , z )

( x + Δ x , y + Δ y , z + Δ z )

Δ y = 1

N

2

N

1

Δ y = 1 ⇒ Δ t = 1 /( y 2

− y 1

Δ N = ( N

2

− N

1

)Δ t = ( N 2

− N

1

) /( y 2

− y 1

Clever Implementation -- Diffuse Reflection

Diffuse Reflection

I

diffuse

= I

p

k d

( L • N ) = I

p

k d

( 1 − t )( L • N 1

) + t ( L • N 2

( 1 − t ) N 1

  • t N 2

J ( t ) = ( 1 − t )( L • N 1

J

1

  • t ( L • N 2

J

2

-- Similar to Gouraud (Scalars)

-- Avoids Dot Products Along Scan Lines

N ( t ) = ( 1 − t ) N 1

  • t N 2

N

next

= N

current

  • Δ N -- Update Normal Vector Incrementally

d next

= N

next

= N

next

• N

next

-- Normalization by Newton’s Method

Clever Implementation -- Specular Reflection

Specular Reflection

I

specular

= I

p

k s

( R • V )

n

-- R = 2( L • N ) N − L

I

specular

= I

p

k s

2( L • N )( N • V ) − ( L • V )

( )

n

N = ( 1 − t ) N 1

  • t N 2

I

specular

= I

p

k s

2 ( 1 − t )( L • N 1

) + t ( L • N 2

{ }

Similar to Gouraud

( 1 − t )( V • N 1

) + t ( V • N 2

{ }

Similar to Gouraud

( 1 − t ) N 1

  • t N 2

2

− ( L • V )

Constant

n

( 1 − t ) N 1

  • t N 2

2

= N + Δ N

2

= ( N + Δ N ) • ( N + Δ N ) -- No Square Root

Spherical Linear Interpolation

Slerp

slerp ( N 1

, N

2

, t ) =

sin ( 1 − t ) φ ( )

sin( φ)

N

1

sin t φ ( )

sin( φ)

N

2

cos( φ) = N 1

• N

2

sin( φ) = 1 − ( N 1

• N

2

2

  • slerp maps unit vectors to unit vectors
    • more natural than linear interpolation

-- avoids square roots

  • Expand incrementally
    • Expand

Δsine and

Δcosine

  • Precompute

sin(Δ t φ) and

cos(Δ t φ)