Stylized Water 2 documentation

📣 UNITY 6

Reminder: this asset is developed for use with Unity 2020-2023.2

Stylized Water 3, for Unity 6, is available now!

If you have purchased a license for Stylized Water 2 less than 45 days ago you are able to upgrade for free! This option will be available until December 31st 2024. (upgrades are a fixed system, no exceptions can be made by either me or Unity staff)

A 25% upgrade discount will remain in effect until June 2025.

Stylized Water 2

Stylized Water 2
Version: 1.6.9
Review

4.1.Shader #

The shader is set to a material, which in turn can be applied to a mesh, business as usual. It will always render in Forward rendering, due to its transparent nature.

The majority of the material parameters have tooltips, if you’re unsure what something is for, mouse over to view a description. Or toggle the “Toggle tooltips” button to expand them all.

Shading modes

The advanced shading mode takes more liberty and focuses on high-end rendering. If water in your game is only something  that’s viewed in the background, or viewed from a top-down perspective it will offer little benefit. The “Simple” shading mode should always be used on mobile hardware.

Compared to the “Simple” shading mode it does:

  • Chromatic refractions, color channels are split one pixel apart
  • Caustics/sun reflection masking, even if the water does not receive shadows, the shadow map is read to avoid these effects being visible in shadows.
  • Translucency color is blended with the light color more accurately.
  • Double-sampling of refraction, which makes the color gradient also appear refracted.
  • 2nd normal map sample for distance normals.

Toggling features in a build

The shader makes use of keywords, which allows specific code to be executed or bypassed entirely. Similar to C# scripting define symbols. The keyword states are saved on the material.

When building the project to the target device, Unity will compile multiple variants of the shader code. For example, one version where point/spot lights are disabled, and another where they are enabled. Ultimately, this allows for quality/performance scaling in real time. This is called a Multi-compile keyword.

For many features such as normal maps, foam and waves this isn’t the case. If a feature isn’t enabled on the material, and the project is built, a shader variant won’t be created with the feature disabled. This means you can’t toggle a feature on/off anymore. This is because the keyword is a Shader feature. This behaviour is by design though. Because multi-compile keywords exponentially increase the amount of shader variants/permutations. Using this for every feature can result in up to 2 million shader variants, which greatly affects build times (by hours).

To learn more about this, see the related Unity manual page.

Should it be important to still allow a feature to be toggled, you can modify the shader to convert a keyword into a multi-compile variant. To do so, open up the StylizedWater2.shader file. Locate the line(s) that read #pragma shader_feature_local _WAVES and replace this with #pragma multi_compile_local _ _WAVES. You can repeat this for any other keyword.

After which, you can toggle the keyword state on a specific material through material.SetKeyword("_WAVES", true/false);.

An (perhaps easier) workaround is to create two materials. One with the feature enabled, and another one with it disabled. You’d only need to use one of these in the scene. But as long as both materials are included in a build, a shader variant for both permutations will be compiled into the build, allowing it to be toggled on/off.

Yes No Suggest edit
Last updated on July 30, 2023
5 of 5 users found this section helpful
Suggest Edit