Skip to content

[HDRP][Fix] Case 1158661: Hardware mode for dynamic resolution breaks editor and game views #1652

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Sep 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions com.unity.render-pipelines.core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
Version Updated
The version number for this package has increased due to a version update of a related graphics package.

### Fixed
- Fixed the scene view to scale correctly when hardware dynamic resolution is enabled (case 1158661)
- Fixed game view artifacts on resizing when hardware dynamic resolution was enabled

## [10.0.0] - 2019-06-10

### Added
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ public class DynamicResolutionHandler
/// </summary>
public DynamicResUpscaleFilter filter { get; set; }

/// <summary>
/// The viewport of the final buffer. This is likely the resolution the dynamic resolution starts from before any scaling. Note this is NOT the target resolution the rendering will happen in
/// but the resolution the scaled rendered result will be upscaled to.
/// </summary>
public Vector2Int finalViewport { get; set; }


private DynamicResolutionType type;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,9 @@ public void SetReferenceSize(int width, int height, MSAASamples msaaSamples, boo

if (DynamicResolutionHandler.instance.HardwareDynamicResIsEnabled())
{
m_RTHandleProperties.rtHandleScale = new Vector4(1.0f, 1.0f, 1.0f, 1.0f);
float xScale = (float)DynamicResolutionHandler.instance.finalViewport.x / GetMaxWidth();
float yScale = (float)DynamicResolutionHandler.instance.finalViewport.y / GetMaxHeight();
m_RTHandleProperties.rtHandleScale = new Vector4(xScale, yScale, m_RTHandleProperties.rtHandleScale.x, m_RTHandleProperties.rtHandleScale.y);
}
else
{
Expand All @@ -212,10 +214,12 @@ public void SetReferenceSize(int width, int height, MSAASamples msaaSamples, boo
/// <param name="enableHWDynamicRes">State of hardware dynamic resolution.</param>
public void SetHardwareDynamicResolutionState(bool enableHWDynamicRes)
{
if(enableHWDynamicRes != m_HardwareDynamicResRequested && m_AutoSizedRTsArray != null)
if(enableHWDynamicRes != m_HardwareDynamicResRequested)
{
m_HardwareDynamicResRequested = enableHWDynamicRes;

Array.Resize(ref m_AutoSizedRTsArray, m_AutoSizedRTs.Count);
m_AutoSizedRTs.CopyTo(m_AutoSizedRTsArray);
for (int i = 0, c = m_AutoSizedRTsArray.Length; i < c; ++i)
{
var rth = m_AutoSizedRTsArray[i];
Expand All @@ -232,7 +236,6 @@ public void SetHardwareDynamicResolutionState(bool enableHWDynamicRes)
// Create the render texture
renderTexture.Create();
}

}
}
}
Expand Down
2 changes: 2 additions & 0 deletions com.unity.render-pipelines.high-definition/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
### Fixed
- Fixed several issues with physically-based DoF (TAA ghosting of the CoC buffer, smooth layer transitions, etc)
- Fixed GPU hang on D3D12 on xbox.
- Fixed game view artifacts on resizing when hardware dynamic resolution was enabled
- Fixed black line artifacts occurring when Lanczos upsampling was set for dynamic resolution
- Fixed Amplitude -> Min/Max parametrization conversion
- Fixed CoatMask block appearing when creating lit master node (case 1264632)
- Fixed issue with SceneEV100 debug mode indicator when rescaling the window.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ void WeightedAcc(CTYPE value, float weight, inout CTYPE accumulated, inout float
// TODO: Revisit derivation.
CTYPE Lanczos(TEXTURE2D_X(_InputTexture), float2 inUV)
{
// Lanczos 3
const float a = 3.0;
const float epsilon = 0.0000000001;
const float a = 3.0; // Lanczos 3

float2 TexSize = _ScreenSize.xy * (_RTHandleScale.xy);
float2 TexelSize = rcp(TexSize);
Expand All @@ -67,7 +67,6 @@ CTYPE Lanczos(TEXTURE2D_X(_InputTexture), float2 inUV)
cosXPIOverA *= sqrtA;
float2 sinXCosXOverA = cosXPIOverA * sinXPI;


// Find UVs
float2 UV_2 = (center - 2) * TexelSize;
float2 UV_1 = (center - 1) * TexelSize;
Expand All @@ -82,9 +81,13 @@ CTYPE Lanczos(TEXTURE2D_X(_InputTexture), float2 inUV)
float2 xMin4 = x - 4.0;
float2 xMin5 = x - 5.0;

// By the definition of x, only xMin2 should possibly = 0
xMin2 = (xMin2 == 0) * epsilon + xMin2; // if (xMin2 == 0), then xMin2 = epsilon

float2 w14 = -sinLancz + sinXCosXOverA;
float2 w25 = -sinLancz - sinXCosXOverA;


float2 weight0 = sinLancz / (x * x);
float2 weight1 = w14 / (xMin1 * xMin1);
float2 weight2 = w25 / (xMin2 * xMin2);
Expand All @@ -93,13 +96,14 @@ CTYPE Lanczos(TEXTURE2D_X(_InputTexture), float2 inUV)
float2 weight5 = w25 / (xMin5 * xMin5);

float2 weight23 = weight2 + weight3; // Readapt since we are leveraging bilinear.

weight23 = (weight23 == 0) * epsilon + weight23; // if (weight23 == 0), then weight23 = epsilon

// Correct UV to account for bilinear adjustment
UV0 += (weight3 / weight23) * TexelSize;

#ifndef ENABLE_ALPHA
float4 accumulation = 0;

// Corners are dropped (similarly to what Jimenez suggested for Bicubic)
accumulation += float4(Bilinear(_InputTexture, float2(UV_2.x, UV0.y)), 1) * weight0.x * weight23.y;
accumulation += float4(Bilinear(_InputTexture, float2(UV_1.x, UV_1.y)), 1) * weight1.x * weight1.y;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,8 @@ internal void Update(FrameSettings currentFrameSettings, HDRenderPipeline hdrp,
actualHeight = Math.Max((int)finalViewport.size.y, 1);
}

DynamicResolutionHandler.instance.finalViewport = new Vector2Int((int)finalViewport.width, (int)finalViewport.height);

Vector2Int nonScaledViewport = new Vector2Int(actualWidth, actualHeight);
if (isMainGameView)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1613,8 +1613,7 @@ protected override void Render(ScriptableRenderContext renderContext, Camera[] c
// We are in a case where the platform does not support hw dynamic resolution, so we force the software fallback.
// TODO: Expose the graphics caps info on whether the platform supports hw dynamic resolution or not.
// Temporarily disable HW Dynamic resolution on metal until the problems we have with it are fixed
bool isMetal = (SystemInfo.graphicsDeviceType == GraphicsDeviceType.Metal);
if (isMetal || (dynResHandler.RequestsHardwareDynamicResolution() && cameraRequestedDynamicRes && !camera.allowDynamicResolution))
if (dynResHandler.RequestsHardwareDynamicResolution() && cameraRequestedDynamicRes && !camera.allowDynamicResolution)
{
dynResHandler.ForceSoftwareFallback();
}
Expand Down