Skip to content

Latest commit

 

History

History
86 lines (67 loc) · 2.19 KB

0426.md

File metadata and controls

86 lines (67 loc) · 2.19 KB

Lighting

The color of an object is based on:

  1. The reflective properties of the object
  2. The color, intensity, and location of any light sources

Types of Light Sources

  • Ambient
    • General light in an image
    • Comes from all locations equally
  • Point Light Source
    • Comes from a specific location (far away)

Phong Reflection Model

  • Models real world reflection by breaking reflection into 3 parts
    • Ambient
    • Diffuse (point source)
    • Specular (point source)
  • I = Ambient + Diffuse + Specular

Ambient Reflection

  • A: Ambient light (0-255)
  • Ka: constant of ambient reflection (0-1)
  • Ambient = A*Ka

Diffuse Reflection

  • Reflection of a point source
  • Light is reflected back evenly in all directions
  • Matte/dull objects

Calculation

  • L: vector from the surface to the light (L-hat is normalized)
  • θ: angle between N (normal vector to surface) and L
  • cosθ = N-hat • L-hat
  • P: point light color (0-255)
  • Kd: constant of diffuse reflection (0-1)
  • Diffuse = P*Kd*(N-hat • L-hat)

!reflection

Specular Reflection

  • Reflects a point source in a specific direction
  • Models glossy/shiny surfaces
  • Strength of a specular reflection is based on:
    • The angle between R and V (α)
    • The angle between L and N (θ)

!specular

Calculation

  • L: vector from the surface to the light (L-hat is normalized)
  • θ: angle between N (normal vector to surface) and L
  • α: angle between R and V (α)
  • R: reflected vector from the surface

We want R-hat • V-hat.

R-hat = T + S
S = T - L-hat
R-hat = 2T - L-hat

cosθ = L • N
cosθ = |T| / |L|
cosθ = |T|

T = |T| * N

T-hat = (L-hat • N-hat) * N-hat
R-hat = 2 * (N-hat • L-hat) * N-hat - L-hat

cosα = (2 * (N-hat • L-hat) * N-hat - L-hat) • V-hat
Specular = P*Ks*[(2 * (N-hat • L-hat) * N-hat - L-hat) • V-hat]^x

x: arbitrary exponent used to simulate how quickly the reflection decreases

Color

I = Ambient + Diffuse + Specular
I = A*Ka + P*Kd*(N-hat • L-hat) + P*Ks*[(2 * (N-hat • L-hat) * N-hat - L-hat) • V-hat]^x

where I is a color.