In an earlier post, I showed how to make caustics with a material function. This is the light function method. This system functions much in the same way the earlier one did, except instead of world position determining the size of the caustics, I used a texture coordinate, and since pixel depth is not available to light function materials, I used the distance between the absolute world position and camera position. There is a second directional light in this scene which does not cast dynamic lighting or shadows, but projects the caustics function into the world. This method respects all material qualities and there is the capability of using both shadow maps and dynamic shadows to improve the quality of the function. However, light functions do not support colored textures (I believe the performance benefit comes from handling most functions using 1-vectors as opposed to RGB 3-vectors), so the caustics are completely desaturated here.
Aside from the color issue, this method supports all the functions of the previous caustics system: the texture blurs and fades out as it approaches the bottom of the water. The caustics are mapped and aligned with the directional light as if it has been cast from the sun. And it even cuts off at the water level! On top of all that, this method also respects the shadow environment and surface properties (color, metallic, roughness, etc). This is the proper way to handle caustics in UE4. The light function uses 85 instructions.
I also used the material function method to shade the particles in the water.
This caustics texture was made with the free caustics generator provided with Allegorithmic's Substance Player. The player is free as well. The distortion is provided by a simple noise texture converted to a normal map. I provided the assets below. Please note if you wish to use a texture for the light function, flag the compression as a Grayscale image. This will use the same amount of memory as a standard texture but improve the quality by decompressing the texture. Because the caustics function relies heavily on the quality of the mipmaps, and to eliminate tiling, it is a much better idea to make sure the texture is large enough so that accurate mipmaps can be produced. Alternatively, you can also hide the texture in one of the channels of a larger mask texture to save memory.
Click here to download the caustics texture, wavy normals, and a Phong material function.
No comments:
Post a Comment