# Depth Texture has different result than ToggleDebugVisualization

**URL:** <https://community.nianticspatial.com/t/depth-texture-has-different-result-than-toggledebugvisualization/537>\
**Category:** Bug Reports\
**Created:** [November 12, 2021, 3:28pm UTC](https://community.nianticspatial.com/t/depth-texture-has-different-result-than-toggledebugvisualization/537 "2021-11-12T15:28:22Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Will\_Tesler](https://avatars.discourse-cdn.com/v4/letter/w/c5a1d2/32.png) [@Will\_Tesler](https://community.nianticspatial.com/u/Will_Tesler)\
**Post date:** [November 12, 2021, 3:28pm UTC](https://community.nianticspatial.com/t/depth-texture-has-different-result-than-toggledebugvisualization/537/1 "2021-11-12T15:28:22Z")

</div>

- **Issue category** : Depth
- **Issue Environment** : On Device
- **ARDK version** : 1.0.1
- **Unity Version** : 2020.3 LTS
- **OS** : Windows
- **Device Type** : Android
- **IDE** : Rider

I am following the [Intermediate Depth Tutorial](https://www.youtube.com/watch?v=FWIhuqrroOQ) and I am finding that the depth map produced by the Depth Manager texture looks worse than the depth map produced when toggling on `ToggleDebugVisualization`. Here are two images showing the difference:

 ![Screenshot_20211111-185037_ArGame](https://us1.discourse-cdn.com/niantic/original/1X/d2c2ef277a862f667b14e3a587a0a99eea836f74.jpeg)

You can note that the first image is able to resolve the doorway behind the bottle, while the depth texture one to the right cannot resolve depth in the distance.

Why do these two versions diverge? What is `ToggleDebugVisualization` doing that makes it superior to the custom approach?

---

<div class="post-metadata">

**Author:** ![Umaiya\_Doddamani1](https://avatars.discourse-cdn.com/v4/letter/u/439d5e/32.png) [@Umaiya\_Doddamani1](https://community.nianticspatial.com/u/Umaiya_Doddamani1)\
**Post date:** [November 12, 2021, 5:53pm UTC](https://community.nianticspatial.com/t/depth-texture-has-different-result-than-toggledebugvisualization/537/2 "2021-11-12T17:53:55Z")

</div>

Hello Will, I’d like to get our team a little more information about your project so we can repro the issue to get this issue resolved as soon as possible. Can you please provide the below details?

Unity version:  
Device type:  
OS:  
IDE:  
Any other helpful info:  
Thank you.

---

<div class="post-metadata">

**Author:** ![Will\_Tesler](https://avatars.discourse-cdn.com/v4/letter/w/c5a1d2/32.png) [@Will\_Tesler](https://community.nianticspatial.com/u/Will_Tesler)\
**Post date:** [November 12, 2021, 11:11pm UTC](https://community.nianticspatial.com/t/depth-texture-has-different-result-than-toggledebugvisualization/537/3 "2021-11-12T23:11:17Z")

</div>

I updated the header to fill in those fields. The most critical thing is the screenshot which I shared which shows the difference.

---

<div class="post-metadata">

**Author:** ![Will\_Tesler](https://avatars.discourse-cdn.com/v4/letter/w/c5a1d2/32.png) [@Will\_Tesler](https://community.nianticspatial.com/u/Will_Tesler)\
**Post date:** [November 15, 2021, 2:39am UTC](https://community.nianticspatial.com/t/depth-texture-has-different-result-than-toggledebugvisualization/537/4 "2021-11-15T02:39:02Z")

</div>

I wanted to update with a solution. I looked at the existing shaders and augmented my frag function in the shader to look like:

```auto
fixed4 frag (v2f i) : SV_Target
{
     float2 depthUV = float2(i.depth_uv.x / i.depth_uv.z, i.depth_uv.y / i.depth_uv.z);
     float rawDepth = tex2D(_DepthTex, depthUV).r;

     float scaledDepth = rawDepth * (_DepthScaleMax - _DepthScaleMin) + _DepthScaleMin;

     float scaledDisparity = 1.0f / scaledDepth;
     float normDisparity = scaledDisparity / _MaxDisparity;

     return normDisparity;
}

```

And I am setting \_MaxDisparity to 4 and \_DepthScaleMax to 1 and \_DepthScaleMin to 0.

This produces an effect more consistent with `ToggleDebugVisualization`.

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/niantic/user_avatar/community.nianticspatial.com/system/32/13_2.png) [@system](https://community.nianticspatial.com/u/system)\
**Post date:** [November 15, 2021, 4:39am UTC](https://community.nianticspatial.com/t/depth-texture-has-different-result-than-toggledebugvisualization/537/5 "2021-11-15T04:39:30Z")

</div>

This topic was automatically closed 2 hours after the last reply. New replies are no longer allowed.
