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
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.
Name | Type | Value |
|---|---|---|
| _LightColor0 (declared in UnityLightingCommon.cginc) | fixed4 | Light color. |
| _WorldSpaceLightPos0 | float4 | Directional lights: (world space direction, 0). Other lights: (world space position, 1). |
| unity_WorldToLight (declared in AutoLight.cginc) | float4x4 | World-to-light matrix. Used to sample cookie & attenuation textures. |
| unity_4LightPosX0, unity_4LightPosY0, unity_4LightPosZ0 | float4 | (ForwardBase pass only) world space positions of first four non-important point lights. |
| unity_4LightAtten0 | float4 | (ForwardBase pass only) attenuation factors of first four non-important point lights. |
| unity_LightColor | half4[4] | (ForwardBase pass only) colors of the first four non-important point lights. |
| unity_WorldToShadow | float4x4[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 |
|---|---|---|
| _LightColor | float4 | Light color. |
| unity_WorldToLight | float4x4 | World-to-light matrix. Used to sample cookie & attenuation textures. |
| unity_WorldToShadow | float4x4[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 and pass types. They contain 3rd order SH to be evaluated by world space normal (see from UnityCG.cginc). The variables are all half4 type, and similar names.
ForwardBaseDeferredShadeSH9unity_SHArVertex-lit rendering ( pass type):
VertexUp to 8 lights are set up for a 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.
VertexName | Type | Value |
|---|---|---|
| unity_LightColor | half4[8] | Light colors. |
| unity_LightPosition | float4[8] | View-space light positions. (-direction,0) for directional lights; (position,1) for Point or Spot Lights. |
| unity_LightAtten | half4[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_SpotDirection | float4[8] | View-space Spot Lights positions; (0,0,1,0) for non-Spot Lights. |