Bake PCSS shadow

Hi everyone!

I have the following problem:
We do have the need to render high quality soft shadows which we can achieve using PCSS. As you know does this have a major performance drawback, especially on mobile devices.
The problem is that we cannot pre-bake all shadows in blender as we have semi-dynamic objects in the scene that will change once but then stay static until they are changed again.

Changing the shadowmap refresh rate to 0 obviously helps in terms of performance and is what we are currently doing. Still, the shadowmap needs to be rendered and filtered every frame and this is what is simply too slow on mobile.

Therefore I’m asking myself if there is any way to basically bake the shadow into the shadow receiving objects of the scene?

Thanks for help!

It should be possible to render the shadow in UV space and then use that as a lightmap.
You’ll need to do the uvunwrap in blender and export the scene but it should be possible.
Might be possible with a material plugin?
cc @Evgeni_Popov

This thread may help - Shadows rendering only once inquiry

1 Like

@labris we are currently using spotlights and no directional lights (so light.autoUpdateExtends = false has no effect - but it obviously also doesn’t solve the issue when we use directional lights).

@Cedric I’m no entirely sure how to go about that as I didn’t find a way to somehow read the filtered shadowmap. Could you point me into the right direction?

Actually, there is already something available in Babylon.

https://doc.babylonjs.com/typedoc/classes/BABYLON.MeshUVSpaceRenderer

So, the idea is to render to UV Space with the shadow applied. and then use that rendered texture as a lightmap.

2 Likes

I tried to make a simple shadow baker example:

The bunny is rendered in a separate RTT with a special material which renders the shadow component into mesh uv space. After 3s, another bunny is displayed with a material that uses the baked shadow to retrieve the shadow component.

As you can see, there are artifacts, because of uv seams (the camera is close to the bunny so you can better see them). I haven’t looked into it, but this technique could be used to mitigate them:

4 Likes