Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


FSR2CommandExecutionData

Represents the data needed to execute FSR2, FSR3, or FSR4 upscaling. If you call GraphicsDevice.ExecuteFSRUpscale2, GraphicsDevice.ExecuteFSRUpscale3, or GraphicsDevice.ExecuteFSRUpscale4, Unity sends the values in this struct to the runtime. After that, you can change the values in this struct without any side effects.
Read time 4 minutesLast updated 2 days ago

Definition

public struct FSR2CommandExecutionData

Remarks

FSR2CommandExecutionData expects
frameTimeDelta
in milliseconds while Unity's _deltaTime is seconds, and
cameraFovAngleVertical
in radians while Unity provides field of view in degrees.
All FSR implementations expect the motion vectors to be in screen space and their values to describe motion from the current frame to the previous frame. Unity's motion vectors describe motion from the previous frame to the current frame and are in normalized device coordinates (NDC), in the [-1, +1] range. To conform to the FSR2 requirements, provide
MVScaleX
and
MVScaleY
values that scale the motion vector values with the motion vector render target size.

Examples

using UnityEngine;using UnityEngine.Rendering;using UnityEngine.Rendering.HighDefinition;using UnityEngine.Experimental.Rendering;using UnityEngine.AMD; // Example HDRP custom pass public class CustomFSRPass : CustomPass{ protected override void Setup(ScriptableRenderContext renderContext, CommandBuffer cmd) { // setup code } protected override void Execute(CustomPassContext ctx) { bool initializeFsr2Context = fsr2Context == null || HasInputResolutionChanged(ctx) || HasOutputResolutionChanged(ctx); if (initializeFsr2Context) { // initialize fsr2Context } Vector2Int mvSize = ctx.cameraMotionVectorsBuffer.GetScaledSize(); m_InputTextureSize = ctx.cameraColorBuffer.GetScaledSize(); fsr2Context.executeData.enableSharpening = m_EnableSharpening ? 1 : 0; fsr2Context.executeData.sharpness = m_Sharpness; fsr2Context.executeData.renderSizeWidth = (uint)m_InputTextureSize.x; fsr2Context.executeData.renderSizeHeight = (uint)m_InputTextureSize.y; fsr2Context.executeData.jitterOffsetX = -ctx.hdCamera.taaJitter.x; fsr2Context.executeData.jitterOffsetY = -ctx.hdCamera.taaJitter.y; fsr2Context.executeData.preExposure = 1.0f; fsr2Context.executeData.frameTimeDelta = Time.deltaTime * 1000.0f; // FSR2 expects time in milliseconds fsr2Context.executeData.cameraNear = ctx.hdCamera.camera.nearClipPlane; fsr2Context.executeData.cameraFar = ctx.hdCamera.camera.farClipPlane; fsr2Context.executeData.cameraFovAngleVertical = ctx.hdCamera.camera.fieldOfView * (Mathf.PI * 2.0f/360.0f); // FSR2 expects in radians // Unity computes motion vectors in NDC, FSR2 expects them in screen space and from current frame to previous frame. // Here we scale by the render target size to meet the FSR2 requirements, // and also invert them to satisfy the frame of reference requirement. fsr2Context.executeData.MVScaleX = -((float)mvSize.x); fsr2Context.executeData.MVScaleY = -((float)mvSize.y); #if UNITY_EDITOR // The same camera is used to render both Scene and Play mode views within the editor. // In case both of these views are visible at the same time, we'll need to reset to avoid // rendering artifacts. fsr2Context.executeData.reset = 1;#else fsr2Context.executeData.reset = (initializeFsr2Context || ctx.hdCamera.isFirstFrame) ? 1 : 0;#endif FSR2TextureTable fsr2TextureTable = new FSR2TextureTable() { // initialize texture table }; amdDevice.ExecuteFSR2(ctx.cmd, fsr2Context, fsr2TextureTable); } protected override void Cleanup() { // cleanup code } private GraphicsDevice amdDevice = null; private FSR2Context fsr2Context = null; private CommandBuffer cmd = null; private RTHandle fsr2OutputColorBuffer; [SerializeField] public float m_Sharpness = 0.92f; [SerializeField] public bool m_EnableSharpening = true; [SerializeField] public FSR2Quality m_Quality = FSR2Quality.Quality; Vector2Int m_InputTextureSize = new Vector2Int(0,0);}

Fields

Value

Description

cameraFarThe distance to the far plane of the camera.
cameraFovAngleVerticalThe camera angle field of view in the vertical direction (expressed in radians).
cameraNearThe distance to the near plane of the camera.
enableSharpeningEnable an additional sharpening pass.
frameTimeDeltaThe time elapsed since the last frame (expressed in milliseconds).
jitterOffsetXThe subpixel jitter offset applied to the camera (X axis).
jitterOffsetYThe subpixel jitter offset applied to the camera (Y axis).
MVScaleXThe scale factor to apply to motion vectors (X axis).
MVScaleYThe scale factor to apply to motion vectors (Y axis).
preExposureThe pre exposure value (must be greater than 0.0f).
renderSizeHeightThe height resolution that was used for rendering the input resources.
renderSizeWidthThe width resolution that was used for rendering the input resources.
resetA boolean value which when set to true, indicates the camera has moved discontinuously.
sharpnessThe sharpness value between 0 and 1, where 0 is no additional sharpness and 1 is maximum additional sharpness.