2
\$\begingroup\$

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 use this shader: https://roystan.net/articles/toon-water.html

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?

What could cause this issue? Feel free to ask for more info, maybe I can provide.

enter image description here

enter image description here

\$\endgroup\$
5
  • \$\begingroup\$ 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. \$\endgroup\$ – Theraot Nov 19 '20 at 11:23
  • \$\begingroup\$ 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? \$\endgroup\$ – Tudvari Nov 19 '20 at 11:34
  • \$\begingroup\$ 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. \$\endgroup\$ – Theraot Nov 19 '20 at 12:16
  • \$\begingroup\$ 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? \$\endgroup\$ – Basic Nov 24 '20 at 16:01
  • \$\begingroup\$ Yes, it's the foam color. Changed it to grey, and the user now see every water grey. He said he got fresh drivers. \$\endgroup\$ – Tudvari Nov 27 '20 at 9:54
0
\$\begingroup\$

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;
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.