# Water shader in Unity3D not working on some Linux distributions/some Mac OS?

I've got reports from some Linux users that the game's water isn't rendered on his machine.

3 example operating systems:

• Ubuntu 20.04 (with kernel 5.4.0-54-generic x86_64

• Linux 4.15 Linux Mint 19.2 64bit

• Mac OS X 10.13.6

I've made a small change so I can use it in orthographic projection as well:

            float existingDepthLinear = 0;

if (unity_OrthoParams.w > 0)
{
// orthographic camera
#if defined(UNITY_REVERSED_Z)
existingDepthLinear = 1.0f - existingDepth01;
#endif
existingDepthLinear = (existingDepthLinear * _ProjectionParams.z) + _ProjectionParams.y;
}
else
{
// perspective camera
existingDepthLinear = LinearEyeDepth(existingDepth01);
}

// Difference, in Unity units, between the water's surface and the object behind it.
float depthDifference = existingDepthLinear - i.screenPosition.z;


I've got a feeling that

            #if defined(UNITY_REVERSED_Z)
existingDepthLinear = 1.0f - existingDepth01;
#endif


is what causing the issue.

When I remove it, on my PC, which was working well until now, the whole surface will be just foam. So plain white. Just like on their computers.

So maybe UNITY_REVERSED_Z is not defined?

• Is the noise procedural? I'm thinking that perhaps the noise that makes the foam is coming up as 1 everywhere, making the water completely white. Wild guess. – Theraot Nov 19 '20 at 11:23
• Yes, the noise is procedural, based on a noise texture, if I recall. That's my first guess as well, but why doesn't the noise works on some linux machines? – Tudvari Nov 19 '20 at 11:34
• Can't come up with a convincing hypothesis. At least it should be relatively easy to test if you change the color of the foam. If we go by Linux being the cause, then I'd say it is a GPU drivers problem. – Theraot Nov 19 '20 at 12:16
• What graphics cards and drivers? I haven't encountered this myself, but know hardware support for various capabilities can be quite patchy depending on the driver installed. Assuming you're referring to this: github.com/IronWarrior/ToonWaterShader/blob/master/Assets/…, I can't see anything obviously problematic (like branching) but perhaps try cutting operations a block at a time to see if there are specific operations that fail? – Basic Nov 24 '20 at 16:01
• Yes, it's the foam color. Changed it to grey, and the user now see every water grey. He said he got fresh drivers. – Tudvari Nov 27 '20 at 9:54

There was a bug in the shader's code. The issue was ocurring on the machines where the Z buffer is reversed.

In that case the existingDepth01 should be inverted, but by mistake... well, I messed up... I reverted the wrong variable, and also in the line after that I used a wrong variable in the calculation. :D And I couldn't see these obvious errors...

It was working on most of the machines only through sheer luck.

Here's the problematic part, fixed:

#if defined(UNITY_REVERSED_Z)
existingDepth01 = 1.0f - existingDepth01;
#endif

existingDepthLinear = (existingDepth01 * _ProjectionParams.z) + _ProjectionParams.y;