Ambient Lighting Algorithm

From Unify Community Wiki
Jump to: navigation, search


Disclaimer and Description

This is a description of the conclusion of some reverse-engineering work. It may not be entirely accurate beyond a certain scope, as it is not based on a direct observation of the source code of the Unity Engine. Please feel free to revise this information if you have better knowledge of the technical underpinnings behind it.

The following describes Unity's ambient lighting color mixing algorithm. It seems to be accurate for lighting intensities from 0 to 1 — as well as above 1 — and regular normalized [0,1] RGB values of colors.

The Algorithm

Given an object that is subject to a lighting condition of color C and intensity J, in a scene with ambient light of color A, the following describes the color P of a pixel of that object. T represents the color of the base texture of the object (i.e. the color that the pixel would be if the object was Self-Illuminated / Unlit).

P = T * (A + 2*C*J)

or, in words,

Final Pixel Color = (Base Texture Color) * [ (Ambient Lighting Color) + (2 * Object Lighting Intensity * Object Lighting Color) ].

Note that color multiplication is a per-channel operation. That is, <r1, g1, b1> * <r2, g2, b2> = <r1r2, g1g2, b1b2>.

Personal tools
Namespaces

Variants
Actions
Navigation
Extras
Tools