Stylized Water 2 documentation

Stylized Water 2

Stylized Water 2
Author: jonathan
Version: 1.1.4
Dated: 22 Sep 2020

6.Troubleshooting/FAQ #

Transparent materials, sprites & particle effects appear below, or in front of water, regardless of position

Since transparent surfaces do not have any depth, it’s not possible to sort them on a per-pixel basis. This is the case for any transparent shader, not just the water. Instead, transparent material are sorted based on their position, render queue value and layer order to determine which material should draw over the other. For more information see the Unity manual page (also applies to orthographic camera setups).

To remedy this:

  • Set the “Order in layer” value on the Sprite/Particle System (found in the Rendering section) to a value higher than 0. This way it’ll always draw over the water
  • (Or) On the particle material, increase the “Priority” value by one
  • (Or) Set the render queue on the water material to 2999 (found under the “Advanced” tab). It’ll render behind everything else.
  • Fallback: Enable the “Alpha clipping” option on the transparent material

    Alternatively, turn on the “ZWrite” option on the water material, found under the “Advanced” tab.

    – ZWrite ON: Transparent materials will properly intersect with the water, parts can be above and below the water
    – ZWrite OFF: Transparent materials are sorted based on their position, order in layer and the material’s render queue (labeled “Priority” on URP’s particle shader). They will either render behind or in front of the water.

    Water is visible in Scene view, but not in the Game view

    On the water material, you’ll notice and error that indicates that the “Depth texture” option is disabled in your URP settings. Click the “Enable” button next to it to enable this. After which, the water will render correctly.

    Water is invisible in scene view with an orthographic camera

    Ensure Dynamic Clipping is enabled:

    Alternatively, bump up the “Near” value to ~0.5

    Water animations don’t work in scene view all of the time

    Check if animated materials are in fact enabled for the scene view. Otherwise shader animations only update when the scene view is repainted (eg. selecting something or moving the camera). This is the case for any animated shaders.

    Note: Unity 2021+ now has an “Always refresh” option here, which should be enabled.

    Water depth and intersection effect do not appear on some objects

    Objects intersecting with the water must use a shader that writes to the depth texture, otherwise there is no way for the water to tell how far away its pixels are in 3D space.

    This means sprites, unlit materials and transparent materials can’t be affected.

    (Mobile) Water looks different on the device, than it does in the editor (or PC/Consoles)

    The color gradient and intersection effects are both based on the depth texture Unity renders. On mobile platforms, the depth texture is of lower precision, so it’s possible any depth-based effect pans out a little differently.

    In order to increase the accuracy of the depth texture, ensure the camera’s far clipping plane (set on the Camera component) is as small as possible. Increasing the near place value will also be beneficial. If no objects come near the camera, you can get away with this.

    (Mobile) When using an orthographic camera, water appears below other objects/terrain and intersection effects aren’t visible

    This issue is caused by transparency sorting, mobile devices are less accurate in this manner, especially with orthographic cameras.

    To rectify this, reduce the “Far clipping plane” on your camera until it starts to clip your geometry. By default this is set to 1000 units, which is overkill for orthographic scenes. Increasing the “Near” value also helps. Secondly, move the camera as close to the environment as possible.

    These steps reduce the rendering range for the camera and therefore increase the accuracy of sorting. After which, the water should render correctly.

    Planar reflections doesn’t work with an orthographic camera
    It does, but there may be a render feature interfering (such as third-party post processing effects). Try disabling each one to see which one causes the issue. If this is the case, create a separate “clean” renderer as outlined here.

    (Planar) reflections appear mostly black

    The water reflections are a hybrid between reflection probes and planar reflections (if used). If everything in the reflection, expect meshes appears black, it’s because your scene does not have a reflection probe set up. This is always the case for brand new scene.

    Go to Window->Rendering->Lighting Settings and disable “Baked Global Illumination” check the “Auto generate” checkbox. Wait for the baking to finish, then disable it again. This will trigger the generation of a “global” reflection probe for the scene and will allow the water to reflect the skybox. It’s only required to do this once per scene.

    Alternatively: Go to GameObject->Light->Reflection probe. Ensure the reflection probe box is large enough to fit the water, and change the type to “Realtime”.

    Planar Reflections, terrain some times turns out black/red
    Why this happens exactly is not known. It occurs in the terrain shader at a specific point, where negative color values are returned.

    Refraction also distorts objects above the water

    This behavior is by design. Using the “Advanced” shading mode performs some additional calculations to largely remove these artifacts.

    Objects rendered after transparent materials, such as through the “Render Objects” render feature will still show these artifacts. This is because the water was rendered before them, so it won’t be able to filter them out.

    Translucency and sun reflection cut off

    When using the Advanced shading mode, the shadow map is used to mask the translucency/sun reflection effect, so that they’re not visible in shadows.

    If nothing in the camera view is rendering anything that casts a shadow, the shadow map isn’t rendered at all and turns blank. In turn, the water shader receives a “broken” shadow map. So generally, in a full environment this will not occur, but is worth mentioning.

    Water shows noise artifacts when viewed from afar

    This scene uses a 16k terrain, where the scene camera is 20.000 units away. At this point you’re inevitably running into precision issues. On water pixels with the skybox directly behind it, depth values are so large that artifacts start to show. In any normal situation, this won’t occur.

    Console errors

    Assertion failed on expression: ‘0 == m_CurrentBuiltInBindMask’ UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr)

    This is sometimes thrown when the shader recompiles, and appears to be a bug in Unity’s Async shader compiler. Fortunately, it’s harmless.

    Yes No Suggest edit
    Last updated on August 31, 2021
    0 of 0 users found this section helpful
    Suggest Edit