Hey folks,
Really looking forward to try the new ibl shadowing render pipeline!
BabylonJS:master
← MiiBond:mbond/ibl-shadows
opened 03:26PM - 15 May 24 UTC
This PR adds an `IblShadowsRenderPipeline` that adds shadowing for image-based l… ighting (IBL). It's applied as a post process after rendering your scene.
All control over the shadows will be done through the `IblShadowsRenderPipeline` object. After creating the pipeline, the first things that the user needs to do are:
1. Assign an IBL image with setIblTexture . This function can take either a cube map or an equirectangular map.
2. Add any meshes that you don't want casting shadows with addExcludedMesh . The apparent resolution of the shadows is directly tied to the size of the scene so you want to only include meshes that are important for shadows. e.g. a skybox should be excluded to avoid making the shadow-casting world huge as well as casting a shadow over everything.
3. Update the scene bounds whenever a shadow-casting object moves using updateSceneBounds. This will recalculate the size of the scene and trigger voxelization. This is a pretty expensive operation in WebGL 2.0 so animated shadow-casters are probably not practical.
There are several pieces to how the effect is created. First, there are two passes that are only run when needed:
* `_IblShadowsVoxelRenderer` - Responsible for building a voxel grid of the geometry in the scene as a 3D texture. This texture is used when tracing rays to the IBL and determining what is in shadow and what isn't. The voxelization only needs to be done when some geometry in the scene moves or is added/removed.
* `_IblShadowsImportanceSamplingRenderer` - Responsible for building the CDF (cumulative distribution function) maps that will make it easy to pick the most important ray directions while sampling. This is only run when the IBL changes.
The `IblShadowsRenderPipeline` also requires several maps to be output from the prepass renderer, including world normals, world positions, velocity and depth. We should change this logic to render these per camera because, right now, the prepass renderer only supports a single camera.
The `IblShadowsRenderPipeline` creates four post process passes that do the per-frame shadow calculations and apply them to the scene:
1. `_IblShadowsVoxelTracingPass` - this full-screen pass traces rays through the voxel grid using several of the prepass targets and the IBL CDF. In addition to voxel tracing, it also calculates screen-space shadows to catch small details and combines this with the lower-res shadows from the voxel tracing. This pass outputs a pretty noisy, greyscale approximation of the scene's shadows.
2. `_IblShadowsSpatialBlurPass` - this full-screen pass blurs the shadow texture.
3. `_IblShadowsAccumulationPass` - this full-screen pass accumulates the shadows over multiple frames. It copies both the accumulation and position buffers from the previous frame and uses them (in conjunction with the velocity buffer) to do this.
The output of the accumulation pass is composited onto the scene with another post-process effect.
Here's a PG to test with:
https://playground.babylonjs.com/#8R5SSE#197
**Some important exposed settings:**
* voxel resolution - the dimension of the voxel grid, in voxels. This directly affects how sharp the shadows are. Must be power-of-two.
* sample directions - how many samples of the voxel grid per pixel. Increasing this results in less noise but adds significantly to the per-frame cost of shadows
* toggling screen-space shadows - SS shadows add small shadow detail close to the shadow caster but may not be needed in all scenes so this is togglable and has various settings to control how they behave.
**Updating the voxel grid:**
* When a mesh is added or removed from a scene, the voxelization of the scene is automatically rebuilt.
* When a mesh moves in the scene, you must call `updateSceneBounds` to get the shadows to rebuild. Is there some place that I could do this automatically for users?
**Things that still need work:**
* The shadows are greyscale and are an approximation of the light intensity blocked by an object. They often over-darken surfaces because of this. I have plans to improve this and also add better support for coloured lighting.
* IBL shadows don't currently work with multiple cameras (mostly due to this issue https://forum.babylonjs.com/t/viewport-issue-when-using-prepassrenderer/51276)
* WebGPU is not yet fully supported. When WebGPU is working, I should be able to make use of compute shaders to significantly speed up voxel grid generation. This should make dynamic scene much more practical.
* Various performance and quality tweaks. e.g. support downsizing the buffers for faster speed.

I saw this thread but however the PG in this page no longer working anymore.
I am assuming because the pipeline is still under updating?
Just wondering when I should be expecting a stable version if this feature?
Wanna try it badly lol
Many thanks,
Tawibox