Skip to content

Commit

Permalink
[Fogbugz 1352407] Fixing TAAU and DLSS resolutions on custom post pro…
Browse files Browse the repository at this point in the history
…cess (#5329)

* Fixing TAAU and DLSS resolutions on custom post process by passing custom state

* Adding missing flag for dynamic res target

* Formatting

* Documentation

* More docs

* changelog

* Formatting

* Using data instead of passData, this causes a copy of a class resulting in a GCAlloc call
  • Loading branch information
kecho committed Sep 3, 2021
1 parent a2fbdf2 commit 296ff24
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 3 deletions.
1 change: 1 addition & 0 deletions com.unity.render-pipelines.core/CHANGELOG.md
Expand Up @@ -49,6 +49,7 @@ The version number for this package has increased due to a version update of a r
- Added an option to change the visibilty of the Volumes Gizmos (Solid, Wireframe, Everything), available at Preferences > Core Render Pipeline
- Added class for drawing shadow cascades `UnityEditor.Rendering.ShadowCascadeGUI.DrawShadowCascades`.
- Added UNITY_PREV_MATRIX_M and UNITY_PREV_MATRIX_I_M shader macros to support instanced motion vector rendering
- Added new API to customize the rtHandleProperties of a particular RTHandle. This is a temporary work around to assist with viewport setup of Custom post process when dealing with DLSS or TAAU

### Fixed
- Help boxes with fix buttons do not crop the label.
Expand Down
27 changes: 25 additions & 2 deletions com.unity.render-pipelines.core/Runtime/Textures/RTHandle.cs
Expand Up @@ -19,6 +19,29 @@ public class RTHandle
internal bool m_EnableHWDynamicScale = false;
internal string m_Name;

internal bool m_UseCustomHandleScales = false;
internal RTHandleProperties m_CustomHandleProperties;

/// <summary>
/// By default, rtHandleProperties gets the global state of scalers against the global reference mode.
/// This method lets the current RTHandle use a local custom RTHandleProperties. This function is being used
/// by scalers such as TAAU and DLSS, which require to have a different resolution for color (independent of the RTHandleSystem).
/// </summary>
/// <param name="properties">Properties to set.</param>
public void SetCustomHandleProperties(in RTHandleProperties properties)
{
m_UseCustomHandleScales = true;
m_CustomHandleProperties = properties;
}

/// <summary>
/// Method that clears any custom handle property being set.
/// </summary>
public void ClearCustomHandleProperties()
{
m_UseCustomHandleScales = false;
}

/// <summary>
/// Scale factor applied to the RTHandle reference size.
/// </summary>
Expand All @@ -34,9 +57,9 @@ public class RTHandle
/// </summary>
public Vector2Int referenceSize { get; internal set; }
/// <summary>
/// Current properties of the RTHandle System
/// Current properties of the RTHandle System. If a custom property has been set through SetCustomHandleProperties method, it will be used that one instead.
/// </summary>
public RTHandleProperties rtHandleProperties { get { return m_Owner.rtHandleProperties; } }
public RTHandleProperties rtHandleProperties { get { return m_UseCustomHandleScales ? m_CustomHandleProperties : m_Owner.rtHandleProperties; } }
/// <summary>
/// RenderTexture associated with the RTHandle
/// </summary>
Expand Down
1 change: 1 addition & 0 deletions com.unity.render-pipelines.high-definition/CHANGELOG.md
Expand Up @@ -390,6 +390,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Fixed wrong ordering in FrameSettings (Normalize Reflection Probes)
- Fixed ThreadMapDetail to saturate AO & smoothness strength inputs to prevent out-of-bounds values set by users (1357740)
- Allow negative wind speed parameter.
- Viewport and scaling of Custom post process when TAAU or DLSS are enabled (case 1352407).

### Changed
- Changed Window/Render Pipeline/HD Render Pipeline Wizard to Window/Rendering/HDRP Wizard
Expand Down
Expand Up @@ -1364,6 +1364,8 @@ class CustomPostProcessData
public TextureHandle motionVecTexture;
public HDCamera hdCamera;
public CustomPostProcessVolumeComponent customPostProcess;
public Vector4 postProcessScales;
public Vector2Int postProcessViewportSize;
}

bool DoCustomPostProcess(RenderGraph renderGraph, HDCamera hdCamera, ref TextureHandle source, TextureHandle depthBuffer, TextureHandle normalBuffer, TextureHandle motionVectors, List<string> postProcessList)
Expand Down Expand Up @@ -1398,19 +1400,39 @@ bool DoCustomPostProcess(RenderGraph renderGraph, HDCamera hdCamera, ref Texture
passData.motionVecTexture = builder.ReadTexture(motionVectors);

passData.source = builder.ReadTexture(source);
passData.destination = builder.UseColorBuffer(renderGraph.CreateTexture(new TextureDesc(Vector2.one, true, true)
passData.destination = builder.UseColorBuffer(renderGraph.CreateTexture(new TextureDesc(Vector2.one, IsDynamicResUpscaleTargetEnabled(), true)
{ colorFormat = GetPostprocessTextureFormat(), enableRandomWrite = true, name = "CustomPostProcesDestination" }), 0);
passData.hdCamera = hdCamera;
passData.customPostProcess = customPP;
passData.postProcessScales = new Vector4(hdCamera.postProcessRTScales.x, hdCamera.postProcessRTScales.y, hdCamera.postProcessRTScalesHistory.x, hdCamera.postProcessRTScalesHistory.y);
passData.postProcessViewportSize = postProcessViewportSize;
builder.SetRenderFunc(
(CustomPostProcessData data, RenderGraphContext ctx) =>
{
var srcRt = (RTHandle)data.source;
var dstRt = (RTHandle)data.destination;
// HACK FIX: for custom post process, we want the user to transparently be able to use color target regardless of the scaling occured. For example, if the user uses any of the HDUtil blit methods
// which require the rtHandleProperties to set the viewport and sample scales.
// In the case of DLSS and TAAU, the post process viewport and size for the color target have changed, thus we override them here.
// When these upscalers arent set, behaviour is still the same (since the post process scale is the same as the global rt handle scale). So for simplicity, we always take this code path for custom post process color.
var newProps = srcRt.rtHandleProperties;
newProps.rtHandleScale = data.postProcessScales;
newProps.currentRenderTargetSize = data.postProcessViewportSize;
newProps.previousRenderTargetSize = data.postProcessViewportSize;
newProps.currentViewportSize = data.postProcessViewportSize;
srcRt.SetCustomHandleProperties(newProps);
dstRt.SetCustomHandleProperties(newProps);
// Temporary: see comment above
ctx.cmd.SetGlobalTexture(HDShaderIDs._CameraDepthTexture, data.depthBuffer);
ctx.cmd.SetGlobalTexture(HDShaderIDs._NormalBufferTexture, data.normalBuffer);
ctx.cmd.SetGlobalTexture(HDShaderIDs._CameraMotionVectorsTexture, data.motionVecTexture);
data.customPostProcess.Render(ctx.cmd, data.hdCamera, data.source, data.destination);
srcRt.ClearCustomHandleProperties();
dstRt.ClearCustomHandleProperties();
});

customPostProcessExecuted = true;
Expand Down

0 comments on commit 296ff24

Please sign in to comment.