The requirements for nodes related to river material

Hello to all the talented individuals at Babylon! Recently, our company has been involved in many projects related to rivers. While referencing numerous official water examples provided by Babylon, we’ve found that they aren’t particularly suitable for rivers. I’ve attempted to directly use node materials to create river effects, drawing from various examples. One crucial functionality needed in river creation is the ability to obtain the depth of the water. This depth information is crucial for creating different colors to depict varying depths of water, as well as for simulating foam effects at the edges where the water meets the ground. Currently, I haven’t found relevant information in the node materials or Babylon documentation. I’ve resorted to using black and white textures as a substitute, but the results are definitely less than ideal. Therefore, I’d like to inquire if there are any Babylon resources available or if it’s possible for us to obtain nodes that cater to this specific functionality.

You can use the SceneDepth block to access the depth buffer of the scene.

For eg:

Thank you for your assistance. I’ve found that in this case, the effect only works when the object is in contact with non-node materials. When the node material of this sphere in the example interacts with another object that also uses a node material, the detection effect doesn’t occur. What functionality do I need to add to the node material to make it work properly?


The depth renderer does work with node materials (https://playground.babylonjs.com/#Z1ESXA#2), but you should make sure that you don’t plug something to the alpha channel of the FragmentOutput block, else the material will be transparent and won’t write to the depth buffer. If you still want to write to the depth buffer for transparent materials, you can set the forceDepthWriteTransparentMeshes property of the depth renderer to true.

Thank you so much for your answer; it has been incredibly helpful for my work. I still have some confusion, though. Could you please continue to help me? Please take a look at the screenshot I’ve provided. The depth testing for the water seems to work well from certain angles, but when I change the angle, the effect doesn’t seem as satisfactory. Is there an explanation for this issue or any related cases and documentation available for solving it?


It’s hard to tell with just a screenshot. If you can setup a (small) repro, we may be able to help more.