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

Optimize lightmapper using triangle clusters on the acceleration structure. #83284

Merged
merged 1 commit into from
Oct 20, 2023

Conversation

DarioSamo
Copy link
Contributor

Originally suggested by @reduz in this post.

Add an additional layer of indirection to the grid used by the lightmapper to store fixed-size triangle clusters. Greatly speeds up baking times on scenes with high triangle density, as the clusters will help to avoid unnecessary checks when the triangle density is high on the scene.

Unreal Sun Temple (from #75440).

Master: Done baking lightmaps in 00:04:39.
PR: Done baking lightmaps in 00:01:10.

Sponza

Master: Done baking lightmaps in 00:00:56.
PR: Done baking lightmaps in 00:00:37.

So far I haven't been able to see if this introduces any errors as the results look identical to me (which is good news as the results would be invalidated otherwise). We should double check as much as possible that nothing breaks before we're sure we want this merged.

Feel free to test it out if you get similar reductions in baking speed and ensuring nothing breaks. Don't expect much gains in scenes with low geometry density, as the optimizations are oriented entirely around reducing ray-triangle intersections in scenes where there was a significant amount of triangles per cell.

Copy link
Member

@Calinou Calinou left a comment

Choose a reason for hiding this comment

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

Tested locally, it works as expected.

With quality set to Ultra and denoiser disabled, these are the bake times on the scene below on an i9-13900K + RTX 4090 on Linux:

master This PR
54 seconds 26 seconds

Visuals are identical.

image

Testing project: test_lightmap_preview_bake_4.x.zip

The scene has 52k vertices and 86k triangles according to Blender, which is relatively low by modern standards.

…cture.

Add an additional layer of indirection to the grid used by the lightmapper to store fixed-size triangle clusters. Greatly speeds up baking times on scenes with high triangle density, as the clusters will help to avoid unnecessary checks when the triangle density is high on the scene.
@DarioSamo
Copy link
Contributor Author

DarioSamo commented Oct 13, 2023

Rebased to fix conflicts with indirect bounces PR that just got merged, taking it out of drafts for further testing.

@DarioSamo DarioSamo marked this pull request as ready for review October 13, 2023 21:01
@DarioSamo DarioSamo requested a review from a team as a code owner October 13, 2023 21:01
@Koalamana9

This comment was marked as off-topic.

@Calinou

This comment was marked as off-topic.

@DarioSamo
Copy link
Contributor Author

Re-ran the test (with higher quality settings) with the rebased version, the performance differential remains pretty much the same in the Unreal Sun Temple.

Master: Done baking lightmaps in 00:15:02.
PR: Done baking lightmaps in 00:03:28.

@Koalamana9

This comment was marked as off-topic.

@DarioSamo

This comment was marked as off-topic.

@clayjohn clayjohn modified the milestones: 4.x, 4.2 Oct 19, 2023
Copy link
Member

@clayjohn clayjohn left a comment

Choose a reason for hiding this comment

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

Looks great to me!

Let's go ahead and merge this for 4.2 as it is a small change that has big benefits.

In light of the many changes to lightmapping this release, let's not try to cherrypick it though

@akien-mga akien-mga merged commit db493ed into godotengine:master Oct 20, 2023
15 checks passed
@akien-mga
Copy link
Member

Thanks!

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

Successfully merging this pull request may close these issues.

5 participants