# Foveated rendering shader functions reference

> Explore the HLSL functions you can use to remap screen-space coordinates in custom shaders that must work under foveated rendering.

The [`FoveatedRendering.hlsl`](https://github.com/Unity-Technologies/Graphics/blob/master/Packages/com.unity.render-pipelines.core/ShaderLibrary/FoveatedRendering.hlsl) file on GitHub defines a set of functions that you can use to support foveated rendering in your custom shaders. These functions return the correct results whether the current raster space is linear or non-uniform, and when foveated rendering isn't active. The functions also handle inverting the y-axis according to whether the platform places the screen-space origin at the top or bottom of the screen.

> **Note:**
>
> These functions have no performance impact on platforms that don't use variable rate rasterization (VRR). You don't need to use conditional `#ifdef` statements to exclude them. However, on platforms that do use VRR, each function includes a dynamic branch that checks the shader constant. This branch adds a small amount of overhead even when foveated rendering isn't active.

To add these functions to a shader, refer to [Adapt custom shaders for foveated rendering](/engine/6000.0/manual/xr/graphics/foveated-rendering/custom-shaders.md).

## UV coordinate remapping functions

Use these functions to convert UV coordinates between the linear and non-uniform raster spaces:

| **Declaration**                                              | **Description**                                                                                                                                                                                                                                                                |
| ------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `float2 FoveatedRemapLinearToNonUniform(float2 uv)`          | Converts linear screen-space UV coordinates to non-uniform screen-space UV coordinates, including any necessary y-axis inversion. If foveated rendering isn't active or the platform doesn't use non-uniform rasterization, the function returns the UV coordinates unchanged. |
| `float2 FoveatedRemapNonUniformToLinear(float2 uv)`          | Converts non-uniform screen-space UV coordinates to linear screen-space UV coordinates, including any necessary y-axis inversion. If foveated rendering isn't active or the platform doesn't use non-uniform rasterization, the function returns the UV coordinates unchanged. |
| `float2 FoveatedRemapPrevFrameLinearToNonUniform(float2 uv)` | Remaps linear screen-space UV coordinates based on the previously rendered frame. Not implemented on Metal.                                                                                                                                                                    |
| `float2 FoveatedRemapPrevFrameNonUniformToLinear(float2 uv)` | Remaps non-uniform screen-space UV coordinates based on the previously rendered frame. Not implemented on Metal.                                                                                                                                                               |

## Density functions

Use the following functions to find the ratio between the screen resolution and the raster resolution, for example when you update a screen-space effect:

| **Declaration**                                   | **Description**                                                                                                                                                                                                                                                        |
| ------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `float2 FoveatedRemapDensity(float2 uv)`          | Returns the ratio between the screen resolution and the raster resolution at the specified screen UV coordinate. If foveated rendering isn't active or the platform doesn't use non-uniform rasterization, the function returns `(1.0,1.0)`. Not implemented on Metal. |
| `float2 FoveatedRemapPrevFrameDensity(float2 uv)` | Returns the density ratio for the previous frame. Not implemented on Metal.                                                                                                                                                                                            |

## Screen coordinate remapping functions

Use the following functions to convert clip-space screen coordinates rather than UV coordinates:

| **Declaration**                                               | **Description**                                                                                                                                                                                                             |
| ------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `float2 FoveatedRemapLinearToNonUniformCS(float2 positionCS)` | Converts linear-space screen coordinates to non-uniform-space screen coordinates. If foveated rendering isn't active or the platform doesn't use non-uniform rasterization, the function returns the coordinates unchanged. |
| `float2 FoveatedRemapNonUniformToLinearCS(float2 positionCS)` | Converts non-uniform-space screen coordinates to linear-space screen coordinates. If foveated rendering isn't active or the platform doesn't use non-uniform rasterization, the function returns the coordinates unchanged. |

## Additional resources

* [Introduction to foveated rendering](/engine/6000.0/manual/xr/graphics/foveated-rendering/introduction.md)
* [Foveated rendering support reference](/engine/6000.0/manual/xr/graphics/foveated-rendering/support.md)
* [Core RP Library package documentation](https://docs.unity3d.com/Packages/com.unity.render-pipelines.core@latest?subfolder=/manual/index.html)
