summaryrefslogtreecommitdiffstats
path: root/gfx/layers/d3d11/mlgshaders/blend-ps-generated.hlslh.tpl
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--gfx/layers/d3d11/mlgshaders/blend-ps-generated.hlslh.tpl36
1 files changed, 36 insertions, 0 deletions
diff --git a/gfx/layers/d3d11/mlgshaders/blend-ps-generated.hlslh.tpl b/gfx/layers/d3d11/mlgshaders/blend-ps-generated.hlslh.tpl
new file mode 100644
index 0000000000..a24577a09a
--- /dev/null
+++ b/gfx/layers/d3d11/mlgshaders/blend-ps-generated.hlslh.tpl
@@ -0,0 +1,36 @@
+float4 Blend{BLEND_FUNC}PS(const VS_BLEND_OUTPUT aInput) : SV_Target
+{
+ if (!RectContainsPoint(aInput.vClipRect, aInput.vPosition.xy)) {
+ discard;
+ }
+
+ float4 backdrop = tBackdrop.Sample(sSampler, aInput.vBackdropCoords);
+ float4 source = simpleTex.Sample(sSampler, aInput.vTexCoords);
+
+ // Apply masks to the source texture, not the result.
+ source *= ReadMask(aInput.vMaskCoords);
+
+ // Shortcut when the backdrop or source alpha is 0, otherwise we may leak
+ // infinity into the blend function and return incorrect results.
+ if (backdrop.a == 0.0) {
+ return source;
+ }
+ if (source.a == 0.0) {
+ return float4(0, 0, 0, 0);
+ }
+
+ // The spec assumes there is no premultiplied alpha. The backdrop and
+ // source are both render targets and always premultiplied, so we undo
+ // that here.
+ backdrop.rgb /= backdrop.a;
+ source.rgb /= source.a;
+
+ float4 result;
+ result.rgb = Blend{BLEND_FUNC}(backdrop.rgb, source.rgb);
+ result.a = source.a;
+
+ // Factor backdrop alpha, then premultiply for the final OP_OVER.
+ result.rgb = (1.0 - backdrop.a) * source.rgb + backdrop.a * result.rgb;
+ result.rgb *= result.a;
+ return result;
+}