Skip to content

Conversation

sunag
Copy link
Collaborator

@sunag sunag commented Feb 15, 2025

Description

The PR introduces volumetric lighting compatible with native Three.js lighting. Some improvements were needed to the lighting system, the next step now is to normalize the changes to work in the other examples.

Volumetric lighting can be executed in the same rendering pass, but when used in post-processing we can use some denoising approach and improve performance by reducing the resolution of the ray-marching buffer.

Currently fog density is related only to additive blending, that's why volumetric lighting instead of volumetric fog, but I have plans to support normal blending for other fog effects.

Shadow calculations are now shared across passes if the camera is the same as the one used. We may need to review how to relate the shadow map to the camera used to avoid duplicate calculations if reflectors are also used.

I found bayer16s idea interesting where we have a relatively large matrix that we can load as a TSL function.

It's a WIP, revisions and docs would be created in the next few days.

Live example

image

Copy link

github-actions bot commented Feb 15, 2025

📦 Bundle size

Full ESM build, minified and gzipped.

Before After Diff
WebGL 336.51
78.38
336.51
78.38
+0 B
+0 B
WebGPU 519.21
144.16
521.78
144.83
+2.57 kB
+669 B
WebGPU Nodes 518.68
144.05
521.25
144.72
+2.57 kB
+672 B

🌳 Bundle size after tree-shaking

Minimal build including a renderer, camera, empty scene, and dependencies.

Before After Diff
WebGL 465.51
112.23
465.51
112.23
+0 B
+0 B
WebGPU 591.04
160.12
592.15
160.44
+1.12 kB
+325 B
WebGPU Nodes 546.35
149.59
547.28
149.88
+939 B
+295 B

@sunag
Copy link
Collaborator Author

sunag commented Feb 17, 2025

I'm still improving!

Live example

image

@sunag sunag changed the title WebGPURenderer: Volumetric lighting - WIP WebGPURenderer: Volumetric lighting Feb 17, 2025
@sunag sunag added this to the r174 milestone Feb 17, 2025
@sunag sunag marked this pull request as ready for review February 17, 2025 07:57
@sunag sunag marked this pull request as draft February 17, 2025 08:05
@Mugen87
Copy link
Collaborator

Mugen87 commented Feb 17, 2025

The new demos really look stunning! This is awesome stuff 🙌 .

@sunag sunag marked this pull request as ready for review February 19, 2025 01:42
@sunag sunag merged commit 4bc99d4 into mrdoob:dev Feb 19, 2025
12 checks passed
@sunag
Copy link
Collaborator Author

sunag commented Feb 19, 2025

Thank you @Mugen87 ❤️

Shadow calculations are now shared across passes if the camera is the same as the one used. We may need to review how to relate the shadow map to the camera used to avoid duplicate calculations if reflectors are also used.

Maybe this will cause regression, and then we could solve it with a parameter in the renderer, we could even share the objects that have passed through the frustrum using this new parameter 🤔

@wyliefoxxx
Copy link

You're a legend - That looks beautiful


let bayer16Texture = null;

export const bayer16 = Fn( ( [ uv ] ) => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently writing the docs for this module...

What is this TSL function about? I've tried to find some references about "Bayer16" but without success.

Is this an alternative noise texture? I know the term "Bayer" only from Bayer Filters in context of image sensors but I don't understand how it relates to this code.

Copy link
Collaborator Author

@sunag sunag Mar 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bayer Matrix is ​​a pattern, it is used for dithering effects as well, but in this case it was used as an alternative to blue-noise. I use bayer16 which is a 16x16 texture with the bayer pattern, when used in Ray Marching specifically in VolumeNodeMaterial.offsetNode, it reduces banding problem, thus being able to use fewer steps without affecting the visuals as much.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants