Stylized Water 2 – Underwater Rendering docs

Stylized Water 2 - Underwater Rendering (Extension)

Stylized Water 2 - Underwater Rendering (Extension)
Author: jonathan
Version: 1.0.4
Dated: 17 May 2021

4.Transparent Materials #

Familiarity with Shader Graph is assumed for this section!

The underwater fog is based on the scene depth, to determine how far away a pixel is away from the camera.

Transparent materials do not contribute to the depth texture Unity renders, therefore cannot be affected by fog. The way around this is to calculate the fog directly in the transparent shader. As such, Unity’s built-in shaders will not support this if the material is set to transparent.

As an alternative, use the Universal Render Pipeline/FX/Underwater Particle shader on particle materials that are used underwater (such as the light rays in the demo scene)

In the StylizedWater2/Shaders/Underwater/Shader Graph folder you’ll find all the functionality needed to add support to a transparent shader.

You’ll find two sub-graphs in this folder:

Apply Underwater Fog

This applies the underwater fog in the same way as it’s done in the post processing effect. The input color will be blended with the fog color based on the fog density. The density output (value gets lower/darker further away from the camera) can also be used to multiply the graph alpha value.

The result will be that the material fades out into the fog.

  • The fog color already has lighting applied to it, hence it adds onto the graph’s Emission value, not the albedo. This applies to both Lit and Unlit graphs.
  • For Lit graphs, pipe in the Fog Density output into the Occlusion port on the Master Node. This avoids environment reflections being visible through the fog.

Get Underwater Mask

This mask (in screen-space) is white for the area of the screen that’s underwater, and black for anything above the water. A common usage would be to multiple the alpha value of the graph, so the material’s pixels are only visible underneath the water.

Note: Only the Red color channel has data, the rest is blank.

Graph example

Example for both Lit and Unlit graphs, where the fog color is applied.

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