arfoundation-samples icon indicating copy to clipboard operation
arfoundation-samples copied to clipboard

[Bug] URP with ARFoundation-ARKit in Unity2020.2.1f1 metal error!

Open weacw opened this issue 5 years ago • 18 comments

Describe the bug Using ARFoundation ARKit with URP 10.2.2 Camera is black and XCode log

metal: Error creating pipeline state (Unlit/ARKitBackground): depthAttachmentPixelFormat is not valid and shader writes to depth
(null)You can only call cameraDepthTarget inside the scope of a ScriptableRenderPass. Otherwise the pipeline camera target texture might have not been created or might have already been disposed.
UnityEngine.Rendering.Universal.ScriptableRenderer:get_cameraDepthTarget()
UnityEngine.XR.ARFoundation.ARBackgroundRendererFeature:AddRenderPasses(ScriptableRenderer, RenderingData&)
UnityEngine.Rendering.Universal.ScriptableRenderer:AddRenderPasses(RenderingData&)
UnityEngine.Rendering.Universal.ForwardRenderer:Setup(ScriptableRenderContext, RenderingData&)
UnityEngine.Rendering.Universal.UniversalRenderPipeline:RenderSingleCamera(ScriptableRenderContext, CameraData, Boolean)
UnityEngine.Rendering.Universal.UniversalRenderPipeline:RenderCameraStack(ScriptableRenderContext, Camera)
UnityEngine.Rendering.Universal.UniversalRenderPipeline:Render(ScriptableRenderContext, Camera[])
UnityEngine.Rendering.RenderPipelineManager:DoRenderLoop_Internal(RenderPipelineAsset, IntPtr, List`1)

Smartphone (please complete the following information):

  • Device: iPhone12
  • OS: iOS 14.3
  • Unity version:Unity2020.2.1f1
  • ARFoundation version:4.1.1
  • URP version:10.2.2

weacw avatar Jan 06 '21 14:01 weacw

The message you posted is just a warning and should not cause a black screen. We will fix the warning (see issue tracker) but that is not the issue here.

Have you followed these steps to setup ARFoundation for URP?

tdmowrer avatar Jan 06 '21 23:01 tdmowrer

The message you posted is just a warning and should not cause a black screen. We will fix the warning (see issue tracker) but that is not the issue here.

Have you followed these steps to setup ARFoundation for URP?

Thank you for your reply!

It works normally when I return to version 2019. Use 2020.2.1 to black screens!

Does URP need more memory than builtin ? I'm testing AR Foundation on URP with UAAL, and the memory is maintained at about 300M+ (BuiltIn:~220+)when I unload the unity (Destroyed ARSession, etc.)

weacw avatar Jan 07 '21 01:01 weacw

Same problem here. 2019.x works. 2020.2f1 black screen.

Schaggo avatar Jan 11 '21 18:01 Schaggo

The "cameraDepthTarget" is a known warning message that appears with URP 10.2. https://issuetracker.unity3d.com/issues/urp-ar-foundation-warning-message-regarding-cameradepthtarget-with-urp-slash-ar-foundation-projects

This is just a warning message and does not affect rendering, apart from the per-frame warning message.

The "Error creating pipeline state" message is a separate issue and most likely the source of your problem. Are you trying to render the background to a separate RenderTexture in your project?

todds-unity avatar Jan 15 '21 02:01 todds-unity

The "cameraDepthTarget" is a known warning message that appears with URP 10.2. https://issuetracker.unity3d.com/issues/urp-ar-foundation-warning-message-regarding-cameradepthtarget-with-urp-slash-ar-foundation-projects

This is just a warning message and does not affect rendering, apart from the per-frame warning message.

The "Error creating pipeline state" message is a separate issue and most likely the source of your problem. Are you trying to render the background to a separate RenderTexture in your project?

Thank you for your reply.

render the background to a separate RenderTexture in your project No. I m used default setting in urp. It's working on Unity 2019.4.xf1, Not working in 2020.x. It's Black Screen!

weacw avatar Jan 15 '21 14:01 weacw

We have not been able to reproduce this issue. Please log a bug with an project that reproduces the issue and post the case ID here.

tdmowrer avatar Jan 15 '21 19:01 tdmowrer

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Jan 23 '21 05:01 stale[bot]

I seem to have discovered the cause of the black screen. I use Camera stacking

uiCamera = GameObject.FindWithTag(ConstKey.CONST_UI_CAMERA_TAG).GetComponent<Camera>();
var tmp_MainCamera = Camera.main;
var tmp_MainAdditionalCameraData = tmp_MainCamera.GetUniversalAdditionalCameraData();
tmp_MainAdditionalCameraData.cameraStack.Add(uiCamera);

weacw avatar Jan 31 '21 02:01 weacw

I to have the same problem with the camera stacks, why would this cause such an issue?

creativewax avatar Feb 01 '21 12:02 creativewax

just worked out how to solve my problem, basically I wanted two cameras, one for UI and one for the AR Stuff, the Overlay camera stack causes the black screen problem, since I am new to URP I have just noticed you can set the priority flag, on setting the UI camera back to base and setting priority to 1 they both now render fine

creativewax avatar Feb 01 '21 12:02 creativewax

just worked out how to solve my problem, basically I wanted two cameras, one for UI and one for the AR Stuff, the Overlay camera stack causes the black screen problem, since I am new to URP I have just noticed you can set the priority flag, on setting the UI camera back to base and setting priority to 1 they both now render fine

Thank you! I returned to the 2019 version. 2020 is not yet stable

weacw avatar Feb 01 '21 12:02 weacw

actually this only solved it in the editor, building for iOS shows the same problem with multiple cameras

creativewax avatar Feb 10 '21 12:02 creativewax

That's unfortunate. Heading back to 2019 from 2020.3.2 (LTS). Even as a Salient error I was still getting most of what I needed in 2019. Will check back with the next update.

natzke avatar Apr 05 '21 05:04 natzke

That's unfortunate. Heading back to 2019 from 2020.3.2 (LTS). Even as a Salient error I was still getting most of what I needed in 2019. Will check back with the next update.

I had the same issue in Unity 2020.3.1f1. Updating AR Foundation (4.0.12 -> 4.1.7) and URP (10.3.2 -> 10.4.0) solved the black screen problem.

However, a new issue popped up as the stacked cameras' perspective didn't match the AR camera, even though they had the same settings in the editor.

It turns out the AR camera's settings are updated at runtime, possibly once the session is initialized. Manually setting FOV of the stacked cameras once the AR session state changes to SessionTracking helped and now the stacked cameras work as expected.

sebastianewak avatar Apr 12 '21 09:04 sebastianewak

We just published 4.1.7, which should fix the issue. Looks like it did for @sebastianewak :)

tdmowrer avatar Apr 13 '21 00:04 tdmowrer

This is still broken in 2019.4.19f1, AR Foundation 4.1.7, URP 7.5.3

mksbamford avatar Apr 13 '21 16:04 mksbamford

This is still broken in 2019.4.19f1, AR Foundation 4.1.7, URP 7.5.3

This issue was specific to URP 10+, so it sounds like you are seeing a different, possibly unrelated issue. Please file a bug by following the instructions at https://unity3d.com/unity/qa/bug-reporting.

tdmowrer avatar Apr 14 '21 23:04 tdmowrer

@tdmowrer Perhaps best for another github issue, but I've recently upgraded my project from Unity 2019 LTS, to 2020.3.20f1 and ARFoundation 4.1.7 , and had a similar black-screen issue on XR Plugin ARKit, caused by

Metal: Error creating pipeline state (Unlit/ARKitBackground): depthAttachmentPixelFormat is not valid and shader writes to depth

According to one of the team-members at Unity,

Team took a look, and wanted me to pass along this:

This error message is the critical issue.

Metal: Error creating pipeline state (Unlit/ARKitBackground): depthAttachmentPixelFormat is not valid and shader writes to depth

When the developer is rendering to a RenderTexture using the ARKitBackground shader, the RenderTexture must have a valid depth buffer.

https://docs.unity3d.com/ScriptReference/RenderTexture-depth.html

Inputting a non-zero depth buffer solved these issues for me; also, following other suggestions in this thread, i.e. downgrades, solves the problem as well. I don't remember seeing such a comment in the Unity documentation for ARFoundation (XR ARkit), and it should be included.

gblikas avatar Oct 22 '21 21:10 gblikas