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

Precompute projection matrices when rendering 2D shadows #98307

Merged
merged 1 commit into from
Nov 10, 2024

Conversation

clayjohn
Copy link
Member

Small optimization I found while profiling CPU performance. light_update_shadow() was calculating the same matrices every time it was called even though they never change.

I also pulled the calculation of the projection matrix out of the loop (although I am 99% certain this was optimized out of the loop anyway in release builds).

Profiled when running the Isometric demo

Before: light_update_shadow() takes 17.1% of the CPU frame time
Screenshot from 2024-10-16 18-09-40

After: light_update_shadow() takes 14.7% of the CPU frame time. Notice that the from_euler chunk is gone completely
Screenshot from 2024-10-16 18-09-46

This demo is GPU-bound so this doesn't change the framerate.

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. Basis::from_euler() is no longer present in profiles when running the 2D isometric demo and standing still for 300 frames.

@Repiteo Repiteo merged commit 2b02143 into godotengine:master Nov 10, 2024
20 checks passed
@Repiteo
Copy link
Contributor

Repiteo commented Nov 10, 2024

Thanks!

@clayjohn clayjohn deleted the Light2D-shadow-projection branch November 12, 2024 22:21
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.

3 participants