Skip to content

Commit 7be49fb

Browse files
committed
(PR #5) ColorGradingLutPass should have its color attachment set to the LUT render target.
Otherwise, the color pass ends up enabling XR mode.
1 parent 87329d5 commit 7be49fb

File tree

4 files changed

+25
-9
lines changed

4 files changed

+25
-9
lines changed

com.unity.render-pipelines.universal/Runtime/2D/Renderer2D.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ public override void Setup(ScriptableRenderContext context, ref RenderingData re
164164
// We generate color LUT in the base camera only. This allows us to not break render pass execution for overlay cameras.
165165
if (stackHasPostProcess && cameraData.renderType == CameraRenderType.Base)
166166
{
167-
m_ColorGradingLutPass.Setup(k_ColorGradingLutHandle);
167+
m_ColorGradingLutPass.Setup(k_ColorGradingLutHandle, ref renderingData);
168168
EnqueuePass(m_ColorGradingLutPass);
169169
}
170170

com.unity.render-pipelines.universal/Runtime/Data/UniversalRenderPipelineAsset.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,6 @@ public enum ColorTransformation
122122
InForwardPass
123123
}
124124

125-
}
126-
127125
public class UniversalRenderPipelineAsset : RenderPipelineAsset, ISerializationCallbackReceiver
128126
{
129127
Shader m_DefaultShader;

com.unity.render-pipelines.universal/Runtime/ForwardRenderer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ public override void Setup(ScriptableRenderContext context, ref RenderingData re
247247

248248
if (generateColorGradingLUT)
249249
{
250-
m_ColorGradingLutPass.Setup(m_ColorGradingLut);
250+
m_ColorGradingLutPass.Setup(m_ColorGradingLut, ref renderingData);
251251
EnqueuePass(m_ColorGradingLutPass);
252252
}
253253

com.unity.render-pipelines.universal/Runtime/Passes/ColorGradingLutPass.cs

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public class ColorGradingLutPass : ScriptableRenderPass
1616
readonly GraphicsFormat m_HdrLutFormat;
1717
readonly GraphicsFormat m_LdrLutFormat;
1818

19+
RenderTextureDescriptor lutTextureDescriptor;
1920
RenderTargetHandle m_InternalLut;
2021

2122
public ColorGradingLutPass(RenderPassEvent evt, PostProcessData data)
@@ -53,9 +54,30 @@ Material Load(Shader shader)
5354
m_LdrLutFormat = GraphicsFormat.R8G8B8A8_UNorm;
5455
}
5556

56-
public void Setup(in RenderTargetHandle internalLut)
57+
public void Setup(in RenderTargetHandle internalLut, ref RenderingData renderingData)
5758
{
5859
m_InternalLut = internalLut;
60+
61+
ref var postProcessingData = ref renderingData.postProcessingData;
62+
bool hdr = postProcessingData.gradingMode == ColorGradingMode.HighDynamicRange;
63+
int lutHeight = postProcessingData.lutSize;
64+
int lutWidth = lutHeight * lutHeight;
65+
var format = hdr ? m_HdrLutFormat : m_LdrLutFormat;
66+
67+
lutTextureDescriptor = new RenderTextureDescriptor(lutWidth, lutHeight, format, 0);
68+
lutTextureDescriptor.vrUsage = VRTextureUsage.None; // We only need one for both eyes in VR
69+
}
70+
71+
/// <inheritdoc />
72+
public override void Configure(CommandBuffer cmd, RenderTextureDescriptor cameraTextureDescriptor)
73+
{
74+
// Create and set the render target to the LUT texture.
75+
cmd.GetTemporaryRT(m_InternalLut.id, lutTextureDescriptor, FilterMode.Bilinear);
76+
77+
// (ASG) This is required, otherwise this pass has the default camera attachment, and the code in
78+
// ScriptableRenderer.Execute enables XR mode for this pass (when in forward color grading mode).
79+
// (John): I believe this is a bug in URP, and this should be set.
80+
ConfigureTarget(m_InternalLut.Identifier());
5981
}
6082

6183
/// <inheritdoc/>
@@ -80,11 +102,7 @@ public override void Execute(ScriptableRenderContext context, ref RenderingData
80102
// Prepare texture & material
81103
int lutHeight = postProcessingData.lutSize;
82104
int lutWidth = lutHeight * lutHeight;
83-
var format = hdr ? m_HdrLutFormat : m_LdrLutFormat;
84105
var material = hdr ? m_LutBuilderHdr : m_LutBuilderLdr;
85-
var desc = new RenderTextureDescriptor(lutWidth, lutHeight, format, 0);
86-
desc.vrUsage = VRTextureUsage.None; // We only need one for both eyes in VR
87-
cmd.GetTemporaryRT(m_InternalLut.id, desc, FilterMode.Bilinear);
88106

89107
// Prepare data
90108
var lmsColorBalance = ColorUtils.ColorBalanceToLMSCoeffs(whiteBalance.temperature.value, whiteBalance.tint.value);

0 commit comments

Comments
 (0)