The color of an object is based on:
- The reflective properties of the object
- The color, intensity, and location of any light sources
- Ambient
- General light in an image
- Comes from all locations equally
- Point Light Source
- Comes from a specific location (far away)
- Models real world reflection by breaking reflection into 3 parts
- Ambient
- Diffuse (point source)
- Specular (point source)
I = Ambient + Diffuse + Specular
- A: Ambient light (0-255)
- Ka: constant of ambient reflection (0-1)
Ambient = A*Ka
- Reflection of a point source
- Light is reflected back evenly in all directions
- Matte/dull objects
- 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)
- 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 (θ)
- 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
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.