Light in Unity 1
Introduction to Lighting in Unity and Lambert Lighting
Lighting in Computer Graphics is all about calculating the Pixel color and its intensity to simulate lighting in real life.
In real life the brightness of an object is dependent on :
- Its orientation relative to the light source (e.g.: the Sun)
- Its orientation relative to the eye (viewer)
In Computer graphics, we try to simulate lighting by simulating those two factors providing the same effect we get in real life.
Understanding light is essential for shader coding, Augmented and Virtual Reality Development.
Lambert Lighting
Developed by Lambert
Lambert Lighting is the conceptual model for simulating Light
The model in Lehman Terms can be described as:
A surface is lit according to the angle between the surface normal vector and the light source vector
Cosine of the angle between the surface normal and the light source defines the intensity of the light.
Image Source: GameDev.net
When the angle between the Surface Normal and the light source is 0 then the Cosine of the angle will return 1, which will turn the brightness all the way.
Image Source: scratchpixel.com
The light intensity at a surface (pixel or vertex in Unity) in the Lambert model is determined by the dot product of the Surface Normal Vector* Light Source Vector.
Lambert lighting can be called in a CGPROGRAM
by adding it to the pragma compiler directive
#pragma surface surf Lambert
Or if you want to implement Lambert Lighting in a CGPROGRAM
#pragma surface surf LambertLighting
half4 LightingLambertLighting(SurfaceOutput s, half3 lightDirection,half LossFactor)
{
half4 returnedColor;
half NormalDotLightDirection;
NormalDotLightDirection=dot(s.Normal,lightDirection);
returnedColor.rgb=s.Albedo*_LightColor0*(NormalDotLightDirection*LossFactor);
returnedColor.a=s.Alpha;
return returnedColor;
}
Rendering Pipeline In Unity
Mesh Anatomy in Unity
Shaders Data types & Packed Arrays