involved technology: Unity Shader、C#、shaderGUI()
This project was finished during my internship in Tencent games. For the game project that I was working with, I was responsible to achieve the needs of the dynamic interactive snow effect of the characters stepping on the snow, mainly the realization of snow material rendering, trajectory, and footprints.
The dynamic interactive snow effect includes the rendering of snow material and the dynamic update of footprints or trajectories. This project is developed under the unity build-in pipeline.
Rendering of the Snow
The Snow is using PBR shading and PBR textures,including Albedo, Normal, Metallic, Roughness, Ambient Occlusion, Emission Maps.
What’s more , Metallic, Roughness, Ambient Occlusion, Emission Maps are compressed into one picture, respectively in the RGBA channel.
When rendering snow, it is divided into upper snow and lower snow materials to be rendered separately, and then blend them.
This picture is the shader property panel of Snow:
Also, use shaderGUI() to adjust the shader properties panel for ease of use by other artists.
Updating the displacement texture
Place an orthogonal camera under the snow to shoot from bottom to top
At the same time, use a heightmap to control the initial height of the snow, and at the same time as the initial value of the Displacement Render Texture. use Blit() to blit with the initial heightmap to get the initial snow height.
use a material with a replacement shader to record and accumulate depth in each frame , set up shadertags for two different objects (Eg.ground and people), depending on the different shader tag to record different object depths.
We create the two render texture we’ll need each frame,RT1 and RT2. We will setup the target texture and pass the right target texture from camera to the shader according to the flag(a bool variable). For Each frame we swap the target texture to always keep the result of the shader.
after rendering (in the OnPostRender() function)we will use blit() to blit the first RT in the second RT to get the tracks depth texture and switch the flag.
Set the replacement shader to update the depth map and output a Displacement Render Texture and then calculate the new height in the ReciveDepth.shader file which will be used as a replacement shader.
Perform vertex offset and change the Normal Map of the snow material according to Displacement RT in the material render shader.
Set the surface subdivision parameters, perform mesh subdivision, and rewrite the surface subdivision function. This is used in the Build-in shader to increase model details.(this will be perfromed in the material render shader)
At the same time, a smoothing algorithm is used to smooth the area between the upper and the bottom.The algorithm use the difference between the average of the surrounding texel with the current pixel to lerp between them to achieve the smoothing.(this will be perfromed in the replacement shader while we are calculating the height map)
Perfrom PBR Lighting calculation in vert and frag in the material render shader.
Comments