Custom shadows with ShadowDepthWrapper

It is a new feature in Babylon.js 4.2 that will greatly help you display accurate shadows for meshes drawn with custom shaders (including NodeMaterial!).

Up to 4.1 you could only use the ShadowGenerator.customShaderOptions property to use a custom shader, which could be cumbersome because the shader is used for all the meshes. So, if you have different custom shaders for different meshes, it could be difficult to achieve the results you looked for.

With 4.2, you can now instruct the engine to use different shadow depth shaders to render different meshes. The ShadowDepthWrapper class is at the core of this feature.

It has been designed to be as easy to use as possible. In most cases, doing:

mesh.material.shadowDepthWrapper = new BABYLON.ShadowDepthWrapper(mesh.material, scene);

is enough to display accurate shadows for your meshes even if using custom code in the vertex/fragment shaders.

However, in some cases it may not be the most efficient way, so have a look at the doc for more information:

8 Likes

This is COOOOOOOL!

1 Like