Skip to content

FidelityFX Variable Shading

alt text

This sample demonstrates the use of the FidelityFX Variable Shading (VRS) compute algorithm.

For details on the techniques that underpins the Variable Shading effect you can refer to the respective technique documentation.

Requirements

  • Windows
  • DirectX(R)12
  • Vulkan(R)

UI elements

The sample contains various UI elements to help you explore the techniques it demonstrates. The table below summarises the UI elements and what they control within the sample.

Element nameValueDescription
Enable Variable ShadingChecked/UncheckedEnable/Disable Variable Shading.
PerDraw VRS1x1, 1x2, 2x1, 2x2Shading rate value. Additional shading rates are 2x4, 4x2, 4x4.
ShadingRateImage EnabledChecked/UncheckedEnable/Disable Tier 2 VRS control image.
ShadingRateImage CombinerChecked/UncheckedThe options for each combiner are: passthrough the previous state (i.e. disable the current stage), override (ignore previous stages), min, max and sum.
VRS variance Threshold0.0 - 1.0Defines a value against which luminance variance gets compared in the compute shader generating the VRS image.
VRS Motion Factor0.0 - 1.0Sets a factor by which the motion of the pixel since the last frame gets scaled to modify the shading rate.
ShadingRateImage OverlayChecked/UncheckedEnable/Disable ShadingRateImage overlay, a debug image over the rendered scene.

Setting up Variable Shading

The Variable Shading compute shader takes as input the linear color buffer produced by the geometry rendering passes, and motion vectors buffer produced before geometry rendering passes. Final VRS control image is written to output buffer passed from setup.

Include the interface for the backend of the VRS API.

C++:

#include <FidelityFX/host/ffx_vrs.h>

Create VRS context:

if (m_AllowAdditionalShadingRates)
m_InitializationParameters.flags |= FFX_VRS_ALLOW_ADDITIONAL_SHADING_RATES;
m_InitializationParameters.shadingRateImageTileSize = m_FeatureInfoVRS.MaxTileSize[0];
ffxVrsContextCreate(&m_VRSContext, &m_InitializationParameters);

Set up dispatch parameters and dispatch:

FfxVrsDispatchDescription dispatchParameters = {};
dispatchParameters.commandList = ffxGetCommandList(pCmdList);
...
FfxErrorCode errorCode = ffxVrsContextDispatch(&m_VRSContext, &dispatchParameters);

Sample controls and configurations

For sample controls, configuration, and FidelityFX Cauldron Framework UI element details, see Running the samples.

See also