-
-
Notifications
You must be signed in to change notification settings - Fork 21.5k
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
Add transparency support for LightmapGI #99538
Add transparency support for LightmapGI #99538
Conversation
e3bfa5c
to
cb7de2e
Compare
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.
Documentation is fine as it was before.
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 in Forward+, there's an issue with static directional shadow rendering:
This occurs even when no transparent materials are visible during the bake:
This doesn't occur in master
:
Testing project: test_pr_99538.zip
That is from using bicubic sampling and shadow antialiasing https://godotengine.org/article/dev-snapshot-godot-4-4-dev-1/#lightmap-bicubic-sampling |
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.
Great work! This is nearly ready. I left a comment on how cull_mode should be exposed, please let me know if it makes sense.
1379aa0
to
33e0f10
Compare
The issue that @Calinou found is tricky. So far I found out that the artifact only appears when the light direction and the surface are orthogonal to eachother. Rotating the directional light slightly removes it. |
Update: if (icell != ivec3(hit_cell)) {
// It's possible for the ray to hit a triangle in a position outside the bounds of the cell
// if it's large enough to cover multiple ones. The hit must be ignored if this is the case.
continue;
} Doing that shouldn't be the solution, so maybe @DarioSamo could give some insight here, as I'm not that familiar with the lightmapper. |
That code seems correct to me, I feel that'd probably indicate the DDA traversal is not reaching the cell it should. Large triangles can cover multiple cells, but the hit must be inside the cell picked by the DDA for it to be valid. It's not an easy area to debug I'm afraid. I wonder if it could be falling on the edge case of a DDA cell? You mentioned it only happens if it's orthogonal, so perhaps it's only an issue because the DDA traversal is strictly following along the edge of one of the cells and never visiting the neighbours. You could try giving the if some tolerance as a hack to see if it's something along those lines. |
33e0f10
to
8afca59
Compare
Update: vec3 position = p_from + dir * distance;
if (any(lessThan(position, cell_min)) ||
any(greaterThan(position, cell_max))) {
// It's possible for the ray to hit a triangle in a position outside the bounds of the cell
// if it's large enough to cover multiple ones. The hit can be ignored if this is the case.
continue;
} with const float CELL_EPSILON = 0.5;
const vec3 cell_min = bake_params.to_cell_offset + vec3(icell) / bake_params.to_cell_size - CELL_EPSILON;
const vec3 cell_max = bake_params.to_cell_offset + vec3(icell + 1) / bake_params.to_cell_size + CELL_EPSILON; However, this broke again when increasing the bounds of the lightmap domain (by placing objects further away). Regardless of the actual cause: This is a pure optimization and not needed for the lightmapper to work properly. And the operations that are skipped aren't that costly, so we might as well remove the branch entirely. So, removing it fixes all weird artifacts and actually improves performance, although we might conceal the underlying issue. I'm not sure how we should proceed at this point. |
Have you tested it with directional and with physically based lights? |
I didn't try directional lights but they seem to work fine: As for physical lights, i never used those before so i just enabled them in the advanced settings. I may have done something wrong since they look more broken than nice but the colors do get taken into account during mixing: For comparison this is how master (i.e. without this PR and the patch i wrote above) currently looks: |
@badsectoracula This is similar to how it was done in the original colored transparency shadow PR: #90132 |
Adding a camera attribute to your LightmapGI node should fix it. It's an "expected behavior". See: #87531 |
Originally this was supposed to be only a salvage of #90109, and I was planning to do the other one after that, but if we can agree on combining the functionality I'd be happy to do that. |
Let's keep this PR short and focused. We can add transparent color shortly after. I would like to get @DarioSamo's input on the DDA traversal fix. If it is indeed just a small optimization, I have no problem removing it for now. |
@Geometror A lot of the performance optimizations I made were using the scene from here: #75440. If you find no regressions with that, then the optimization can go. |
Trying the scene at #75440 seems impossible as the 'Plotting mesh into acceleration structure' step seems to freeze, however this freeze doesn't happen on v4.4dev6 and v4.3. Also found that the console gets flooded with Issues I previously experienced have been fixed. Thanks a lot. 😄 MRP for the error |
4c691c6
to
97604c0
Compare
@spookto Thanks a lot for testing, but just to save you time, sometimes I do a push to sync the progress between my devices (which can be in a broken state). Usually I write a comment whenever meaningful progress was made. Currently, I'm fighting with the issue you described in your last comment. The sun temple scene completely breaks when the cell check discussed above isn't in place (only after #85653 and so far I couldn't figure out why). With cell check/without before #85653 it looks like that (no lights enabled besides sun) |
7c9a2ba
to
a5a4005
Compare
I was finally able to fix all issues:
As expected, baking of the sun temple scene is a bit slower (since the scene contains transparent vegetation), but not too bad. (90s -> 111s, default of max. 8 transparency rays) Sun temple with texel scale set to 2 |
a5a4005
to
4d1c7af
Compare
Is that an existing issue? I might be remembering wrong. |
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'm happy with the code and consider this ready for merging! I trust that the testing from Geometror and others is sufficient
servers/rendering/renderer_rd/shaders/forward_clustered/scene_forward_clustered.glsl
Show resolved
Hide resolved
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 good to me (see the remark I made, which can be addressed in a future PR).
servers/rendering/renderer_rd/shaders/forward_clustered/scene_forward_clustered.glsl
Outdated
Show resolved
Hide resolved
servers/rendering/renderer_rd/shaders/forward_mobile/scene_forward_mobile.glsl
Outdated
Show resolved
Hide resolved
Co-authored-by: Guerro323 <kaltobattle@gmail.com>
2fe1d68
to
a3525bc
Compare
Thanks! |
Salvages #90109 (co-authored by @guerro323)
Fixes #77590
I added the required changes for compatibility and adjusted the algorithm to the antialiasing of direct light samples that was introduced awhile ago.
Although unrelated to this PR (observable in
master
), there seems to be a regression/change of behavior that shadows of lights with size 0 appear much softer, depending on the texel scale. I know, a higher texel scale increases the resolution of the light map, but compared to the screenshots of the original PR it's definitely different. Maybe this new behavior is desired, because hard shadows can look bad on low-res light maps.Note
(Copied from the original PR)
The culling logic was updated in the Lightmapper to correctly support Back and Disabled cull modes.
To preserve the current behavior and to not have any breaking change, the first direct light rays will retain the old behavior where light is blocked even if it should be culled.
This behavior is still needed otherwise there would be holes in the shadows of penetrated meshes (which can be quite common) and would need the material to be updated to Disabled cull mode, which may not be intuitive in most cases.
TL;DR: There should be no breaking changes on existing scenes. This do need some more testing but all my scenes looked correct.