ShaderLab builtin values
Reference Manual > ShaderLab Reference > ShaderLab builtin valuesUnity provides a handful of builtin values for your shaders: things like current object's transformation matrices, light's color, time etc.
You just use them in ShaderLab like you'd use any other property, the only difference is that you don't have to declare it somewhere - they are "built in".
Using them in Cg shaders requires including UnityCG.cginc file.
Transformations
| Name | Type | Value | Usage |
| _Object2World | float4x4 | Object to World space matrix | Finding world space positions |
| _World2Object | float4x4 | World to Object space matrix | Finding local space positions from world space |
| _ObjectSpaceCameraPos | float3 | Camera's position in object space |
Lighting
In plain ShaderLab, you access the following properties by appending zero at the end: e.g. the light's model*light color is _ModelLightColor0. In Cg shaders, they are exposed as arrays with a single element, so the same in Cg is _ModelLightColor[0].
| Name | Type | Value |
| _ModelLightColor | float4 | Material's Main * Light color |
| _SpecularLightColor | float4 | Material's Specular * Light color |
| _ObjectSpaceLightPos | float4 | Light's position in object space. w component is 0 for directional lights, 1 for other lights |
| _Light2World | float4x4 | Light to World space matrix |
| _World2Light | float4x4 | World to Light space matrix |
| _Object2Light | float4x4 | Object to Light space matrix |
Misc
| Name | Type | Value | Usage |
| _Time | float4 | Time (t/20, t, t*2, t*3) | Animating things inside the shaders |
| _SinTime | float4 | Sine of time: (t/8, t/4, t/2, t) | Animating things inside the shaders |
| _CosTime | float4 | Cosine of time: (t/8, t/4, t/2, t) | Animating things inside the shaders |
| _ProjectionParams | float4 | x is 1.0 or -1.0, negative if currently rendering with a flipped projection matrix y is camera's near plane z is camera's far plane w is 1/FarPlane. | Projecting textures in screen space |
| _CubeNormalize | samplerCUBE | Normalization cube map | Used for pixel lighting on older hardware |
| _SpecFalloff | sampler2D | Specular lookup map | Used for pixel lighting on older hardware |