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 an unintended type conversion in the terrain shader #371

Merged
merged 2 commits into from
Feb 13, 2024

Conversation

rdw-software
Copy link
Member

@rdw-software rdw-software commented Feb 13, 2024

This error was concealed by a recent change to wgpu, where it would automatically convert unsigned integers to floats when it deems it "safe" to do so. Previously, it would've given a validation error here because the hardcoded numbers aren't compiled to floats unless explicitly marked as such.

Apparently, this hidden conversion broke the discard logic, leading to black surfaces being discarded in at least one case (c_tower1). This is because the division doesn't have enough precision if using integers. Being explicit fixes the problem.

Edit: I also noticed the shader isn't actually discarding the fragment, which seems like a silly oversight.

This error was concealed by a recent change to wgpu, where it would automatically convert unsigned integers to floats when it deems it "safe" to do so. Previously, it would've given a validation error here because the hardcoded numbers aren't compiled to floats unless explicitly marked as such.

Apparently, this hidden conversion broke the discard logic, leading to black surfaces being discarded in at least one case (c_tower1). This is because the division doesn't have enough precision if using integers. Being explicit fixes the problem.
Setting the alpha to zero has the same net effect, but it wastes GPU compute time as the rest of the shader program might still be executed - for no good reason, given that the fragment won't be visible anyway.
@rdw-software rdw-software merged commit 357e064 into main Feb 13, 2024
6 checks passed
@rdw-software rdw-software deleted the shader-transparency-fix branch February 22, 2024 15:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant