googlesamples / arcore-depth-lab

ARCore Depth Lab is a set of Depth API samples that provides assets using depth for advanced geometry-aware features in AR interaction and rendering. (UIST 2020)
https://augmentedperception.github.io/depthlab/
Apache License 2.0
780 stars 153 forks source link

Material doesn't have a texture property '_CurrentDepthTexture' #17

Closed knewk closed 3 years ago

knewk commented 4 years ago

Hi, I'm running depth lab samples on Unity 2019.4.9, ARCore SDK 1.18, on Pixel 2. Seems SetDepthTexture(DepthTarget) assumes the target material has a _CurrentDepthTexture property which is not always the case. In the collider sample, none of the depth target occlusion materials have a _CurrentDepthTexture property. This results in like huge numbers of log errors on the device monitor.

09-09 09:17:47.552: E/Unity(8720): Material doesn't have a texture property '_CurrentDepthTexture' 09-09 09:17:47.552: E/Unity(8720): DepthSource:SetDepthTexture(DepthTarget) 09-09 09:17:47.552: E/Unity(8720): DepthSource:Update() 09-09 09:17:47.552: E/Unity(8720): [./Runtime/Shaders/Material.cpp line 1452] 09-09 09:17:47.552: E/Unity(8720): (Filename: ./Runtime/Shaders/Material.cpp Line: 1452)

Offending code in DepthSource.cs:

private static readonly string k_CurrentDepthTexturePropertyName = "_CurrentDepthTexture";
........
private static void SetDepthTexture(DepthTarget target)
    {
        Texture2D depthTexture = DepthTexture;

        if (target.SetAsMainTexture)
        {
            if (target.DepthTargetMaterial.mainTexture != depthTexture)
            {
                target.DepthTargetMaterial.mainTexture = depthTexture;
            }
        }
        else if (target.DepthTargetMaterial.GetTexture(k_CurrentDepthTexturePropertyName) !=
            depthTexture)
        {
            target.DepthTargetMaterial.SetTexture(k_CurrentDepthTexturePropertyName,
                depthTexture);
        }
    }
ruofeidu commented 4 years ago

Thank you knewk for reporting this!

I think by adding target.DepthTargetMaterial.HasProperty(_currentDepthTexturePropertyName) && will resolve this. We are working on pushing a new version now.

knewk commented 4 years ago

Thx, I added this "dummy" property to object occlusion shader for depth target which worked as well.
_CurrentDepthTexture("Static Depth Texture", 2D) = "" {} The include #include "Assets/GoogleARCore/SDK/Materials/ARCoreDepth.cginc" has a line sampler2D _CurrentDepthTexture; but doesn't seem to be exposed as a property. The 100,000 logs I was getting definitely effected performance. Thx again, KnewK Entertainment

ruofeidu commented 3 years ago

I think I fixed it in ARCore Depth Lab with ARCore SDK v1.24.0 of the recent releases: https://github.com/googlesamples/arcore-depth-lab/releases Thank you again for spotting this!