This week I have been testing a variable weather scene in Unity.
From model asset import, material creation, to post-processing, I got a basic understanding of the rendering part of the real-time rendering engine.
The effect of using displacement mapping:
Shader Code:
I mainly produce rainy and snowy environments.
The core idea of snow: texture mixing to make snow colour, and vertex offset to make snow thickness.
The addition of snow colour is completed in the fragment program, which is mainly to calculate the dot product between the normal of the object and the direction of the snow. The snow position is an angle less than 90 degrees. Code:
Snow thickness is made by vertex offset, which is mainly combined with vertex normal in the direction of snow cover, multiplied by snow thickness and snowfall; code:
The special effects of snow particles need to pay attention to the movement effect of the particles and the melting after landing. Because the snow is lighter and the flying trajectory is messy, the speed setting can be given multiple directions, and the falling speed can also be lower. Let the snow fall more slowly. The noise effect can also be enabled, but since the noise effect always exists, the snowflakes will still move after landing, which is not applicable here. The landing effect needs to turn on collision, add Mesh Collider to the objects in the scene, the particles can collide with the model, adjust the parameters to make the particles stay on the surface of the model because the scene is a static mesh, the collision quality can choose medium or low, it A set of voxels can be used to cache previous collisions so that they can be quickly reused in future frames. The effect of disappearing and melting is similar to that of screen snowflakes.
The core idea of raining: dynamic texture, a mask based on the direction of world space
I separately created an orthogonal camera and particle system with a black background in a very far place of the scene and created a RenderTexture. I captured the particle image on the RenderTexture through this orthogonal camera and obtained a dynamic black and white texture, and The dynamics of the texture can be modified and added arbitrarily.
Then I have to consider the method of calculating the mask. The rain is generally on top of the model. Here I decided to use the world normal direction float3 wNormal = WorldNormalVector(IN, o.Normal); I can give the model different faces in different directions. The colour, the positive direction of the y-axis is green, and it can be changed as the model rotates.
After obtaining the dynamic texture and black and white mask, the next product idea is very clear. Combine the mask to display the dynamic texture in the correct position, and then adjust the roughness, normal, colour and other attributes. Here we refer to some pictures showing objects in the rain and summarize some characteristic attributes, such as water absorption. The stronger the water absorption of the object, the darker the colour of the object will become when it is wetted by water.
Later, I also made moss growth based on the snowing effect. This is the final effect of the weather system: