Rain Post Process Shader
翻譯自Rain Post Process Shader
I wanted to show you an old project of mine where I created a rain post process shader.
First there should be at least four features which have to show up: the rain drops themselves, water which is flowing on the surfaces, there should be excluded areas from this effect and refraction which shows up if you take a closer look at the rain flooded surfaces.
下雨效果至少包含4個部分:雨水降落本身、表面上向下流動的雨水、不接受雨水效果的區域和靠近雨水表面時看到的折射效果。
The rain drops are pretty straight forward: one drop texture which is tiled several times and layered above each other is linear interpolated based on the scene depth. This just gets added to the final scene color.雨水本身的圖片 每個層之間通過場景深度進行線性插值
The next step is to build up the setup for the water flowing over the surfaces. First we need the World Normal to get information in which direction the water should flow. I have masked out the blue channel since it indicates that the normals point upwards. The rest (one minus this value) is water that flows downwards. Of course the normals have to be normalized at the start to avoid artifacts.
通過法線知道水怎麼流動,法線b通道為1,向上,其他向下,法線要歸一化
This information will be the base to create appropriate UV motions. I use it as a time mask which can be set up with brightness and contrast. In the end both UV coordinate sets (the down flowing water and the water on the ground) are interpolated based on the normal direction.
這個信息是創建uv動畫的基礎,把他用作一個時間的mask,同時給它一個明暗度和對比度值。最後,向下流的水和地上的水基於法線方向進行混合。
To avoid obvious tiling patterns on bigger surfaces I add some of the color information to the resulting UVs and use it as an offset.
為了避免較大的表面tiling比較明顯,在得到的uv上增加顏色信息作為offset。
I use the red channel of the flowing water (without color) as a base for computing the screen refraction. This is interpolated by the depth fade to see it only when nearby. It is now used as UV-set for the final scene color.
flowing water的紅通道作為基礎計算屏幕折射。通過深度漸隱插值,使只有在近處時可見。作為最終屏幕的uv。
To exclude parts of the which should not be affected I used the custom depth buffer. I compare the scene depth with the custom depth and it results into a grey scale mask which I use for masking out the rain before adding it to the scene.
為了排除不接受下雨效果的區域,用custom depth做遮罩。
推薦閱讀: