Light in Unity 1
Introduction to Lighting in Unity and Lambert Lighting

Light in Unity 1



Introduction to Lighting in Unity and Lambert Lighting
No alt text provided for this image

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 :

  1. Its orientation relative to the light source (e.g.: the Sun)
  2. 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

No alt text provided for this image

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
Lambert Lighting

Cosine of the angle between the surface normal and the light source defines the intensity of the light.

No alt text provided for this image
No alt text provided for this image


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.

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


 Lambert model is determined by the dot product of the Surface Normal Vector* Light Source Vector

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
Rendering Pipeline In Unity


Mesh Anatomy in Unity
Mesh Anatomy in Unity


Shaders' Data Types
Shaders Data types & Packed Arrays


To view or add a comment, sign in

More articles by Ahmed Schrute

  • Genetic Evolution (Behavioral Traits) Simulation using Unity3D

    This is a simulation of Genetic Evolution with a focus on Behavioral traits passed between generation, In this…

  • Vertex Fragment Shader Structure

    This article is a continuum of shader coding articles using Shader lab in Unity, I highly recommend you visit my two…

  • Rendering Queues in Unity

    A lot of times, we need to render certain objects(Player, Gem …etc) to the front even there is an object overlaying our…

  • Normal Mapping

    If you have read the Lighting in Unity 1 and Lighting in Unity2, you have seen how important normal vectors are for…

    2 Comments
  • Light in Unity 2

    Intro to Blinn Phong Lighting model In the previous article, We have been through Lambert Lighting Model and how it…

  • Shader Variables Data Types in Unity

    Why we use different variable types when writing shaders? Shader code is for every pixel(or vertex), therefor efficient…

  • Understanding Mesh Anatomy in Unity

    In order to shade a model we need to understand its geometric structure Let’s take a cube as an example of a mesh model…

  • Rendering Pipeline In Unity

    Introduction to Rendering Pipeline in Unity Rendering Rendering is the process of drawing a scene on the computer…

  • Unity CPU Profiling

    Enhancing unity CPU performance I usually have a routine before I start inspecting the CPU usage tap which is opening…

Explore content categories