# Built-in shader variables reference

> Reference for the global variables Unity provides for your custom shaders, such as transformation matrices and light parameters.

Unity's built-in include files contain global variables for your shaders: things like current object's transformation matrices, light parameters, current time and so on. You use them in [shader programs](/engine/6000.6/manual/materials-and-shaders/shaders/writing-custom/shader-writing/sl/writing-shader-writing-shader-programs-hlsl.md) like any other variable, but if you include the relevant include file, you don't have to declare them.

For more information on include files, see [Built-in include files](/engine/6000.6/manual/materials-and-shaders/shaders/writing-shaders-birp/use-built-in-shader-methods-birp/sl-builtin-includes.md).

## Inline sampler suffixes

Add the following suffixes when you declare an inline `SamplerState` sampler in HLSL code, to manually set texture filtering and wrapping modes. Separate multiple words with an underscore (`_`). For example, to set a sampler to use linear filtering and repeat wrapping mode, name it `sampler_linear_repeat`.

> **Note:**
>
> These sampler suffixes only work if you target the DX11, DX12, Metal or Vulkan graphics API.

You must include a single filtering mode and a single texture wrapping mode. The other suffixes are optional.

| **Suffix**                              | **Description**                                                                                                                                                                                                                                                                                                                                    |
| --------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `point`                                 | Enables nearest texture filtering.                                                                                                                                                                                                                                                                                                                 |
| `linear`                                | Enables bilinear texture filtering.                                                                                                                                                                                                                                                                                                                |
| `trilinear`                             | Enables trilinear texture filtering.                                                                                                                                                                                                                                                                                                               |
| `clamp`                                 | Sets the texture wrapping mode to clamp.                                                                                                                                                                                                                                                                                                           |
| `repeat`                                | Sets the texture wrapping mode to repeat.                                                                                                                                                                                                                                                                                                          |
| `mirror`                                | Sets the texture wrapping mode to mirror.                                                                                                                                                                                                                                                                                                          |
| `mirroronce`                            | Sets the texture wrapping mode to mirror once. If you target a mobile platform that doesn't support `mirroronce`, Unity falls back to `mirror`.                                                                                                                                                                                                    |
| `compare`                               | Sets the sampler to compare depth values. For more information refer to [SampleCmp](https://learn.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-to-samplecmp) and [SampleCmpLevelZero](https://learn.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-to-samplecmplevelzero) in the Microsoft HLSL documentation. |
| `aniso2`, `aniso4`, `aniso8`, `aniso16` | Enables anisotropic filtering with 2x, 4x, 8x, or 16x sampling. Depending on the graphics API and platform you target, Unity might clamp the filtering to a lower value, or disable anisotropic filtering completely.                                                                                                                              |

Add `U`, `V` or `W` to a wrap mode to set the wrapping mode for that axis only. For example, `sampler_clampu_point` sets the U axis to clamp mode, and leaves the V and W axes at their default wrapping mode.

For more information, refer to:

* [`Texture.wrapMode`](/engine/6000.6/script-reference/unityengine/texture/wrapmode.md)
* [`Texture.anisoLevel`](/engine/6000.6/script-reference/unityengine/texture/anisolevel.md)
* [`Texture.filterMode`](/engine/6000.6/script-reference/unityengine/texture/filtermode.md)

## Transformations

All these matrices are `float4x4` type, and are column major.

> **Note:**
>
> If you use the Universal Render Pipeline (URP), you can also use variables from the `Core.hlsl` library file. For more information, refer to [Transform positions in a custom URP shader](/engine/6000.6/manual/materials-and-shaders/shaders/writing-custom-shaders-urp/use-built-in-shader-methods/transformations.md).

| **Name**              | **Value**                                   |
| --------------------- | ------------------------------------------- |
| UNITY\_MATRIX\_MVP    | Current model \* view \* projection matrix. |
| UNITY\_MATRIX\_MV     | Current model \* view matrix.               |
| UNITY\_MATRIX\_V      | Current view matrix.                        |
| UNITY\_MATRIX\_P      | Current projection matrix.                  |
| UNITY\_MATRIX\_VP     | Current view \* projection matrix.          |
| UNITY\_MATRIX\_T\_MV  | Transpose of model \* view matrix.          |
| UNITY\_MATRIX\_IT\_MV | Inverse transpose of model \* view matrix.  |
| unity\_ObjectToWorld  | Current model matrix.                       |
| unity\_WorldToObject  | Inverse of current model matrix.            |

## Camera and screen

These variables will correspond to the [Camera](/engine/6000.6/manual/cameras/birp/class-camera.md) that is rendering. For example during shadowmap rendering, they will still refer to the Camera component values, and not the "virtual camera" that is used for the shadowmap projection.

> **Note:**
>
> If you use the Universal Render Pipeline (URP), you can also use variables from the `Core.hlsl` library file. For more information, refer to [Use the camera in a custom URP shader](/engine/6000.6/manual/materials-and-shaders/shaders/writing-custom-shaders-urp/use-built-in-shader-methods/camera.md).

| **Name**                         | **Type** | **Value**                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| -------------------------------- | -------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| \_WorldSpaceCameraPos            | float3   | World space position of the camera.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| \_ProjectionParams               | float4   | `x` is 1.0 (or -1.0 if currently rendering with a [flipped projection matrix](/engine/6000.6/manual/materials-and-shaders/shaders/writing-custom/shader-writing/sl/writing-shader-writing-shader-programs-hlsl/sl-platform-differences.md)), `y` is the camera's near plane, `z` is the camera's far plane and `w` is 1/FarPlane.                                                                                                                                                                                                                                                                                                                          |
| \_ScreenParams                   | float4   | `x` is the width of the camera's target texture in pixels, `y` is the height of the camera's target texture in pixels, `z` is 1.0 + 1.0/width and `w` is 1.0 + 1.0/height.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| \_ZBufferParams                  | float4   | Used to linearize Z buffer values.`x`: `1 - far/near`, or `-1 + far/near` if `UNITY_REVERSED_Z` is set to 1.For more information about `UNITY_REVERSED_Z`, refer to [Branch based on platform features](/engine/6000.6/manual/materials-and-shaders/shaders/writing-custom/shader-writing/shader-branching-built-in-macros/platform.md).`y`: `far/near`, or `1` if `UNITY_REVERSED_Z` is set to 1.For more information about `UNITY_REVERSED_Z`, refer to [Branch based on platform features](/engine/6000.6/manual/materials-and-shaders/shaders/writing-custom/shader-writing/shader-branching-built-in-macros/platform.md).`z`: `x / far``w`: `y / far` |
| unity\_OrthoParams               | float4   | The following parameters:`x`: half the width of the camera view in world space`y`: half the height of the camera view in world space`z`: unused`w`: 1.0 if the camera is orthographic, or 0.0 if the camera is perspective                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| unity\_CameraProjection          | float4x4 | Camera's projection matrix.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| unity\_CameraInvProjection       | float4x4 | Inverse of camera's projection matrix.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| unity\_CameraWorldClipPlanes\[6] | float4   | Camera frustum plane world space equations, in this order: left, right, bottom, top, near, far.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |

## Time

Time is measured in seconds, and is scaled by the Time multiplier in your Project's [Time settings](/engine/6000.6/manual/unity-editor/editor-settings-reference/comp-manager-group/class-time-manager.md). There is no built-in variable that provides access to unscaled time.

Time matches `Time.time`, which is the time since the application started. If you use the Built-In Render Pipeline, time matches `Time.timeSinceLevelLoad` instead.

| **Name**         | **Type** | **Value**                                                   |
| ---------------- | -------- | ----------------------------------------------------------- |
| \_Time           | float4   | `(t/20, t, t\*2, t\*3)`. Use for animations inside 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).               |

