Suggest a change# ShaderLab built-in values

## Transformations

## Lighting

## Various

Unity provides a handful of built-in 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.

Name |
Type |
Value |

UNITY_MATRIX_MVP | float4x4 | Current model * view * projection matrix. |

UNITY_MATRIX_MV | float4x4 | Current model * view matrix. |

UNITY_MATRIX_V | float4x4 | Current view matrix. |

UNITY_MATRIX_P | float4x4 | Current projection matrix. |

UNITY_MATRIX_VP | float4x4 | Current view * projection matrix. |

UNITY_MATRIX_T_MV | float4x4 | Transpose of model * view matrix. |

UNITY_MATRIX_IT_MV | float4x4 | Inverse transpose of model * view matrix. |

UNITY_MATRIX_TEXTURE0 to UNITY_MATRIX_TEXTURE3 | float4x4 | Texture transformation matrices. |

_Object2World | float4x4 | Current model matrix. |

_World2Object | float4x4 | Inverse of current world matrix. |

_WorldSpaceCameraPos | float3 | World space position of the camera. |

unity_Scale | float4 |
`xyz` components unused; `w` contains scale for uniformly scaled objects. |

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 |

Name |
Type |
Value |

_Time | float4 | Time (t/20, t, t*2, t*3), use to animate things inside the shaders. |

_SinTime | float4 | Sine of time: (t/8, t/4, t/2, t). |

_CosTime | float4 | Cosine of time: (t/8, t/4, t/2, t). |

unity_DeltaTime | float4 | Delta time: (dt, 1/dt, smoothDt, 1/smoothDt). |

_ProjectionParams | float4 |
`x` is 1.0 (or –1.0 if currently rendering with a flipped projection matrix), `y` is the camera’s near plane, `z` is the camera’s far plane and `w` is 1/FarPlane. |

_ScreenParams | float4 |
`x` is the current render target width in pixels, `y` is the current render target height in pixels, `z` is 1.0 + 1.0/width and `w` is 1.0 + 1.0/height. |

Your name (optional):

Your email (optional):