Skip to content

Commit 28934f1

Browse files
gmitrano-unityEvergreen
authored andcommitted
[URP] Fix Accidental Alpha Overwrite in non-A2C Cases
This change fixes a case where some alpha-to-coverage specific logic was overwriting the alpha value used by transparent surfaces that were also using alpha-clipping. The solution for this problem is to inline the alpha overwrite logic into the alpha-to-coverage specific calculations.
1 parent 43ffe36 commit 28934f1

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

Packages/com.unity.render-pipelines.universal/ShaderLibrary/ShaderVariablesFunctions.hlsl

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -184,18 +184,17 @@ bool IsAlphaToMaskAvailable()
184184
// When AlphaToMask is not available: Terminates the current invocation if the alpha value is below the cutoff and returns the input alpha value otherwise
185185
half AlphaClip(half alpha, half cutoff)
186186
{
187-
// If the user has specified zero as the cutoff threshold, the expectation is that the shader will function as if alpha-clipping was disabled.
188-
// Ideally, the user should just turn off the alpha-clipping feature in this case, but in order to make this case work as expected, we force alpha
189-
// to 1.0 here to ensure that alpha-to-coverage never throws away samples when its active. (This would cause opaque objects to appear transparent)
190-
alpha = (cutoff <= 0.0) ? 1.0 : alpha;
191-
192187
// Produce 0.0 if the input value would be clipped by traditional alpha clipping and produce the original input value otherwise.
193188
// WORKAROUND: The alpha parameter in this ternary expression MUST be converted to a float in order to work around a known HLSL compiler bug.
194189
// See Fogbugz 934464 for more information
195190
half clippedAlpha = (alpha >= cutoff) ? float(alpha) : 0.0;
196191

197192
// Calculate a specialized alpha value that should be used when alpha-to-coverage is enabled
198-
half alphaToCoverageAlpha = SharpenAlpha(alpha, cutoff);
193+
194+
// If the user has specified zero as the cutoff threshold, the expectation is that the shader will function as if alpha-clipping was disabled.
195+
// Ideally, the user should just turn off the alpha-clipping feature in this case, but in order to make this case work as expected, we force alpha
196+
// to 1.0 here to ensure that alpha-to-coverage never throws away samples when its active. (This would cause opaque objects to appear transparent)
197+
half alphaToCoverageAlpha = (cutoff <= 0.0) ? 1.0 : SharpenAlpha(alpha, cutoff);
199198

200199
// When alpha-to-coverage is available: Use the specialized value which will be exported from the shader and combined with the MSAA coverage mask.
201200
// When alpha-to-coverage is not available: Use the "clipped" value. A clipped value will always result in thread termination via the clip() logic below.

0 commit comments

Comments
 (0)