Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

ARCameraBackground override material not working?

Discussion in 'AR' started by vl4dimir, Jul 12, 2018.

  1. vl4dimir

    vl4dimir

    Joined:
    Jun 28, 2012
    Posts:
    21
    Hi all, did anyone succeed in using a custom camera background shader/material to work with the ARCameraBackground component?

    I'm using a basic ARSession+AR Session Origin setup which works fine with the built-in material, but no matter which material I set as the "override material" in ARCameraBackground, I'm just getting a black background (the cube I put in the scene is being drawn though). Even setting the builtin ARCoreShader.shader as my material's shader is not working, so I'm suspecting that the shader itself is not the problem. Am I missing something?

    I'm on Unity 2018.2.0f2, using AR Foundation 1.0.0-preview.13 and ARCore XR Plugin 1.0.0-preview.17.
     
  2. vl4dimir

    vl4dimir

    Joined:
    Jun 28, 2012
    Posts:
    21
    There seems to be a bug in the ARCameraBackground component, the background renderer's render mode is not being set to
    ARRenderMode.MaterialAsBackground
    when setting the custom material. I copied the code from ARCameraBackground into my project and added this line to the the material setter:

    Code (CSharp):
    1. backgroundRenderer.mode = ARRenderMode.MaterialAsBackground;
    Hope that helps someone.
     
  3. andrew257

    andrew257

    Joined:
    Dec 11, 2017
    Posts:
    1
    Hi, I am having the same issue, my AR camera is black and not rendering, Kindly help me out, thanks !!
     
  4. tdmowrer

    tdmowrer

    Joined:
    Apr 21, 2017
    Posts:
    605
    Yep, certainly a bug here; thanks for reporting!

    A question for you folks: currently, if you start with the the material overridden, then set
    overrideMaterial = false
    , then set it back to
    true
    , that won't work unless you also re-set the
    material
    . This is because there is only a single material property, and it will be automatically set if override is false, overwriting the value you've specified. Is this a common use case? Should we store both the overridden and automatic materials separately so they are easier to switch between?
     
  5. WolfBeardedLion

    WolfBeardedLion

    Joined:
    Apr 5, 2013
    Posts:
    27
    I believe having two functions added would work best:

    (1) a function that takes a material as a parameter and sets that as the "override" material (and sets overrideMaterial to true), and

    (2) a function that sets overrideMaterial to false and adds the normal AR material back.

    This approach seems pretty inline with the rest of Unity, and should be pretty easy for developers to pick up.
     
  6. vl4dimir

    vl4dimir

    Joined:
    Jun 28, 2012
    Posts:
    21
    Yes, please! :)
     
  7. tdmowrer

    tdmowrer

    Joined:
    Apr 21, 2017
    Posts:
    605
    The latest version had this change. See the changelog.
     
  8. dradb

    dradb

    Joined:
    Jan 10, 2015
    Posts:
    86
    I'm still getting the same problem in Unity 2020.1.4 with ARFoundation 4.0.8. ARcamerabackground does not override the Camera "Clear Flags" (color or Skybox). The real world scene cannot be seen.
    I also have Unity 2019.4 installed with ARFoundation 2.1 and it works fine.
    Unity 2020.1.4 works OK with ARFoundation 3.1.3.
     
    Last edited: Sep 3, 2020
  9. dradb

    dradb

    Joined:
    Jan 10, 2015
    Posts:
    86
    tdmowrer,
    I've also now tested with ARFoundation 4.0.2, with Unity 2020.1.4. ARcamerabackground still does not override the Camera "Clear Flags" (color or Skybox). The real world scene cannot be seen.
    The ARcamerabackground script in ARF 4.0 looks very different to the previous one. Is something missing or does something else need to be added?
    Is this a bug?
     
  10. dradb

    dradb

    Joined:
    Jan 10, 2015
    Posts:
    86
    tdmowrer,
    I've just installed the new Unity 2020.2 beta. ARFoundation 4.0.8 is shown as "verified". However it still gives the same problem ... the mobile's camera view is not rendered. It only shows the default skybox on the mobile (Android).
    ARcamerabackground is attached but doesn't work. ('Use Custom Material' is unchecked)

    I've also tested URP with ARF 4 and it has the same issue.

    Help please.
     
    Last edited: Sep 4, 2020
  11. DayLightDancer

    DayLightDancer

    Joined:
    Feb 21, 2016
    Posts:
    4
    I tried several times to do something with unity but every new update just broke something that I use.
     
    Last edited: Oct 12, 2020
    K_NooKs, Slywalker and Rs like this.