Unity’s built-in include files contain global variables for your shadersA program that runs on the GPU. More info
See in Glossary: things like current object’s transformation matrices, light parameters, current time and so on. You use them in shader programs 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.
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 and 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:
All these matrices are float4x4 type, and are column major.
Note: If you use the Universal Render PipelineA series of operations that take the contents of a Scene, and displays them on a screen. Unity lets you choose from pre-built render pipelines, or write your own. More info
See in Glossary (URP), you can also use variables from the Core.hlsl library file. For more information, refer to Transform positions in a custom URP shader.
| 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 world matrix. |
These variables will correspond to the CameraA component which creates an image of a particular viewpoint in your scene. The output is either drawn to the screen or captured as a texture. More info
See in Glossary 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.
| 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), 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 pixelsThe smallest unit in a computer image. Pixel size depends on your screen resolution. Pixel lighting is calculated at every screen pixel. More infoSee in Glossary, 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.
|
| unity_OrthoParams | float4 | The following parameters:
|
| 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 is measured in seconds, and is scaled by the Time multiplier in your Project’s Time settings. 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). |
| Name | Type | Value |
|---|---|---|
| unity_Lightmap | Texture2D | Contains lightmapA pre-rendered texture that contains the effects of light sources on static objects in the scene. Lightmaps are overlaid on top of scene geometry to create the effect of lighting. More info See in Glossary information. |
| unity_LightmapST | float4[8] | Scales and translates the UV information to the correct range to sample the lightmap texture. |
| 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 skyboxA special type of Material used to represent skies. Usually six-sided. More info See in Glossary, this is the average color of the skybox, which Unity calculates using the DC component of the spherical harmonics data in the ambient probe. 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. |
| Name | Type | Value |
|---|---|---|
| unity_LODFade | float4 | Level-of-detail fade when using LODGroup. 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)). |