Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


Lighting variables in the Built-In Render Pipeline reference

Find the built-in shader variables that control lighting in the Built-In Render Pipeline.
Read time 2 minutesLast updated 10 days ago

Important
The Built-In Render Pipeline is deprecated and will be made obsolete in a future release.
It remains supported, including bug fixes and maintenance, through the full Unity 6.7 LTS lifecycle.
Find the built-in shader variables that control lighting in the Built-In Render Pipeline.
Light parameters are passed to shaders in different ways depending on which Rendering Path is used, and which LightMode Pass Tag is used in the shader.
Forward rendering (
ForwardBase
and
ForwardAdd
pass types):

Name

Type

Value

_LightColor0 (declared in UnityLightingCommon.cginc)fixed4Light color.
_WorldSpaceLightPos0float4Directional lights: (world space direction, 0). Other lights: (world space position, 1).
unity_WorldToLight (declared in AutoLight.cginc)float4x4World-to-light matrix. Used to sample cookie & attenuation textures.
unity_4LightPosX0, unity_4LightPosY0, unity_4LightPosZ0float4(ForwardBase pass only) world space positions of first four non-important point lights.
unity_4LightAtten0float4(ForwardBase pass only) attenuation factors of first four non-important point lights.
unity_LightColorhalf4[4](ForwardBase pass only) colors of the first four non-important point lights.
unity_WorldToShadowfloat4x4[4]World-to-shadow matrices. One matrix for Spot Lights, up to four for directional light cascades.
Deferred shading, used in the lighting pass shader (all declared in UnityDeferredLibrary.cginc):

Name

Type

Value

_LightColorfloat4Light color.
unity_WorldToLightfloat4x4World-to-light matrix. Used to sample cookie & attenuation textures.
unity_WorldToShadowfloat4x4[4]World-to-shadow matrices. One matrix for Spot Lights, up to four for directional light cascades.
Spherical harmonics coefficients (used by ambient and light probes) are set up for
ForwardBase
and
Deferred
pass types. They contain 3rd order SH to be evaluated by world space normal (see
ShadeSH9
from UnityCG.cginc). The variables are all half4 type,
unity_SHAr
and similar names.
Vertex-lit rendering (
Vertex
pass type):
Up to 8 lights are set up for a
Vertex
pass type; always sorted starting from the brightest one. So if you want to render objects affected by two lights at once, you can just take first two entries in the arrays. If there are fewer than eight lights affecting the object, the rest will have their color set to black.

Name

Type

Value

unity_LightColorhalf4[8]Light colors.
unity_LightPositionfloat4[8]View-space light positions. (-direction,0) for directional lights; (position,1) for Point or Spot Lights.
unity_LightAttenhalf4[8]Light attenuation factors. x is cos(spotAngle/2) or -1 for non-Spot Lights; y is 1/cos(spotAngle/4) or 1 for non-Spot Lights; z is quadratic attenuation; w is squared light range.
unity_SpotDirectionfloat4[8]View-space Spot Lights positions; (0,0,1,0) for non-Spot Lights.

Additional resources