-
-
Notifications
You must be signed in to change notification settings - Fork 22k
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
LightmapGI: Pack L1 SH coefficients for directional lightmaps #96114
Conversation
f056a09
to
7fc357d
Compare
I've added a basic versioning system with the use of a new internal property whose purpose is to notify the LightmapGI node if the directional lightmaps are packed or not. I'm not sure if this is a good solution though. |
scene/3d/lightmap_gi.cpp
Outdated
@@ -1352,6 +1365,7 @@ void LightmapGI::_notification(int p_what) { | |||
switch (p_what) { | |||
case NOTIFICATION_POST_ENTER_TREE: { | |||
if (light_data.is_valid()) { | |||
ERR_FAIL_COND_MSG(light_data->is_using_spherical_harmonics() && !light_data->is_using_packed_directional(), "The directional lightmap textures are stored in a format that isn't supported anymore. Please rebake to fix the issue."); |
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.
Since the packing is implemented as a separate pass, could we not just run that pass when we encounter an old lightmap and upgrade it automatically for the user?
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.
I thought about it, but older lightmaps wouldn't work the same way since they use different coefficients
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.
Oh right, I guess #95888 technically breaks compatibility already for existing lightmaps so this PR fixes the compatibility breakage from that.
Here is an MIT licenced implementation of the Geomerics technique. Its a but more expensive to unpack, but it looks really good.
We can probably switch to BC1 once we merge #95915 |
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.
Tested locally (rebased on top of master
b6223c0), it works as expected in all rendering methods. This allows using VRAM compressed directional lightmaps with any rendering method, whereas you'd get error spam previously (and a black screen).
Testing project: test_lightmap_directional_compress.zip
Preview
VRAM Uncompressed
VRAM Compressed (this PR)
PS: I noticed directional lightmaps generally represent light direction in a more faint manner compared to real-time lights, even when there is only a single clear light direction at a given texel, no indirect light involved and when lightmap bounces are set to 0. Is there a way we could get the directional lightmapping appearance to make normal mapped surfaces closer to how they'd look like with real-time lighting? This isn't an issue specific to this PR, but I thought it'd be worth pointing out.
I have been thinking about this a lot. I think it has to do with our discussion above about the coefficients. Right now I think something is off with the spherical harmonic baking process that results in the average light being roughly correct, but the directional light being too weak. |
7fc357d
to
ba7d5d3
Compare
ba7d5d3
to
a89f4fa
Compare
Thanks! |
Depends on #96113
Packs the L1 coefficients of SH lightmaps into a 0.0-1.0 range, which will allow compressing directional lightmaps as BC6U. This is an approach based on https://media.contentapi.ea.com/content/dam/eacom/frostbite/files/gdc2018-precomputedgiobalilluminationinfrostbite.pdf.
The packing is currently performed as an extra step after the image has already been denoised as a way to avoid precision errors.
TODO:
Future work:
Comparison:
Testing project:
sh-lightmaps.zip