![]() Personally I am not a fan of how the depth effect looks using the previous method. You can especially see it on the rocks where the same spots on the water get either a black or a white color based on on shallow the viewing angle is. ![]() This effect/artifact can be seen in the video below when moving around the camera. This means that when looking at the same point on the water surface, the returned depth value depends on how shallow the angle is under which you are looking at the water surface. If you were looking at the water and shooting an invisible ray from your eye towards a point of the water, the distance that the ray would travel between hitting the surface of the water and hitting the ground below the water surface is the distance that you get here from these nodes. It is very important to note that this calculated depth value is not the vertical depth of the water. Depth subtraction.įinally we Divide by a depth range/distance control parameter, Saturate the output (clamp between 0 and 1) and then perform a One Minus operation to get a white value near the shore and a black value in the deep parts of the water. We can then Subtract the 2 distances to get the desired distance which represents the Water Depth. For this, we can use the alpha component of the Screen Position (Raw) node which gives us the distance between the camera and the water surface. What we actually care about is not the distance between the camera and the objects under the water, but the distance between the surface of the water and the objects under the water. Scene depth - screen position = water depth. The distance of this ray is what is returned by the node. You can imagine it by tracing an imaginary ray from the camera towards the water that stops when it first hits an object under the water surface. In this node setup, the Scene Depth (Eye) node returns the distance (in world space units, meters) between the camera and the objects below the water. Most water shader tutorials use some variation of the following node setup to calculate a depth fade value that goes from shallow (1, white) to deep (0, black). We will use the depth value it to drive many other effects of our water such as color, opacity, refraction and foam. The single most important step in creating our water shader is figuring out the depth of the water. □ During this tutorial, newly added nodes will be marked in green so you can easily follow along to create the shader yourself from the ground up. In the scene, I created a plane and assigned it the material that we created before. Jump to heading #Sceneįor the scene, I am using The Illustrated Nature by Artkovski but you can use any scene you want. ![]() Select this material and in the Advanced Options, change the Render Queue to be Transparent. You can then create a material that uses this shader. The shader material should be set the Unlit and the surface type to Opaque. Jump to heading #Shader and materialĬreate a new Unlit Shader Graph shader. Make sure to enable the depth and opaque textures in the URP pipeline asset. ⚠️ This tutorial has been made with Unity 2022.2.6f1 and Universal RP 14.0.6.īefore starting this tutorial, there are a few things that need to be set up. The goal is not to create a physically accurate result, but rather to achieve a real-time, controllable and good-looking stylized water shader. ![]() ![]() In this tutorial I will explain step-by-step how to create a beautiful stylized water shader in Unity using Shader Graph. 31 minute read Jump to heading #Introduction ![]()
0 Comments
Leave a Reply. |