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

Fix use of discard in shaders #79865

Merged
merged 1 commit into from
Jul 25, 2023
Merged

Conversation

clayjohn
Copy link
Member

@clayjohn clayjohn commented Jul 24, 2023

discard was being included in all shaders set to depth pass opaque, which is the majority of shaders. Instead it should only be used with alpha prepass materials as it disables some GPU optimizations.

This PR also cleans up the shader defines a bit to ensure that the OPAQUE_PREPASS discard is only included when in the depth pass, and when not using an alpha hash.

Addresses the first concern in godotengine/godot-proposals#7366

Testing with the Bistro reference scene I get anywhere from a 2% to a 5% decrease in frame times (when GI and shadows are disabled, meaning the majority of the cost is depth pass and opaque pass).

Production edit: Fixes #77600

discard was being included in all shaders set to depth pass opaque, which is the majority of shaders

Instead it should only be used with alpha prepass materials
@reduz
Copy link
Member

reduz commented Jul 24, 2023

Not sure if I understand the change on the shader, but remember it also needs to run on the depth passes.

@clayjohn
Copy link
Member Author

Not sure if I understand the change on the shader, but remember it also needs to run on the depth passes.

Thanks. This logic ensures that it only runs when in the depth pass and we are using a depth_draw_alpha_prepass material. Regular transparent, transparent hash, and opaque objects never need this

@BastiaanOlij
Copy link
Contributor

BastiaanOlij commented Jul 24, 2023

Indeed, this is especially important when rendering opaque objects, just including the discard check if if totally defunct means we get the overhead of the fragment shader running.

Should fix: #77600

@YuriSizov YuriSizov merged commit 3f2e901 into godotengine:master Jul 25, 2023
13 checks passed
@YuriSizov
Copy link
Contributor

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.

Overhead in fragment discard for opaque_prepass
4 participants