Tutorial: Adding Snow and Moss based on Normal Map in World Space in Godot

Prerequisites
Addons - Pixel Normal World Node & Vector Transform Node. Both can be installed from the asset library within the editor.


Shader
Since we want the moss or snow to be applied based on the normal map, we need to get the normal map direction in World Space.
Normal maps are usually stored in Tangent Space. To get the normal map direction in world space, I made a node called PixelNormalWorld.
Connect the normal map to PixelNormalWorld node and connect the output to Albedo.

The result is our normal map in world space.

Since we need the upward direction of the normal map, we’ll connect the Y to Albedo. (Y is up vector for Godot)

And now we have the mask that we’ll use for applying snow or moss. The only problem is we still have the mask on the bottom of the mesh, where snow wouldn’t fall.

We can fix this issue by only keeping the mask where the mesh normals are facing upwards.
In the Vertex Shader we convert NORMAL (vertex normals) to world space using the Vector Transform node I made. We’re using AxB(3x3) instead of the default AxB method, because we don’t want the normals to change when we move the object.

We’ll send this to the fragment shade using a varying.

In the fragment shader we’ll use the Y value of the normals to mask the PixelNormalWorld node output. We need to saturate the normal's Y as well as the end result to make sure that the values are are clamped within the [0-1] range.

Now we have a mask based on normal map direction in world space, but only in areas facing upwards.

We’ll add a smoothstep node to control the normals mask.

Use a Mix node to blend between the two textures.

Result.


