Recreating snow with a shader

7. Final Result

Our final result is snow that accumulates for depth and edges, with research done to other techniques as well. It does not matter what shape the object is, it is all taken into calculation. There was research done into the snow itself and how to make it look better.

The final result

7.1. Performance and Scale

This research was not focused on performance but rather how to create visually good looking snow. There are some ways to improve performance. To improve performance we could use techniques from the research of Van Eijk (2021). But we could also tweak a couple of parameters. To make the snow plane bigger but still keep good performance we ignore certain visual techniques when you go too far away. Techniques like: box blur and the edges. At a certain distance you could even remove the depth entirely due to it not being visible.

7.2 Improvements

There are a few things that were tried during the research but could not be successfully implemented. Below will be some of the techniques that could not be finished on time. The plan is to still implement them at a later date.

7.3.1 Remapping the normals

Because of the displacement the surface looked sharp at some places. To combat this, an attempt was made to use Phong Tessellation as seen in 3.6.1 Implementing Phong tessellation. After hours this was still not implemented correctly and therefore abandoned for the time being.

One method found was by Andersson (z.d.) where he applied the logic of remapping normals to the frostbite engine.

Remapping normals in frostbite (Andersson, z.d.)

Using that code we ported it to HLSL:

float3 filterNormal(sampler2D tex, float2 uv, float texelSize, float texelAspect) 
    float4 h; 

    h[0] = tex2Dlod(tex, float4(uv + texelSize * float2( 0,-1),0,0)).r * texelAspect; 
    h[1] = tex2Dlod(tex, float4(uv + texelSize * float2(-1, 0),0,0)).r * texelAspect; 
    h[2] = tex2Dlod(tex, float4(uv + texelSize * float2( 1, 0),0,0)).r * texelAspect; 
    h[3] = tex2Dlod(tex, float4(uv + texelSize * float2( 0, 1),0,0)).r * texelAspect;
    float3 n; 
    n.z = h[0] - h[3]; 
    n.x = h[1] - h[2]; 
    n.y = 2; 

    return normalize(n); 

This resulted in a surface that had normals but the result was not quite the way I wanted. With 1 line we can see the normals as colors.

o.Albedo = o.Normal + 0.5 * 0.5;


7.3.2 Triplanar normal mapping

Stretched textures

When making depth with box blur, a problem was encountered. On the sides our texture would be stretched and not look as beautiful as it could. To combat this, triplanar mapping could be applied. A great example was made by Golus (2020). When implementing this example we encountered an issue. That issue was that since we are blending multiple normal maps, our results would not come out the way we wanted to. Our surface normals were also not correct, contributing to the issues.

8. Sources

Unity. (z.d.-a). Unity – Manual: Surface Shaders with DX11 / OpenGL Core Tessellation. Unity3d. Geraadpleegd op 8 november 2021, van

Van Eijk, N. (2021, 30 maart). Snow Deformation Shader – HVA GPE Game Lab – Spring 2021. Game Lab. Geraadpleegd op 3 november 2021, van

Unity. (z.d.). Unity – Scripting API: Mathf.PerlinNoise. Unity3d. Geraadpleegd op 8 november 2021, van

TwoTailsGames. (z.d.). Unity tessellation shader. GitHub. Geraadpleegd op 8 november 2021, van

Technologies, U. (z.d.). Unity – Scripting API: Mathf.PerlinNoise. Unity. Geraadpleegd op 8 november 2021, van

Fugaro, M. (z.d.). Three.js – Calculating normals after displacement in shader. Codepen. Geraadpleegd op 8 november 2021, van

Golus, B. (2020, 12 februari). Normal Mapping for a Triplanar Shader – Ben Golus. Medium. Geraadpleegd op 8 november 2021, van

Tran, T. (2018, 3 juli). Creating Snow Trails in Unreal Engine 4. Raywenderlich.Com. Geraadpleegd op 8 november 2021, van

WB Games Montreal. (z.d.). Deformable Snow Rendering in Batman: Arkham Origins. gdcvault. Geraadpleegd op 8 november 2021, van

Andersson, J. (z.d.). Terrain Rendering in Frostbite Using Procedural Shader Splatting. Geraadpleegd op 8 november 2021, van

Related Posts