## Lightmaps

| **Name**          | **Type**   | **Value**                                                                                     |
| ----------------- | ---------- | --------------------------------------------------------------------------------------------- |
| unity\_Lightmap   | Texture2D  | Contains lightmap information.                                                                |
| unity\_LightmapST | float4\[8] | Scales and translates the UV information to the correct range to sample the lightmap texture. |

## Fog and Ambient

| **Name**                   | **Type** | **Value**                                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
| -------------------------- | -------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| unity\_AmbientSky          | fixed4   | Sky ambient lighting color in gradient ambient lighting case.                                                                                                                                                                                                                                                                                                                                                                                                               |
| unity\_AmbientEquator      | fixed4   | Equator ambient lighting color in gradient ambient lighting case.                                                                                                                                                                                                                                                                                                                                                                                                           |
| unity\_AmbientGround       | fixed4   | Ground ambient lighting color in gradient ambient lighting case.                                                                                                                                                                                                                                                                                                                                                                                                            |
| unity\_IndirectSpecColor   | fixed4   | If you use a [skybox](/engine/6000.6/manual/creating-environments/sky/skyboxes-using.md), this is the average color of the skybox, which Unity calculates using the `DC` component of the [spherical harmonics data](/engine/6000.6/manual/lighting-overview/direct-and-indirect-lighting/lightmap-data/light-probes-technical-information.md) in the [ambient probe](/engine/6000.6/script-reference/unityengine/rendersettings/ambientprobe.md). Otherwise this is black. |
| UNITY\_LIGHTMODEL\_AMBIENT | fixed4   | Ambient lighting color (sky color in gradient ambient case). Legacy variable.                                                                                                                                                                                                                                                                                                                                                                                               |
| unity\_FogColor            | fixed4   | Fog color.                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| unity\_FogParams           | float4   | Parameters for fog calculation: (density / sqrt(ln(2)), density / ln(2), -1/(end-start), end/(end-start)). *x* is useful for Exp2 fog mode, *y* for Exp mode, *z* and *w* for Linear mode.                                                                                                                                                                                                                                                                                  |

## Various

| **Name**           | **Type** | **Value**                                                                                                                                                                                                              |
| ------------------ | -------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| unity\_LODFade     | float4   | Level-of-detail fade when using [LODGroup](/engine/6000.6/manual/analysis/graphics-performance-profiling/lod/lod-group/class-lodgroup.md). *x* is fade (0..1), *y* is fade quantized to 16 levels, *z* and *w* unused. |
| \_TextureSampleAdd | float4   | Set automatically by Unity **for UI only** based on whether the texture being used is in Alpha8 format (the value is set to (1,1,1,0)) or not (the value is set to (0,0,0,0)).                                         |
