🔧 Convert window texture alpha from premultiplied to straight

This commit is contained in:
Simon Schneegans
2022-05-11 04:59:58 +02:00
parent 478ba77288
commit d224d14db1
11 changed files with 83 additions and 23 deletions
+7 -2
View File
@@ -176,7 +176,7 @@ if (utils.isInShellProcess()) {
freeShaders.push(this);
}
// This is called by the constructor. This is means it's only called when the effect
// This is called by the constructor. This means, it's only called when the effect
// is used for the first time.
vfunc_build_pipeline() {
const declarations = `
@@ -218,8 +218,13 @@ if (utils.isInShellProcess()) {
float c = cos(angle);
coords = vec2(dot(coords, vec2(c, -s)), dot(coords, vec2(s, c)));
// Fade out the window texture.
// Shell.GLSLEffect uses straight alpha. So we have to convert from premultiplied.
cogl_color_out = texture2D(uTexture, coords + center);
if (cogl_color_out.a > 0) {
cogl_color_out.rgb /= cogl_color_out.a;
}
// Fade out the window texture.
cogl_color_out.a *= 1.0 - progress;
`;
+6 -1
View File
@@ -213,7 +213,7 @@ if (utils.isInShellProcess()) {
freeShaders.push(this);
}
// This is called by the constructor. This is means it's only called when the effect
// This is called by the constructor. This means, it's only called when the effect
// is used for the first time.
vfunc_build_pipeline() {
const declarations = `
@@ -277,6 +277,11 @@ if (utils.isInShellProcess()) {
cogl_color_out = texture2D(uTexture, coords);
}
}
// Shell.GLSLEffect uses straight alpha. So we have to convert from premultiplied.
if (cogl_color_out.a > 0) {
cogl_color_out.rgb /= cogl_color_out.a;
}
`;
this.add_glsl_snippet(Shell.SnippetHook.FRAGMENT, declarations, code, true);
+6 -1
View File
@@ -163,7 +163,7 @@ if (utils.isInShellProcess()) {
freeShaders.push(this);
}
// This is called by the constructor. This is means it's only called when the effect
// This is called by the constructor. This means, it's only called when the effect
// is used for the first time.
vfunc_build_pipeline() {
const declarations = `
@@ -220,6 +220,11 @@ if (utils.isInShellProcess()) {
vec2 masks = getMasks();
vec4 windowColor = texture2D(uTexture, cogl_tex_coord_in[0].st);
// Shell.GLSLEffect uses straight alpha. So we have to convert from premultiplied.
if (windowColor.a > 0) {
windowColor.rgb /= windowColor.a;
}
// Dissolve window to effect color / transparency.
cogl_color_out.rgb = mix(uColor, windowColor.rgb, 0.2 * masks.y + 0.8);
cogl_color_out.a = windowColor.a * masks.y;
+6 -1
View File
@@ -163,7 +163,7 @@ if (utils.isInShellProcess()) {
freeShaders.push(this);
}
// This is called by the constructor. This is means it's only called when the effect
// This is called by the constructor. This means, it's only called when the effect
// is used for the first time.
vfunc_build_pipeline() {
const declarations = `
@@ -237,6 +237,11 @@ if (utils.isInShellProcess()) {
vec4 masks = getMasks();
vec4 windowColor = texture2D(uTexture, cogl_tex_coord_in[0].st);
// Shell.GLSLEffect uses straight alpha. So we have to convert from premultiplied.
if (windowColor.a > 0) {
windowColor.rgb /= windowColor.a;
}
// Dissolve window to effect color / transparency.
cogl_color_out.rgb = mix(uColor, windowColor.rgb, 0.5 * masks.w + 0.5);
cogl_color_out.a = windowColor.a * masks.w;
+9 -2
View File
@@ -290,7 +290,7 @@ if (utils.isInShellProcess()) {
freeShaders.push(this);
}
// This is called by the constructor. This is means it's only called when the effect
// This is called by the constructor. This means, it's only called when the effect
// is used for the first time.
vfunc_build_pipeline() {
@@ -395,8 +395,15 @@ if (utils.isInShellProcess()) {
// Map noise value to color.
vec4 fire = getFireColor(noise);
// Get the window texture and fade it according to the effect mask.
// Get the window texture.
cogl_color_out = texture2D(uTexture, cogl_tex_coord_in[0].st);
// Shell.GLSLEffect uses straight alpha. So we have to convert from premultiplied.
if (cogl_color_out.a > 0) {
cogl_color_out.rgb /= cogl_color_out.a;
}
// Fade the window according to the effect mask.
cogl_color_out.a *= effectMask.x;
// Add the fire to the window.
+7 -2
View File
@@ -122,7 +122,7 @@ var Hexagon = class Hexagon {
// This is called from extension.js if the extension is disabled. This should free all
// static resources.
static cleanUp() {
shaderInstance = null;
freeShaders = [];
}
}
@@ -182,7 +182,7 @@ if (utils.isInShellProcess()) {
freeShaders.push(this);
}
// This is called by the constructor. This is means it's only called when the effect
// This is called by the constructor. This means, it's only called when the effect
// is used for the first time.
vfunc_build_pipeline() {
@@ -273,6 +273,11 @@ if (utils.isInShellProcess()) {
vec2 lookupOffset = tileProgress * hex.xy / texScale / (1.0 - tileProgress);
cogl_color_out = texture2D(uTexture, cogl_tex_coord_in[0].st + lookupOffset);
// Shell.GLSLEffect uses straight alpha. So we have to convert from premultiplied.
if (cogl_color_out.a > 0) {
cogl_color_out.rgb /= cogl_color_out.a;
}
vec4 glow = uGlowColor;
vec4 line = uLineColor;
+9 -2
View File
@@ -194,7 +194,7 @@ if (utils.isInShellProcess()) {
freeShaders.push(this);
}
// This is called by the constructor. This is means it's only called when the effect
// This is called by the constructor. This means, it's only called when the effect
// is used for the first time. The technique for this effect was inspired by
// https://www.shadertoy.com/view/ldccW4, however the implementation is quite
// different as the letters drop only once and there is no need for a noise texture.
@@ -274,8 +274,15 @@ if (utils.isInShellProcess()) {
vec2 rainMask = getRain(coords);
float textMask = getText(coords);
// Get the window texture and fade it according to the effect mask.
// Get the window texture.
cogl_color_out = texture2D(uTexture, coords);
// Shell.GLSLEffect uses straight alpha. So we have to convert from premultiplied.
if (cogl_color_out.a > 0) {
cogl_color_out.rgb /= cogl_color_out.a;
}
// Fade the window according to the effect mask.
cogl_color_out.a *= rainMask.y;
// This is used to fade out the remaining trails in the end.
+14 -9
View File
@@ -189,7 +189,7 @@ if (utils.isInShellProcess()) {
freeShaders.push(this);
}
// This is called by the constructor. This is means it's only called when the effect
// This is called by the constructor. This means, it's only called when the effect
// is used for the first time.
vfunc_build_pipeline() {
const declarations = `
@@ -265,17 +265,22 @@ if (utils.isInShellProcess()) {
if (dustGroup == i) {
// Fade the window color to uDustColor.
// Get the window color.
vec4 windowColor = texture2D(uTexture, coords + 0.5);
// Shell.GLSLEffect uses straight alpha. So we have to convert from premultiplied.
if (windowColor.a > 0) {
windowColor.rgb /= windowColor.a;
}
// Fade the window color to uDustColor.
vec3 dustColor = mix(windowColor.rgb, uDustColor.rgb, uDustColor.a);
windowColor.rgb = mix(windowColor.rgb, dustColor*windowColor.a, progress);
windowColor.rgb = mix(windowColor.rgb, dustColor, progress);
// Dissolve the dust particles.
float dissolve = (dustMap.x - progress) > 0 ? 1 : 0;
windowColor *= dissolve;
// Blend the layers.
cogl_color_out = mix(cogl_color_out, windowColor, windowColor.a);
// Dissolve and blend the layers.
if (dustMap.x - progress > 0) {
cogl_color_out = windowColor;
}
}
}
`;
+6 -1
View File
@@ -189,7 +189,7 @@ if (utils.isInShellProcess()) {
freeShaders.push(this);
}
// This is called by the constructor. This is means it's only called when the effect
// This is called by the constructor. This means, it's only called when the effect
// is used for the first time.
vfunc_build_pipeline() {
const declarations = `
@@ -273,6 +273,11 @@ if (utils.isInShellProcess()) {
vec2 offset = vec2(dFdx(scratchMap), dFdy(scratchMap)) * progress * 0.5;
cogl_color_out = texture2D(uTexture, coords + offset);
// Shell.GLSLEffect uses straight alpha. So we have to convert from premultiplied.
if (cogl_color_out.a > 0) {
cogl_color_out.rgb /= cogl_color_out.a;
}
// Add colorful flashes.
float flashIntensity = 1.0 / FLASH_INTENSITY * (scratchMap - progress) + 1;
if (flashIntensity < 0 || flashIntensity >= 1) {
+7 -1
View File
@@ -162,7 +162,7 @@ if (utils.isInShellProcess()) {
freeShaders.push(this);
}
// This is called by the constructor. This is means it's only called when the effect
// This is called by the constructor. This means, it's only called when the effect
// is used for the first time.
vfunc_build_pipeline() {
const declarations = `
@@ -207,6 +207,12 @@ if (utils.isInShellProcess()) {
float mask = tbMask * lrMask * ffMask;
cogl_color_out = texture2D(uTexture, cogl_tex_coord_in[0].st);
// Shell.GLSLEffect uses straight alpha. So we have to convert from premultiplied.
if (cogl_color_out.a > 0) {
cogl_color_out.rgb /= cogl_color_out.a;
}
cogl_color_out.rgb = mix(cogl_color_out.rgb, uColor * cogl_color_out.a, smoothstep(0, 1, progress));
cogl_color_out.a *= mask;
+6 -1
View File
@@ -169,7 +169,7 @@ if (utils.isInShellProcess()) {
freeShaders.push(this);
}
// This is called by the constructor. This is means it's only called when the effect
// This is called by the constructor. This means, it's only called when the effect
// is used for the first time.
vfunc_build_pipeline() {
const declarations = `
@@ -236,6 +236,11 @@ if (utils.isInShellProcess()) {
// Get the color of the window.
cogl_color_out = texture2D(uTexture, cogl_tex_coord_in[0].st);
// Shell.GLSLEffect uses straight alpha. So we have to convert from premultiplied.
if (cogl_color_out.a > 0) {
cogl_color_out.rgb /= cogl_color_out.a;
}
// Compute several layers of moving wisps.
vec2 uv = (cogl_tex_coord_in[0].st-0.5) / mix(1.0, 0.5, progress) + 0.5;
uv /= uScale;