Effect: Fix overlay alpha handling.
Before, a translucent overlay over an opaque video would result in a translucent output. This is not consistent with physical properties of light (if putting a translucent object in front of an opaque object, you can't see behind the opaque object). Using the mixing properties from DefaultVideoCompositor. PiperOrigin-RevId: 586636275
@ -181,14 +181,14 @@ import com.google.common.collect.ImmutableList;
|
||||
.append(" }\n")
|
||||
.append("}\n")
|
||||
.append("\n")
|
||||
.append("float getMixAlpha(float videoAlpha, float overlayAlpha) {\n")
|
||||
.append(" if (videoAlpha == 0.0) {\n")
|
||||
.append(" return 1.0;\n")
|
||||
.append(" } else {\n")
|
||||
.append(" return clamp(overlayAlpha/videoAlpha, 0.0, 1.0);\n")
|
||||
.append(" }\n")
|
||||
.append("vec4 getMixColor(vec4 videoColor, vec4 overlayColor) {\n")
|
||||
.append(" vec4 outputColor;\n")
|
||||
.append(" outputColor.rgb = overlayColor.rgb * overlayColor.a\n")
|
||||
.append(" + videoColor.rgb * (1.0 - overlayColor.a);\n")
|
||||
.append(" outputColor.a = overlayColor.a + videoColor.a * (1.0 - overlayColor.a);\n")
|
||||
.append(" return outputColor;\n")
|
||||
.append("}\n")
|
||||
.append("")
|
||||
.append("\n")
|
||||
.append("float srgbEotfSingleChannel(float srgb) {\n")
|
||||
.append(" return srgb <= 0.04045 ? srgb / 12.92 : pow((srgb + 0.055) / 1.055, 2.4);\n")
|
||||
.append("}\n")
|
||||
@ -232,12 +232,9 @@ import com.google.common.collect.ImmutableList;
|
||||
formatInvariant(
|
||||
" applyEotf(electricalOverlayColor%d.rgb), electricalOverlayColor%d.a);\n",
|
||||
texUnitIndex, texUnitIndex))
|
||||
.append(" fragColor = mix(\n")
|
||||
.append(
|
||||
formatInvariant(
|
||||
" fragColor, opticalOverlayColor%d, getMixAlpha(videoColor.a,"
|
||||
+ " opticalOverlayColor%d.a));\n",
|
||||
texUnitIndex, texUnitIndex));
|
||||
" fragColor = getMixColor(fragColor, opticalOverlayColor%d);\n", texUnitIndex));
|
||||
}
|
||||
|
||||
shader.append(" gl_FragColor = fragColor;\n").append("}\n");
|
||||
|
Before Width: | Height: | Size: 8.4 KiB After Width: | Height: | Size: 8.0 KiB |
Before Width: | Height: | Size: 7.6 KiB After Width: | Height: | Size: 7.3 KiB |
Before Width: | Height: | Size: 7.8 KiB After Width: | Height: | Size: 7.8 KiB |
Before Width: | Height: | Size: 14 KiB After Width: | Height: | Size: 14 KiB |
Before Width: | Height: | Size: 14 KiB After Width: | Height: | Size: 14 KiB |
Before Width: | Height: | Size: 14 KiB After Width: | Height: | Size: 14 KiB |
Before Width: | Height: | Size: 8.1 KiB After Width: | Height: | Size: 7.6 KiB |
Before Width: | Height: | Size: 7.6 KiB After Width: | Height: | Size: 7.3 KiB |
Before Width: | Height: | Size: 14 KiB After Width: | Height: | Size: 13 KiB |
Before Width: | Height: | Size: 13 KiB After Width: | Height: | Size: 13 KiB |
Before Width: | Height: | Size: 14 KiB After Width: | Height: | Size: 13 KiB |
Before Width: | Height: | Size: 14 KiB After Width: | Height: | Size: 14 KiB |
Before Width: | Height: | Size: 14 KiB After Width: | Height: | Size: 14 KiB |
Before Width: | Height: | Size: 14 KiB After Width: | Height: | Size: 14 KiB |
Before Width: | Height: | Size: 14 KiB After Width: | Height: | Size: 14 KiB |
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 14 KiB |
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 14 KiB |
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 14 KiB |
Before Width: | Height: | Size: 14 KiB After Width: | Height: | Size: 14 KiB |
Before Width: | Height: | Size: 14 KiB After Width: | Height: | Size: 14 KiB |
Before Width: | Height: | Size: 10 KiB After Width: | Height: | Size: 9.9 KiB |
Before Width: | Height: | Size: 7.5 KiB After Width: | Height: | Size: 7.5 KiB |
Before Width: | Height: | Size: 6.9 KiB After Width: | Height: | Size: 6.9 KiB |
Before Width: | Height: | Size: 7.5 KiB After Width: | Height: | Size: 7.5 KiB |
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 12 KiB |
Before Width: | Height: | Size: 27 KiB After Width: | Height: | Size: 24 KiB |
Before Width: | Height: | Size: 519 KiB After Width: | Height: | Size: 519 KiB |
Before Width: | Height: | Size: 516 KiB After Width: | Height: | Size: 515 KiB |
Before Width: | Height: | Size: 500 KiB After Width: | Height: | Size: 499 KiB |
Before Width: | Height: | Size: 509 KiB After Width: | Height: | Size: 509 KiB |
Before Width: | Height: | Size: 504 KiB After Width: | Height: | Size: 504 KiB |
Before Width: | Height: | Size: 472 KiB After Width: | Height: | Size: 473 KiB |
Before Width: | Height: | Size: 529 KiB After Width: | Height: | Size: 525 KiB |
Before Width: | Height: | Size: 542 KiB After Width: | Height: | Size: 535 KiB |
Before Width: | Height: | Size: 395 KiB After Width: | Height: | Size: 399 KiB |
Before Width: | Height: | Size: 526 KiB After Width: | Height: | Size: 523 KiB |
Before Width: | Height: | Size: 520 KiB After Width: | Height: | Size: 514 KiB |
Before Width: | Height: | Size: 535 KiB After Width: | Height: | Size: 532 KiB |