Skip to content

Commit b21345b

Browse files
[HDRP] Added a RenderGraph pass that resets the camera size after the dynamic res upscale (#3070)
* Added a RenderGraph pass that resets the camera size after the dynamic res upscale * Updated changelog # Conflicts: # com.unity.render-pipelines.high-definition/CHANGELOG.md * fixed class name * update class name * PR fix * Fixed RTHandle scale Co-authored-by: sebastienlagarde <sebastien@unity3d.com>
1 parent 5b57f64 commit b21345b

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

com.unity.render-pipelines.high-definition/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
99
### Fixed
1010
- Fixed GC allocations from XR occlusion mesh when using multipass.
1111
- Fixed XR depth copy when using MSAA.
12+
- Fixed after post process custom pass scale issue when dynamic resolution is enabled (case 1299194).
1213

1314
### Changed
1415
- Change the source value for the ray tracing frame index iterator from m_FrameCount to the camera frame count (case 1301356).

com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Camera/HDCamera.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,8 @@ internal GameObject exposureTarget
343343

344344
internal bool stopNaNs => m_AdditionalCameraData != null && m_AdditionalCameraData.stopNaNs;
345345

346+
internal bool allowDynamicResolution => m_AdditionalCameraData != null && m_AdditionalCameraData.allowDynamicResolution;
347+
346348
internal HDPhysicalCamera physicalParameters { get; private set; }
347349

348350
internal IEnumerable<AOVRequestData> aovRequests =>

com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.RenderGraph.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,8 @@ void ExecuteWithRenderGraph(RenderRequest renderRequest,
275275
}
276276
PushFullScreenExposureDebugTexture(m_RenderGraph, postProcessDest);
277277

278+
ResetCameraSizeForAfterPostProcess(m_RenderGraph, hdCamera, commandBuffer);
279+
278280
RenderCustomPass(m_RenderGraph, hdCamera, postProcessDest, prepassOutput, customPassCullingResults, cullingResults, CustomPassInjectionPoint.AfterPostProcess, aovRequest, aovCustomPassBuffers);
279281

280282
CopyXRDepth(m_RenderGraph, hdCamera, prepassOutput.resolvedDepthBuffer, backBuffer);
@@ -1542,6 +1544,34 @@ bool RenderCustomPass(RenderGraph renderGraph,
15421544
return executed;
15431545
}
15441546

1547+
class ResetCameraSizeForAfterPostProcessPassData
1548+
{
1549+
public HDCamera hdCamera;
1550+
public ShaderVariablesGlobal shaderVariablesGlobal;
1551+
}
1552+
1553+
void ResetCameraSizeForAfterPostProcess(RenderGraph renderGraph, HDCamera hdCamera, CommandBuffer commandBuffer)
1554+
{
1555+
if (DynamicResolutionHandler.instance.DynamicResolutionEnabled())
1556+
{
1557+
using (var builder = renderGraph.AddRenderPass("Reset Camera Size After Post Process", out ResetCameraSizeForAfterPostProcessPassData passData))
1558+
{
1559+
passData.hdCamera = hdCamera;
1560+
passData.shaderVariablesGlobal = m_ShaderVariablesGlobalCB;
1561+
builder.AllowPassCulling(false);
1562+
1563+
builder.SetRenderFunc(
1564+
(ResetCameraSizeForAfterPostProcessPassData data, RenderGraphContext ctx) =>
1565+
{
1566+
data.shaderVariablesGlobal._ScreenSize = new Vector4(data.hdCamera.finalViewport.width, data.hdCamera.finalViewport.height, 1.0f / data.hdCamera.finalViewport.width, 1.0f / data.hdCamera.finalViewport.height);
1567+
data.shaderVariablesGlobal._RTHandleScale = RTHandles.rtHandleProperties.rtHandleScale;
1568+
ConstantBuffer.PushGlobal(ctx.cmd, data.shaderVariablesGlobal, HDShaderIDs._ShaderVariablesGlobal);
1569+
RTHandles.SetReferenceSize((int)data.hdCamera.finalViewport.width, (int)data.hdCamera.finalViewport.height, data.hdCamera.msaaSamples);
1570+
});
1571+
}
1572+
}
1573+
}
1574+
15451575
class BindCustomPassBuffersPassData
15461576
{
15471577
public Lazy<RTHandle> customColorTexture;

0 commit comments

Comments
 (0)