From 0bd0fb27b9a1d6d989a437e6d04b0a36d2c1bdd9 Mon Sep 17 00:00:00 2001 From: Simon Schneegans Date: Fri, 10 Jun 2022 07:20:21 +0200 Subject: [PATCH] :wrench: Use new global methods for shader I/O --- resources/shaders/apparition.frag | 8 ++------ resources/shaders/broken-glass.frag | 9 +++------ resources/shaders/common.glsl | 2 +- resources/shaders/energize-a.frag | 15 ++++++--------- resources/shaders/energize-b.frag | 15 ++++++--------- resources/shaders/fire.frag | 9 +++------ resources/shaders/hexagon.frag | 17 ++++++----------- resources/shaders/matrix.frag | 9 +++------ resources/shaders/snap.frag | 18 +++++++----------- resources/shaders/trex.frag | 9 +++------ resources/shaders/wisps.frag | 9 +++------ 11 files changed, 43 insertions(+), 77 deletions(-) diff --git a/resources/shaders/apparition.frag b/resources/shaders/apparition.frag index 7e4372a..5f1d8db 100644 --- a/resources/shaders/apparition.frag +++ b/resources/shaders/apparition.frag @@ -48,12 +48,8 @@ void main() { float c = cos(angle); coords = vec2(dot(coords, vec2(c, -s)), dot(coords, vec2(s, c))); - // Shell.GLSLEffect uses straight alpha. So we have to convert from premultiplied. - oColor = texture2D(uTexture, coords + center); - if (oColor.a > 0) { - oColor.rgb /= oColor.a; - } - // Fade out the window texture. + vec4 oColor = getInputColor(coords + center); oColor.a *= 1.0 - progress; + setOutputColor(oColor); } \ No newline at end of file diff --git a/resources/shaders/broken-glass.frag b/resources/shaders/broken-glass.frag index fd1a508..da5477c 100644 --- a/resources/shaders/broken-glass.frag +++ b/resources/shaders/broken-glass.frag @@ -25,7 +25,7 @@ const float ACTOR_SCALE = 2.0; const float PADDING = ACTOR_SCALE / 2.0 - 0.5; void main() { - oColor = vec4(0, 0, 0, 0); + vec4 oColor = vec4(0, 0, 0, 0); float progress = uForOpening ? 1.0 - uProgress : uProgress; @@ -66,12 +66,9 @@ void main() { float shardGroup = floor(shardMap.g * SHARD_LAYERS * 0.999); if (shardGroup == i && (shardMap.x - pow(progress + 0.1, 2)) > 0) { - oColor = texture2D(uTexture, coords); + oColor = getInputColor(coords); } } - // Shell.GLSLEffect uses straight alpha. So we have to convert from premultiplied. - if (oColor.a > 0) { - oColor.rgb /= oColor.a; - } + setOutputColor(oColor); } \ No newline at end of file diff --git a/resources/shaders/common.glsl b/resources/shaders/common.glsl index 04c1085..798ff43 100644 --- a/resources/shaders/common.glsl +++ b/resources/shaders/common.glsl @@ -106,7 +106,7 @@ uniform float uTime; uniform vec2 uSize; uniform float uPadding; -// On GNOME, we set iTexCoord and oColor to be aliases for the cogl variables. +// On GNOME, we set iTexCoord to be an alias for the cogl variables. #define iTexCoord cogl_tex_coord_in[0] // Shell.GLSLEffect uses straight alpha. So we have to convert from premultiplied. diff --git a/resources/shaders/energize-a.frag b/resources/shaders/energize-a.frag index a1d1264..e8ccd43 100644 --- a/resources/shaders/energize-a.frag +++ b/resources/shaders/energize-a.frag @@ -59,17 +59,12 @@ vec2 getMasks(float progress) { void main() { float progress = easeOutQuad(uProgress); - vec2 masks = getMasks(progress); - vec4 windowColor = texture2D(uTexture, iTexCoord.st); - - // Shell.GLSLEffect uses straight alpha. So we have to convert from premultiplied. - if (windowColor.a > 0) { - windowColor.rgb /= windowColor.a; - } + vec2 masks = getMasks(progress); + vec4 oColor = getInputColor(iTexCoord.st); // Dissolve window to effect color / transparency. - oColor.rgb = mix(uColor, windowColor.rgb, 0.2 * masks.y + 0.8); - oColor.a = windowColor.a * masks.y; + oColor.rgb = mix(uColor, oColor.rgb, 0.2 * masks.y + 0.8); + oColor.a = oColor.a * masks.y; vec2 scaledUV = (iTexCoord.st - 0.5) * (1.0 + 0.1 * progress); scaledUV /= uScale; @@ -94,4 +89,6 @@ void main() { // oColor = vec4(vec3(masks.x), 1.0); // oColor = vec4(vec3(masks.y), 1.0); // oColor = vec4(vec3(particles), 1.0); + + setOutputColor(oColor); } \ No newline at end of file diff --git a/resources/shaders/energize-b.frag b/resources/shaders/energize-b.frag index 68856b9..32dad1f 100644 --- a/resources/shaders/energize-b.frag +++ b/resources/shaders/energize-b.frag @@ -76,17 +76,12 @@ vec4 getMasks(float progress) { void main() { float progress = easeOutQuad(uProgress); - vec4 masks = getMasks(progress); - vec4 windowColor = texture2D(uTexture, iTexCoord.st); - - // Shell.GLSLEffect uses straight alpha. So we have to convert from premultiplied. - if (windowColor.a > 0) { - windowColor.rgb /= windowColor.a; - } + vec4 masks = getMasks(progress); + vec4 oColor = getInputColor(iTexCoord.st); // Dissolve window to effect color / transparency. - oColor.rgb = mix(uColor, windowColor.rgb, 0.5 * masks.w + 0.5); - oColor.a = windowColor.a * masks.w; + oColor.rgb = mix(uColor, oColor.rgb, 0.5 * masks.w + 0.5); + oColor.a = oColor.a * masks.w; // Add leading shower particles. vec2 showerUV = iTexCoord.st + vec2(0, -0.7 * progress / SHOWER_TIME); @@ -118,4 +113,6 @@ void main() { // oColor = vec4(vec3(shower), 1.0); // oColor = vec4(vec3(streaks), 1.0); // oColor = vec4(vec3(atoms), 1.0); + + setOutputColor(oColor); } \ No newline at end of file diff --git a/resources/shaders/fire.frag b/resources/shaders/fire.frag index f1cf381..44b0d65 100644 --- a/resources/shaders/fire.frag +++ b/resources/shaders/fire.frag @@ -103,12 +103,7 @@ void main() { vec4 fire = getFireColor(noise); // Get the window texture. - oColor = texture2D(uTexture, iTexCoord.st); - - // Shell.GLSLEffect uses straight alpha. So we have to convert from premultiplied. - if (oColor.a > 0) { - oColor.rgb /= oColor.a; - } + vec4 oColor = getInputColor(iTexCoord.st); // Fade the window according to the effect mask. oColor.a *= effectMask.x; @@ -120,4 +115,6 @@ void main() { // oColor = vec4(vec3(noise), 1); // oColor = vec4(vec3(effectMask.x), 1); // oColor = vec4(vec3(effectMask.y), 1); + + setOutputColor(oColor); } \ No newline at end of file diff --git a/resources/shaders/hexagon.frag b/resources/shaders/hexagon.frag index 14f8a8a..2900a2a 100644 --- a/resources/shaders/hexagon.frag +++ b/resources/shaders/hexagon.frag @@ -79,22 +79,15 @@ void main() { vec2 texScale = 0.1 * uSize / uScale; vec4 hex = getHexagons(iTexCoord.st * texScale); - if (tileProgress > hex.z) { + vec4 oColor = vec4(0.0); - // Crop outer parts of the shrinking tiles. - oColor.a = 0.0; - - } else { + // Crop outer parts of the shrinking tiles. + if (tileProgress < hex.z) { // Make the tiles shrink by offsetting the texture lookup towards the edge // of the cell. vec2 lookupOffset = tileProgress * hex.xy / texScale / (1.0 - tileProgress); - oColor = texture2D(uTexture, iTexCoord.st + lookupOffset); - - // Shell.GLSLEffect uses straight alpha. So we have to convert from premultiplied. - if (oColor.a > 0) { - oColor.rgb /= oColor.a; - } + oColor = getInputColor(iTexCoord.st + lookupOffset); vec4 glow = uGlowColor; vec4 line = uLineColor; @@ -122,4 +115,6 @@ void main() { oColor.rgb = mix(oColor.rgb, line.rgb, line.a); } } + + setOutputColor(oColor); } \ No newline at end of file diff --git a/resources/shaders/matrix.frag b/resources/shaders/matrix.frag index ad1db69..4547474 100644 --- a/resources/shaders/matrix.frag +++ b/resources/shaders/matrix.frag @@ -83,12 +83,7 @@ void main() { float textMask = getText(coords); // Get the window texture. - oColor = texture2D(uTexture, coords); - - // Shell.GLSLEffect uses straight alpha. So we have to convert from premultiplied. - if (oColor.a > 0) { - oColor.rgb /= oColor.a; - } + vec4 oColor = getInputColor(coords); // Fade the window according to the effect mask. oColor.a *= rainMask.y; @@ -107,4 +102,6 @@ void main() { // oColor = vec4(vec3(textMask), 1); // oColor = vec4(vec3(rainMask.x), 1); // oColor = vec4(vec3(rainMask.y), 1); + + setOutputColor(oColor); } \ No newline at end of file diff --git a/resources/shaders/snap.frag b/resources/shaders/snap.frag index 952b95a..25a69bf 100644 --- a/resources/shaders/snap.frag +++ b/resources/shaders/snap.frag @@ -34,11 +34,7 @@ void main() { progress = progress + 0.25 - 0.5 * simplex2D((iTexCoord.st + uSeed) * 2.0); progress = pow(max(0, progress), 2.0); - // This may help you to understand how this effect works. - // oColor = vec4(progress, 0, 0, 0); - // return; - - oColor = vec4(0, 0, 0, 0); + vec4 oColor = vec4(0.0); for (float i = 0; i < DUST_LAYERS; ++i) { @@ -80,12 +76,7 @@ void main() { if (dustGroup == i) { // 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; - } + vec4 windowColor = getInputColor(coords + 0.5); // Fade the window color to uDustColor. vec3 dustColor = mix(windowColor.rgb, uDustColor.rgb, uDustColor.a); @@ -97,4 +88,9 @@ void main() { } } } + + // This may help you to understand how this effect works. + // oColor = vec4(progress, 0, 0, 0); + + setOutputColor(oColor); } \ No newline at end of file diff --git a/resources/shaders/trex.frag b/resources/shaders/trex.frag index a59b699..ecb74f4 100644 --- a/resources/shaders/trex.frag +++ b/resources/shaders/trex.frag @@ -90,12 +90,7 @@ void main() { // Get the window texture. We shift the texture lookup by the local derivative of // the claw texture in order to mimic some folding distortion. vec2 offset = vec2(dFdx(scratchMap), dFdy(scratchMap)) * progress * 0.5; - oColor = texture2D(uTexture, coords + offset); - - // Shell.GLSLEffect uses straight alpha. So we have to convert from premultiplied. - if (oColor.a > 0) { - oColor.rgb /= oColor.a; - } + vec4 oColor = getInputColor(coords + offset); // Add colorful flashes. float flashIntensity = 1.0 / FLASH_INTENSITY * (scratchMap - progress) + 1; @@ -120,4 +115,6 @@ void main() { // These are pretty useful for understanding how this works. // oColor = vec4(vec3(flashIntensity), 1); // oColor = vec4(vec3(scratchMap), 1); + + setOutputColor(oColor); } \ No newline at end of file diff --git a/resources/shaders/wisps.frag b/resources/shaders/wisps.frag index de7e6e6..90d36de 100644 --- a/resources/shaders/wisps.frag +++ b/resources/shaders/wisps.frag @@ -71,12 +71,7 @@ void main() { vec2 coords = iTexCoord.st * (scale + 1.0) - scale * 0.5; // Get the color of the window. - oColor = texture2D(uTexture, coords); - - // Shell.GLSLEffect uses straight alpha. So we have to convert from premultiplied. - if (oColor.a > 0) { - oColor.rgb /= oColor.a; - } + vec4 oColor = getInputColor(coords); // Compute several layers of moving wisps. vec2 uv = (iTexCoord.st - 0.5) / mix(1.0, 0.5, progress) + 0.5; @@ -110,4 +105,6 @@ void main() { // oColor = vec4(vec3(wisps), 1.0); // oColor = vec4(vec3(noise), 1.0); // oColor = vec4(vec3(mask*min(wispsIn, 1.0 - wispsOut)), 1.0); + + setOutputColor(oColor); } \ No newline at end of file