← COURSE LIBRARY
Lighting · 35 min

The Dot Product as Light

BeginnerNeeds: VectorsNeeds: Normalization
Sign in to record mastery, quiz results and reviews for this course.Sign in

You will be able to

  • Explain N·L geometrically rather than as a formula you memorised.
  • Predict the shading result for any light direction without running the shader.
  • Identify why unnormalized normals break lighting and how to spot it in a frame.

The concept

The dot product is the single most reused operation in real-time shading. It measures how much two directions agree: 1 when parallel, 0 when perpendicular, negative when opposed. Lambert diffuse is nothing more than saturate(N·L) — the cosine of the angle between the surface normal and the direction to the light, clamped so back-facing light contributes nothing. Every facing test, Fresnel term, specular lobe and cone falloff in your renderer is built on the same operation.

In your engine

In Shader Graph, use a Dot Product node between Normal Vector (World) and the light direction from a Custom Function; in HLSL, `saturate(dot(normalWS, lightDir))` inside the fragment stage.

Practice (4)

Predict the result
N = (0,1,0), L = (0,1,0). What is saturate(dot(N,L))?
Predict the result
N = (0,1,0), L = (0,-1,0). What does an unclamped dot(N,L) return, and what does saturate do to it?
Find the bug
This shader shows blown-out lighting that changes brightness when the object is scaled. Which line is wrong?

1: float3 N = mul((float3x3)unity_ObjectToWorld, v.normal);
2: float3 L = normalize(_LightDir);
3: float d = saturate(dot(N, L));
Tune the value
The light sits 60° from the surface normal. What diffuse value should saturate(N·L) produce? (2 decimals)

Knowledge check

01Why is the dot product clamped in a diffuse term?
02dot(A,B) = 0 for two unit vectors means:
03Which of these is NOT built on a dot product?
04Normals interpolated across a triangle must be renormalized in the fragment shader because:

Build challenge

Build an unlit shader that reproduces Lambert diffuse using only dot, saturate and a multiply. Expose light direction and light colour as artist controls. Verify it visually matches your engine's built-in diffuse under a single directional light.

SELF-CHECK RUBRIC

Your mastery state