ShaderLab builtin values
Manual     Reference     Scripting   
Reference Manual > Shader Reference > ShaderLab builtin values

ShaderLab builtin values

Unity provides a handful of builtin values for your shaders: things like current object's transformation matrices, 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 programmable shaders requires including UnityCG.cginc file.

Transformations

float4x4 UNITY_MATRIX_MVP
Current model*view*projection matrix
float4x4 UNITY_MATRIX_MV
Current model*view matrix
float4x4 UNITY_MATRIX_P
Current projection matrix
float4x4 UNITY_MATRIX_T_MV
Transpose of model*view matrix
float4x4 UNITY_MATRIX_IT_MV
Inverse transpose of model*view matrix
float4x4 UNITY_MATRIX_TEXTURE0 to UNITY_MATRIX_TEXTURE3
Texture transformation matrices
float4x4 _Object2World
Current model matrix
float4x4 _World2Object
Inverse of current world matrix
float3 _WorldSpaceCameraPos
World space position of the camera
float4 unity_Scale
xyz components unused; .w contains scale for uniformly scaled objects.

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

Various

Page last updated: 2010-09-02