Stylized Water 2 documentation

Stylized Water 2

Stylized Water 2
Version: 1.2.0

6.Troubleshooting/FAQ #


Transparent materials (+sprites & particle effects) always appear either below, or in front of water

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 perspective 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. As long as they’re on the same render queue.
    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.

    Transparent materials underneath the water aren't refracted

    The refraction features make use of the Opaque Texture URP renders. As the name implies, this texture represents the screen’s image right after opaque geometry is drawn but before transparent materials are rendered (including water).

    Because of this, transparent materials aren’t captured in this texture, thus can’t be refracted.

    Water depth and intersection effects aren't visible in a build

    It’s likely, when the game is running on the device, a different Quality profile is used than in the editor.

    If you have different pipeline assets assigned, per quality level, ensure the “Depth Texture” option is also enabled for them.

    See the Getting Started page for more details.

    Water depth and intersection effects do not appear on some objects

    The effect relies on the depth texture Unity renders, which provides a means to measure the distance from the water surface to an object’s pixel on screen.

    As such, shaders that don’t support depth writing will not be affected. This usually means:

    • Transparent materials (water/particles/etc)
    • Unlit materials (before Unity 2021.1)
    • Sprites
    • UI elements
    • Details/grass rendered through the terrain system
    • Custom (handwritten) shaders without a DepthOnly pass
    • Anything rendered through a custom render loop, without a depth buffer (if you’re developing this, you probably already know this)


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

    On the water material, you’ll notice an 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 not visible in the scene view with an orthographic camera

    Ensure Dynamic Clipping is enabled:

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

    Error: Failed to include source file Underwater/UnderwaterFog.hlsl

    As of 2022.1 Unity changed the behaviour of their shader compiler, which causes this falsepositive error to be thrown. That part of the shader code is not supposed to be activated normally, and it’ll be stripped during the build process. So ultimately it’s harmless, and doesn’t actually mean anything is practically wrong.

    I have yet to find a way around this inconvenience!

    Water animations don't always work in scene view, or aren't smooth

    In the scene view bar, check if the “Always Refresh” option is enabled. In Unity 2019 this was called “Animated Materials“.

    If not, any kind of shader animation only update when the scene view is refreshed (eg. selecting something or moving the camera).

    Mobile hardware

    Rendering large distances is challenging on mobile hardware, due to limited hardware precision. On PC/Console the depth texture uses high precision values (16-bit), whilst on mobile it uses linear values (from 0-1, 8-bit). As such, this shader can also be affected by it.

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

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

    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.
      • For orthographic camera’s move the camera as close as possible.
    • Increase the near plane value. If no objects come near the camera, you can get away with this.

    Intersection foam starts flickering when viewed from afar (~+1000 units)

    The intersection foam effect is based on the depth texture Unity renders. On mobile platforms, this depth texture is of lower precision than on PC/Consoles. This means in the far distance, the depth value (of any given pixel) may be very close to that of the geometry behind it (eg. 0.98553 vs 0.98554). Due to floating point rounding errors, these values may move back and forth, which translates to a visual artefact.


    • Limit the maximum render range by decreasing the camera’s far clipping plane value (set on the Camera component).
    • Draw the foam effect through Vertex Colors so that its based on static data.

    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.
    • 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.


    Light reflections shows noisy artefacts

    This is entirely attributed to the result of texture compression.

    You can disable compression on the normal map that is being used on the material to resolve this, at the cost of more memory (~4x).

    Refraction also distorts objects above the water

    Objects rendered after transparent materials, such as through the Render Objects render feature or Overlay cameras will show these artifacts.

    This is because these objects will render after the water has been. As such, when the water shader renders it’ll have no knowledge of these objects, and can’t filter them out.

    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 floating point precision issues. On water pixels with the skybox directly behind it, depth values are reaching infinity and causes artifacts to show.

    In any normal situation, this won’t occur. Otherwise, ensure there is some geometry behind/underneath the water.

    Yes No Suggest edit
    Last updated on September 7, 2022
    2 of 2 users found this section helpful
    Suggest Edit