-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Fix lightmaps break when deferred rendering is enabled #14599
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
Fix lightmaps break when deferred rendering is enabled #14599
Conversation
|
Btw, maybe we should open another issue for the emissive issue? |
|
Related: #13871 |
|
The output of the deferred pass is already too large. We can't afford to include an additional attachment. I think the lightmap data should be stored in the emissive channel as it is essentially emissive. |
Good idea, the emissive object seems not need a lightmap, let me do some research and change the code. |
|
If we use the deferred.y to store emissive or lightmap, we need to add an extra bit to distinguish between them. Therefore we can no longer use Note that the Previouslet deferred = vec4(
deferred_types::pack_unorm4x8_(vec4(base_color_srgb, in.material.perceptual_roughness)),
rgb9e5::vec3_to_rgb9e5_(emissive),
props,
deferred_types::pack_24bit_normal_and_flags(octahedral_normal, flags),
);Newlet deferred = vec4(
deferred_types::pack_unorm4x8_(vec4(base_color_srgb, in.material.perceptual_roughness)),
deferred_types::pack_unorm4x8_(vec4(emissive_or_lightmap, has_lightmap)),
props,
deferred_types::pack_24bit_normal_and_flags(octahedral_normal, flags),
); |
|
Both the emissive and the light map need the extra precision and range from rgb9e5. My recommendation is actually to sum the emissive and light map into the emissive channel as light maps are essentially emissive. You'd want to pre-multiply it by the diffuse color as seen here:
|
48340e5 to
2fedba4
Compare
|
Hi @DGriffin91 , I have used the emissive channel to transmit the lightmap data. Could you please review the code? Thank you. |
Co-authored-by: JMS55 <47158642+JMS55@users.noreply.github.com>
055b9bc to
86d00ed
Compare
|
Hi @JMS55 , I have synchronized my code with upstream and made necessary adaptations for the changes in the emissive's alpha channel. Now the lightmap works perfectly without the emissive issues we discussed earlier. |
|
Hi @DGriffin91 , could you please help review these changes? Thank you. |
IceSentry
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code looks fine, but can you answer me and @JMS55 about the LIGHTMAP shader_def that is still in the code instead of quietly resolving? I don't get why it's there.
|
Hi @IceSentry and @JMS55 , we need to keep the // Invoked from Prepass Pipeline
fn pbr_input_from_standard_material(
in: VertexOutput,
is_front: bool,
) -> pbr_types::PbrInput {
// ...
#ifdef LIGHTMAP
pbr_input.lightmap_light = lightmap(
in.uv_b,
pbr_bindings::material.lightmap_exposure,
in.instance_index);
#endif
// ...
} |
A previous PR, bevyengine#14599, attempted to enable lightmaps in deferred mode, but it still used the `OpaqueNoLightmap3dBinKey`, which meant that it would be broken if multiple lightmaps were used. This commit fixes that issue, and allows bindless lightmaps to work with deferred rendering as well.
A previous PR, #14599, attempted to enable lightmaps in deferred mode, but it still used the `OpaqueNoLightmap3dBinKey`, which meant that it would be broken if multiple lightmaps were used. This commit fixes that issue, and allows bindless lightmaps to work with deferred rendering as well.
A previous PR, bevyengine#14599, attempted to enable lightmaps in deferred mode, but it still used the `OpaqueNoLightmap3dBinKey`, which meant that it would be broken if multiple lightmaps were used. This commit fixes that issue, and allows bindless lightmaps to work with deferred rendering as well.
A previous PR, bevyengine#14599, attempted to enable lightmaps in deferred mode, but it still used the `OpaqueNoLightmap3dBinKey`, which meant that it would be broken if multiple lightmaps were used. This commit fixes that issue, and allows bindless lightmaps to work with deferred rendering as well.

Objective
Solution
Store lightmap sample result into G-Buffer and pass them into theDeferred Lighting Pipeline, therefore we can get the correct indirect lighting via theapply_pbr_lightingfunction.The original G-Buffer lacks storage for lightmap data, therefore a new buffer is added. We can only use Rgba16Uint here due to the 32-byte limit on the render targets.Testing
lightmaps(adjust the code based on the issue and check the rendering result)transmission(it contains a prepass)ssr(it also uses the G-Bufffer)meshlet(forward and deferred)pbrShowcase
By updating the
lightmapsexample to use deferred rendering, this pull request enables correct rendering result of the Cornell Box.Emissive Issue
The emissive light object appears incorrectly rendered because the alpha channel of emission is set to 1 in deferred rendering and 0 in forward rendering, leading to different emissive light result. Could this be a bug?