ShaderLab builtin values
Reference Manual > ShaderLab Reference > ShaderLab builtin values

ShaderLab builtin values

Unity 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

NameTypeValueUsage
_Object2Worldfloat4x4Object to World space matrixFinding world space positions
_World2Objectfloat4x4World to Object space matrixFinding local space positions from world space
_ObjectSpaceCameraPosfloat3Camera'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].

NameTypeValue
_ModelLightColorfloat4Material's Main * Light color
_SpecularLightColorfloat4Material's Specular * Light color
_ObjectSpaceLightPosfloat4Light's position in object space. w component is 0 for directional lights, 1 for other lights
_Light2Worldfloat4x4Light to World space matrix
_World2Lightfloat4x4World to Light space matrix
_Object2Lightfloat4x4Object to Light space matrix

Misc

NameTypeValueUsage
_Timefloat4Time (t/20, t, t*2, t*3)Animating things inside the shaders
_SinTimefloat4Sine of time: (t/8, t/4, t/2, t)Animating things inside the shaders
_CosTimefloat4Cosine of time: (t/8, t/4, t/2, t)Animating things inside the shaders
_ProjectionParamsfloat4x 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
_CubeNormalizesamplerCUBENormalization cube mapUsed for pixel lighting on older hardware
_SpecFalloffsampler2DSpecular lookup mapUsed for pixel lighting on older hardware