Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bevy_pbr: Make choosing of diffuse indirect lighting explicit. #15093

Merged
merged 1 commit into from
Sep 9, 2024

Conversation

cryscan
Copy link
Contributor

@cryscan cryscan commented Sep 8, 2024

Objective

Make choosing of diffuse indirect lighting explicit, instead of using numerical conditions like all(indirect_light == vec3(0.0f)), as using that may lead to unwanted light leakage.

Solution

Use an explicit found_diffuse_indirect condition to indicate the found indirect lighting source.

Testing

I have tested examples lightmaps, irradiance_volumes and reflection_probes, there are no visual changes. For further testing, consider a "cave" scene with lightmaps and irradiance volumes. In the cave there are some purly dark occluded area, those dark area will sample the irradiance volume, and that is easy to leak light.

@cryscan cryscan changed the title Make choosing of diffuse indirect lighting explicit. bevy_pbr: Make choosing of diffuse indirect lighting explicit. Sep 8, 2024
@IQuick143 IQuick143 added A-Rendering Drawing game state to the screen D-Straightforward Simple bug fixes and API improvements, docs, test and examples S-Needs-Review Needs reviewer attention (from anyone!) to move forward D-Shaders This code uses GPU shader languages labels Sep 8, 2024
Copy link
Member

@alice-i-cecile alice-i-cecile left a comment

Choose a reason for hiding this comment

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

Much clearer, thank you.

@alice-i-cecile alice-i-cecile added the C-Code-Quality A section of code that is hard to understand or change label Sep 8, 2024
@alice-i-cecile alice-i-cecile added S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it and removed S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Sep 8, 2024
@alice-i-cecile alice-i-cecile added this pull request to the merge queue Sep 9, 2024
Merged via the queue into bevyengine:main with commit 9b006fd Sep 9, 2024
26 checks passed
@mgi388
Copy link
Contributor

mgi388 commented Sep 10, 2024

@cryscan re:

as using that may lead to unwanted light leakage

do you mind explaining to me what this means and how it manifests as a bug in a game eg with an example if you have one? I’m using light maps myself, albeit not entirely successfully, and I’m trying to understand exactly what you mean by light leakage and also why the old code has the problem.

@cryscan
Copy link
Contributor Author

cryscan commented Sep 10, 2024

@cryscan re:

as using that may lead to unwanted light leakage

do you mind explaining to me what this means and how it manifests as a bug in a game eg with an example if you have one? I’m using light maps myself, albeit not entirely successfully, and I’m trying to understand exactly what you mean by light leakage and also why the old code has the problem.

Irradiance volumes (or light probes) are prone to light leakage. One common case is an indoor area with thin walls: light from outside of the wall is very likely to leak into the inside area which are supposed to be dark. On the other hand, lightmaps are less likely to leak light. In terms of this particular PR, the original code checks whether to use lightmaps or fallback to irradiance volumes by checking whether the data read is zero. This is unrelieable because for some highly occluded pixels where the lightmap is intended to be completely dark, the shader picks irradiance volumes, and that will very likely to make the pixel accidentally lit up, and you will see artefacts in very dark areas.

@cryscan cryscan deleted the indirect-priority branch September 10, 2024 18:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Rendering Drawing game state to the screen C-Code-Quality A section of code that is hard to understand or change D-Shaders This code uses GPU shader languages D-Straightforward Simple bug fixes and API improvements, docs, test and examples S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants