Skip to content

Commit 2f3e23c

Browse files
[HDRP][Compositor] Fix issue with screen space UI not drawing (#2070)
* Fix issue with screen space UI not drawing on the graphics compositor * Revert minor code change * Remove debug/log messages * Hide internal compositor data from inspector Co-authored-by: sebastienlagarde <sebastien@unity3d.com>
1 parent 4ea9e92 commit 2f3e23c

File tree

3 files changed

+69
-28
lines changed

3 files changed

+69
-28
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
121121
- Fix nan in pbr sky
122122
- Fixed Light skin not properly applied on the LookDev when switching from Dark Skin (case 1278802)
123123
- Fixed accumulation on DX11
124+
- Fixed issue with screen space UI not drawing on the graphics compositor (case 1279272).
124125

125126
### Changed
126127
- Preparation pass for RTSSShadows to be supported by render graph.

com.unity.render-pipelines.high-definition/Runtime/Compositor/CompositionLayer.cs

Lines changed: 47 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ public enum ResolutionScale
5454
[SerializeField] bool m_ClearAlpha = true; // Specifies if the Alpha channel will be cleared when stacking this camera over the previous one (for overlays)
5555
[SerializeField] Renderer m_OutputRenderer = null; // Specifies the output surface/renderer
5656
[SerializeField] LayerType m_Type;
57+
58+
public Camera sourceCamera => m_Camera;
5759
[SerializeField] Camera m_Camera = null; // The source camera for the layer (were we get the default properties). The actual rendering, with overridden properties is done by the m_LayerCamera
5860
[SerializeField] VideoPlayer m_InputVideo = null;
5961
[SerializeField] Texture m_InputTexture = null;
@@ -131,6 +133,9 @@ public float aspectRatio
131133

132134
[SerializeField] Camera m_LayerCamera;
133135

136+
// Returns true if this layer is using a camera that was cloned internally for drawing
137+
bool isUsingACameraClone => !m_LayerCamera.Equals(m_Camera);
138+
134139
private CompositorLayer()
135140
{
136141
}
@@ -210,39 +215,47 @@ public void Init(string layerID = "")
210215
m_Camera = CompositionManager.GetSceceCamera();
211216
}
212217

218+
var compositor = CompositionManager.GetInstance();
219+
213220
// Create a new camera if necessary or use the one specified by the user
214221
if (m_LayerCamera == null && m_OutputTarget == OutputTarget.CameraStack)
215222
{
216-
217-
// Clone the camera that was given by the user. We avoid calling Instantiate because we don't want to clone any other children that might be attachen to the camera
218-
var newCameraGameObject = new GameObject("Layer " + layerID)
219-
{
220-
hideFlags = HideFlags.HideInInspector | HideFlags.HideInHierarchy | HideFlags.HideAndDontSave
221-
};
222-
m_LayerCamera = newCameraGameObject.AddComponent<Camera>();
223-
newCameraGameObject.AddComponent<HDAdditionalCameraData>();
224-
CopyInternalCameraData();
225-
226-
m_LayerCamera.name = "Compositor" + layerID;
227-
m_LayerCamera.gameObject.hideFlags = HideFlags.HideInInspector | HideFlags.HideInHierarchy | HideFlags.HideAndDontSave;
228-
if(m_LayerCamera.tag == "MainCamera")
223+
if (!compositor.IsThisCameraShared(m_Camera))
229224
{
230-
m_LayerCamera.tag = "Untagged";
225+
// The camera is not shared, so it is safe to use it directly in the layer (no need to clone it)
226+
m_LayerCamera = m_Camera;
231227
}
232-
233-
// Remove the compositor copy (if exists) from the cloned camera. This will happen if the compositor script was attached to the camera we are cloning
234-
var compositionManager = m_LayerCamera.GetComponent<CompositionManager>();
235-
if (compositionManager != null)
228+
else
236229
{
237-
CoreUtils.Destroy(compositionManager);
238-
}
230+
// Clone the camera that was given by the user. We avoid calling Instantiate because we don't want to clone any other children that might be attachen to the camera
231+
var newCameraGameObject = new GameObject("Layer " + layerID)
232+
{
233+
hideFlags = HideFlags.HideInInspector | HideFlags.HideInHierarchy | HideFlags.HideAndDontSave
234+
};
235+
m_LayerCamera = newCameraGameObject.AddComponent<Camera>();
236+
newCameraGameObject.AddComponent<HDAdditionalCameraData>();
237+
CopyInternalCameraData();
238+
239+
m_LayerCamera.name = "Compositor" + layerID;
240+
m_LayerCamera.gameObject.hideFlags = HideFlags.HideInInspector | HideFlags.HideInHierarchy | HideFlags.HideAndDontSave;
241+
if (m_LayerCamera.tag == "MainCamera")
242+
{
243+
m_LayerCamera.tag = "Untagged";
244+
}
239245

240-
var cameraData = m_LayerCamera.GetComponent<HDAdditionalCameraData>();
241-
if (cameraData == null)
242-
{
243-
m_LayerCamera.gameObject.AddComponent(typeof(HDAdditionalCameraData));
244-
}
246+
// Remove the compositor copy (if exists) from the cloned camera. This will happen if the compositor script was attached to the camera we are cloning
247+
var compositionManager = m_LayerCamera.GetComponent<CompositionManager>();
248+
if (compositionManager != null)
249+
{
250+
CoreUtils.Destroy(compositionManager);
251+
}
245252

253+
var cameraData = m_LayerCamera.GetComponent<HDAdditionalCameraData>();
254+
if (cameraData == null)
255+
{
256+
m_LayerCamera.gameObject.AddComponent(typeof(HDAdditionalCameraData));
257+
}
258+
}
246259
}
247260
m_ClearsBackGround = false;
248261
m_LayerPositionInStack = 0; // will be set in SetupLayerCamera
@@ -299,7 +312,6 @@ public void Init(string layerID = "")
299312
}
300313
}
301314

302-
var compositor = CompositionManager.GetInstance();
303315
if (m_OutputRenderer != null && Application.IsPlaying(compositor.gameObject))
304316
{
305317
MaterialPropertyBlock propertyBlock = new MaterialPropertyBlock();
@@ -317,7 +329,7 @@ public void Init(string layerID = "")
317329
if (layerData == null)
318330
{
319331
layerData = m_LayerCamera.gameObject.AddComponent<AdditionalCompositorData>();
320-
layerData.hideFlags = HideFlags.HideAndDontSave;
332+
layerData.hideFlags = HideFlags.HideAndDontSave | HideFlags.HideInInspector;
321333
}
322334
// Reset the layer params (in case we cloned a camera which already had AdditionalCompositorData)
323335
if (layerData != null)
@@ -370,7 +382,8 @@ public bool Validate()
370382

371383
public void DestroyRT()
372384
{
373-
if (m_LayerCamera != null)
385+
// We should destroy the layer camera only if it was cloned
386+
if (m_LayerCamera != null && isUsingACameraClone)
374387
{
375388
var cameraData = m_LayerCamera.GetComponent<HDAdditionalCameraData>();
376389
if (cameraData)
@@ -462,6 +475,12 @@ public void SetAdditionalLayerData()
462475

463476
internal void CopyInternalCameraData()
464477
{
478+
if (!isUsingACameraClone)
479+
{
480+
// we are using directly the source camera, so there is no need to copy any properties
481+
return;
482+
}
483+
465484
// Copy/update the camera data (but preserve the camera depth/draw-order [case 1264552])
466485
var drawOrder = m_LayerCamera.depth;
467486
m_LayerCamera.CopyFrom(m_Camera);

com.unity.render-pipelines.high-definition/Runtime/Compositor/CompositionManager.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -797,6 +797,27 @@ void CustomRender(ScriptableRenderContext context, HDCamera camera)
797797
CommandBufferPool.Release(cmd);
798798
}
799799

800+
/// <summary>
801+
/// Helper function that indicates if a camera is shared between multiple layers
802+
/// </summary>
803+
/// <param name="camera">The input camera</param>
804+
/// <returns>Returns true if this camera is used to render in more than one layer</returns>
805+
internal bool IsThisCameraShared(Camera camera)
806+
{
807+
int count = 0;
808+
foreach (var layer in m_InputLayers)
809+
{
810+
811+
if (layer.outputTarget == CompositorLayer.OutputTarget.CameraStack &&
812+
camera.Equals(layer.sourceCamera))
813+
{
814+
count++;
815+
}
816+
}
817+
// If we found the camera in more than one layer then it is shared between layers
818+
return count > 1;
819+
}
820+
800821
static public Camera GetSceceCamera()
801822
{
802823
if (Camera.main != null)

0 commit comments

Comments
 (0)