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;

Result:

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
https://docs.unity3d.com/2020.1/Documentation/Manual/SL-SurfaceShaderTessellation.html


Van Eijk, N. (2021, 30 maart). Snow Deformation Shader – HVA GPE Game Lab – Spring 2021. Game Lab. Geraadpleegd op 3 november 2021, van
https://summit2021a.game-lab.nl/2021/03/30/snow-deformation-shader/


Unity. (z.d.). Unity – Scripting API: Mathf.PerlinNoise. Unity3d. Geraadpleegd op 8 november 2021, van
https://docs.unity3d.com/ScriptReference/Mathf.PerlinNoise.html


TwoTailsGames. (z.d.). Unity tessellation shader. GitHub. Geraadpleegd op 8 november 2021, van
https://github.com/TwoTailsGames/Unity-Built-in-Shaders/blob/master/CGIncludes/Tessellation.cginc


Technologies, U. (z.d.). Unity – Scripting API: Mathf.PerlinNoise. Unity. Geraadpleegd op 8 november 2021, van
https://docs.unity3d.com/ScriptReference/Mathf.PerlinNoise.html


Fugaro, M. (z.d.). Three.js – Calculating normals after displacement in shader. Codepen. Geraadpleegd op 8 november 2021, van
https://codepen.io/marco_fugaro/pen/xxZWPWJ


Golus, B. (2020, 12 februari). Normal Mapping for a Triplanar Shader – Ben Golus. Medium. Geraadpleegd op 8 november 2021, van
https://bgolus.medium.com/normal-mapping-for-a-triplanar-shader-10bf39dca05a


Tran, T. (2018, 3 juli). Creating Snow Trails in Unreal Engine 4. Raywenderlich.Com. Geraadpleegd op 8 november 2021, van
https://www.raywenderlich.com/5760-creating-snow-trails-in-unreal-engine-4


WB Games Montreal. (z.d.). Deformable Snow Rendering in Batman: Arkham Origins. gdcvault. Geraadpleegd op 8 november 2021, van https://www.gdcvault.com/play/1020177/Deformable-Snow-Rendering-in-Batman3


Andersson, J. (z.d.). Terrain Rendering in Frostbite Using Procedural Shader Splatting. media.contentapi.ea.com. Geraadpleegd op 8 november 2021, van
https://media.contentapi.ea.com/content/dam/eacom/frostbite/files/chapter5-andersson-terrain-rendering-in-frostbite.pdf

Related Posts