Android depth texture precision issue.

Hi, I’m using the depth texture in Shader Graph in URP for water FX. The depth texture on Android seems a lot less precise than on PC or iOS. Have I done something wrong or is there a setting somewhere I’m not aware of?

I have made sure the shader precision settings are set to Float.

I’m using Unity 2019.3.6f1
URP 7.2.1


Same issue here, but not with shadergraph. Anyone from Unity ?

Hi!
Can you please report a bug?
Thanks!

This was fixed some time ago: [9.x.x] Fix DepthTexture precision, macros in Core.hlsl and make URP … · Unity-Technologies/Graphics@afef275 · GitHub

For mobile devices depth should always be sampled using a float sampler, for improved accuracy, which is what this fix does. Perhaps this wasn’t implemented in Shader Graph yet. If not, my guess is it will be in URP 7.4.x

@jimmikaelkael For custom shaders, you can add
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareDepthTexture.hlsl" then use
SampleSceneDepth(float 2uv)
to sample the depth texture, instead of declaring the depth texture yourself.

Yes I think it’s possible to build a repro project.

Before I do this, there’s this PR: https://github.com/Unity-Technologies/Graphics/pull/26
Might be related ? not sure…
I let you clarify if this PR is intended to fix this problem first.

This is what I’m doing already.

@jimmikaelkael yes, this PR should fix your problem

Hah, well that’s strange. That’s exactly what should fix the issue :stuck_out_tongue:

@aleksandrk So, I’ve tried in latest 2020 beta, URP 8.0.1, the precision issue persists
Tried merging https://github.com/Unity-Technologies/Graphics/pull/26, then this is fixed. Glad this PR will fix it.

1 Like

Is this being backported to 7.3.x?

Also, is this related to stencil issues on Quest?

The problem is that DeclareDepthTexture didn’t have _FLOAT in the depth texture declaration. That’s what my PR is fixing and solves the depth precision issue.

The PR you’ve been linking to is a backport to 7.x.x which means it will be part of the next 7.x.x release. Next one scheduled is 7.4 and should arrive in May.
https://github.com/Unity-Technologies/Graphics/pull/26

Thanks. I manually changed the _FLOAT declaration and the issue on Quest seems to persists? Can you confirm if the issue is also fixed on Android VR platform (specifically Quest)?

Oh that’s interesting. You might be dealing with a separate issue than what I was addressing.
Can you file a bug so the XR team can take a look and fix?

Case 1232794.

1 Like

Hey, finally got around to updating URP to 7.4.1 and it did fix my issue.

Thanks.

1 Like

Hi, we are on 2019.2.7f2
how can I fix the problem on that version of unity please. iOS seems fine, but android is off…

Declare _CameraDepthTexture like this:

TEXTURE2D_X_FLOAT(_CameraDepthTexture);
SAMPLER(sampler_CameraDepthTexture);

Thanks very much for your reply, but where do I do that please? I am not defining the depth texture in code… Unity is doing it automatically.
I just have a small script that tells Camera.main. (or whatever camera) to enable rendering of Depth information.
e.g.

GetComponent<Camera>().depthTextureMode = depthTextureMode;

but unity does not provide a parameter for precision. Its fine on iOS, but on Android… its inaccurate, or possibly needs a z-bias.

TEXTURE2D_X doesn’t exist in 2019.2.7f2 projects, how do I fix it there please ?

Hello, sorry to necro a thread, but i am experiencing this issue right now as well.

Unity 2020.3.29f1
URP 10.8.1
Shadergraph 10.8.1

i posted on the shadergraph thread here : URP - scene depth node in shadergraph not working on mobile