24. Lighting - 2
Dated: 30-06-2025
Clamping Color
Values
Clamping
is fast, but it tends to lose fidelity in the scene, particularly in areas where we would want and expect subtle changes as the light intensities interact, but end up with those interactions getting eradicated because the differences are all getting clamped out by the graphics hardware.
Scaling Color
Values by Intensity
Imagine a color
\(c = (r, g, b)\) with \(g > 1\) then, after scaling down other components by the largest, we have
This reduces intensity
but maintains hue
and saturation
.
Shifting Color
Values to Maintain Saturation
A Color Cube
Brightness = Gray Vector
Compute a gray vector in the direction of pure gray (the black–white diagonal of the RGB cube
). This is something like \((0.6, 0.6, 0.6)\) — a color with no hue but same brightness as the original.
Preserve Intensity
You want this grayscale vector to have the same brightness
as the original color.
Draw a Ray Perpendicular to the Gray
Take the original color and draw a ray from the grayscale vector perpendicular
to the grayscale direction. This ray represents how saturated the original color was.
Clip
Extend this ray until it hits the boundaries of the \([0,1]\) RGB cube
. This gives you a new color that's still inside the valid range but tries to preserve brightness
and saturation
as much as possible.
Negative Colors
and Darklights
Darklights
are nothing more than lights in which one or more of the color values are negative. Darklights
can also be used to affect a scene if we want to filter out a specific rgb
color. If we wanted to get a night vision effect, we could use a darklight
with negative red and blue values, for example, which would just leave the green channel.
Alpha Blending
Alpha value determines opaqueness. 0xFF
(255
) means that the surface is completely opaque
and 0x00
(0
) means it is transparent
.