Fix bug with alpha to coverage by enabling depth discard when using alpha to coverage #84211
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes: #82637
The issue here is that the area of coverage when rendering to the depth prepass was greater than the area of coverage when rendering the object. Leading to unshaded pixels around the edges.
By way of background, what alpha to coverage does is slightly shrink the area of coverage, and in the distance between the regular coverage of alpha hash, and the new area of coverage, it creates a little gradient which uses alpha to coverage to reduce coverage samples and create a smooth transition (as smooth as MSAA can provide anyway).
We do two types of discarding. One when using alpha scissor or alpha hash (alpha scissor is specified by the user, and alpha hash is computed dynamically). And another when using depth_prepass_alpha. In theory, we should never use both. The changes in #79865 made that assumption which is what brings us here. Alpha to coverage needs the depth prepass to use a much smaller coverage value or else it ends up with one bigger than the alpha scissor coverage and that leads us to the current black artifacts.
This PR allows the depth pass to do its discard, even when using alpha hash materials as long as depth_prepass_alpha or alpha to coverage are being used.
Future work
This PR is enough to solve the regression and restore the 4.1.x behaviour. However, the fact that we have to do this is ridiculous. We really need to do a careful re-evaluation of how alpha to coverage is implemented and fix issues like this. For 1, we should be able to get an exact coverage based on the information we have. This approach leaves way too much of the object out of the depth-prepass.
We should go ahead with this PR for 4.2. But for future releases we need to strongly consider making larger changes to improve the feature instead of just fixing the regression.
Dev1
Beta3
This PR