Version: Unity 6.5 (6000.5)
Language : English
Update shader graph effects for foveated rendering
Multiview Render Regions

Foveated rendering shader functions reference

The 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.

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

Update shader graph effects for foveated rendering
Multiview Render Regions