Skip to content

Latest commit

 

History

History
68 lines (46 loc) · 3.16 KB

variable-shading.md

File metadata and controls

68 lines (46 loc) · 3.16 KB

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 name Value Description
Enable Variable Shading Checked/Unchecked Enable/Disable Variable Shading.
PerDraw VRS 1x1, 1x2, 2x1, 2x2 Shading rate value. Additional shading rates are 2x4, 4x2, 4x4.
ShadingRateImage Enabled Checked/Unchecked Enable/Disable Tier 2 VRS control image.
ShadingRateImage Combiner Checked/Unchecked The 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 Threshold 0.0 - 1.0 Defines a value against which luminance variance gets compared in the compute shader generating the VRS image.
VRS Motion Factor 0.0 - 1.0 Sets a factor by which the motion of the pixel since the last frame gets scaled to modify the shading rate.
ShadingRateImage Overlay Checked/Unchecked Enable/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