The set of texture slots available for the FSR2Context and FSRUpscalerContext.
Use this struct to specify input and output textures for FSR2, FSR3, and FSR4 upscaling.
Note: You must create output color texture colorOutput with enableRandomWrite parameter set to true
when initializing the RTHandle of the texture. This is due to FSR passes requiring access to the resources in a compute shader.
Refer to the Input resources section in AMD's documentation for more details:
Additional resources: AMDUnityPlugin, GraphicsDevice, FSR2Context, FSRUpscalerContext, FSR2CommandInitializationData, FSRUpscalerCommandInitializationData, FSR2CommandExecutionData
using UnityEngine; using UnityEngine.Rendering; using UnityEngine.Rendering.HighDefinition; using UnityEngine.Experimental.Rendering; using UnityEngine.AMD;
// Example HDRP custom pass public class CustomFSRPass : CustomPass { void InitializeAMDDevice() { // device initialization code } bool HasOutputResolutionChanged(CustomPassContext ctx) { // detect resolution change } bool HasInputResolutionChanged(CustomPassContext ctx) { // detect resolution change }
protected override void Setup(ScriptableRenderContext renderContext, CommandBuffer cmd) { if (amdDevice == null) { InitializeAMDDevice(); }
float scalingRatio = fsr2Context == null ? 1.0f : amdDevice.GetUpscaleRatioFromQualityMode(m_Quality); fsr2OutputColorBuffer = RTHandles.Alloc( new Vector2(scalingRatio, scalingRatio), slices: 1, dimension: TextureDimension.Tex2D, colorFormat: GraphicsFormat.R16G16B16A16_SFloat, name: "fsr2OutputColorBuffer", enableRandomWrite: true ); }
protected override void Execute(CustomPassContext ctx) { bool initializeFsr2Context = fsr2Context == null || HasInputResolutionChanged(ctx) || HasOutputResolutionChanged(ctx); if (initializeFsr2Context) { // fsr2Context initialization code }
fsr2Context.executeData.enableSharpening = m_EnableSharpening ? 1 : 0; // populate rest of the fsr2Context.executeData
FSR2TextureTable fsr2TextureTable = new FSR2TextureTable() { // Mandatory inputs colorInput = ctx.cameraColorBuffer, colorOutput = fsr2OutputColorBuffer, depth = ctx.cameraDepthBuffer, motionVectors = ctx.cameraMotionVectorsBuffer,
// Optional inputs transparencyMask = null, exposureTexture = null, reactiveMask = null, biasColorMask = null };
amdDevice.ExecuteFSR2(ctx.cmd, fsr2Context, fsr2TextureTable); }
protected override void Cleanup() { // cleanup code }
private GraphicsDevice amdDevice = null; private FSR2Context fsr2Context = null; private RTHandle fsr2OutputColorBuffer;
[SerializeField] public float m_Sharpness = 0.92f; [SerializeField] public bool m_EnableSharpening = true; [SerializeField] public FSR2Quality m_Quality = FSR2Quality.Quality; FSR2Quality m_QualityBefore = FSR2Quality.Quality; Vector2Int m_InputTextureSize = new Vector2Int(0,0); }
| Property | Description |
|---|---|
| biasColorMask | This is obsolete. Use transparencyMask instead. If both are specified, then transparencyMask is used and this is ignored. |
| colorInput | The input color texture to upsample for FSR2Context or FSRUpscalerContext. This texture is mandatory and you must set it to a non-null value. |
| colorOutput | The output color texture. This texture is mandatory and you must set it to a non-null value. |
| depth | The input depth texture. This must be the same size as the input color texture. This texture is mandatory and you must set it to a non-null value. |
| exposureTexture | A 1x1 texture with pre-exposure values. See AMD's documentation for details. If you do not use pre-exposure, do not set this texture. Also if there's no particular reason then it's recommended to enable auto exposure via FfxFsr2InitializationFlags or FfxApiCreateContextUpscaleFlags instead of using this texture. This texture is optional. |
| motionVectors | The motion vectors texture. Depending on the FfxFsr2InitializationFlags specified in FSR2Context.initData or FfxApiCreateContextUpscaleFlags specified in FSRUpscalerContext.initData, this texture can have the input resolution or output resolution. This texture is mandatory and you must set it to a non-null value. |
| reactiveMask | A texture of format R8_UNORM and same size as colorInput that adjusts the temporal accumulation balance. See AMD's documentation for details. This texture is optional in FSR2, FSR3 and ignored in FSR4. |
| transparencyMask | A texture of format R8_UNORM and same size as colorInput that adjusts the pixel history protection mechanisms. See AMD's documentation for details. This texture is optional in FSR2, FSR3 and ignored in FSR4. |