🔧 Use methods shader I/O

This commit is contained in:
Simon Schneegans
2022-06-09 11:34:18 +02:00
parent b8335dd4e6
commit bf3aa0af93
3 changed files with 60 additions and 24 deletions
+2 -2
View File
@@ -109,7 +109,7 @@ class BMW%NICK%Effect {
{
type: Effect.ShaderUniform,
fragmentShader: this.shader,
uniform: "uForOpening",
uniform: "forOpening",
from: 1.0,
to: 1.0
}
@@ -143,7 +143,7 @@ class BMW%NICK%Effect {
{
type: Effect.ShaderUniform,
fragmentShader: this.shader,
uniform: "uForOpening",
uniform: "forOpening",
from: 0.0,
to: 0.0
}
+54 -14
View File
@@ -17,17 +17,21 @@
// --------------------------------------------------------------------- standard uniforms
// Each shader can access these standard uniforms:
// Each shader can access these standard input values:
// bool uForOpening: True if a window-open animation is ongoing, false otherwise.
// sampler2D uTexture: Contains the texture of the window.
// float uProgress: A value which transitions from 0 to 1 during the animation.
// float uTime: A steadily increasing value in seconds.
// vec2 uSize: The size of uTexture in pixels.
// float uPadding: The empty area around the actual window (e.g. where the shadow
// is drawn). For now, this will only be set on GNOME.
// vec2 iTexCoord: Texture coordinates for retrieving the window input color.
// bool uForOpening: True if a window-open animation is ongoing, false otherwise.
// float uProgress: A value which transitions from 0 to 1 during the animation.
// float uTime: A steadily increasing value in seconds.
// vec2 uSize: The size of uTexture in pixels.
// float uPadding: The empty area around the actual window (e.g. where the shadow
// is drawn). For now, this will only be set on GNOME.
// Furthermore, there is the global input "vec2 iTexCoord" and the output "vec4 oColor".
// Furthermore, there are two global methods for reading the window input color and
// setting the shader output color. Both methods assume straight alpha:
// vec4 getInputColor(vec2 coords)
// void setOutputColor(vec4 outColor)
#if defined(KWIN) // --------------------------------------------------------------------
@@ -43,11 +47,23 @@ bool uForOpening = forOpening == 1.0;
in vec2 texcoord0;
out vec4 fragColor;
#define uTexture sampler
#define uProgress animationProgress
#define uPadding 0.0
#define iTexCoord texcoord0
#define oColor fragColor
vec4 getInputColor(vec2 coords) {
vec4 color = texture2D(sampler, coords);
if (color.a > 0.0) {
color.rgb /= color.a;
}
return color;
}
void setOutputColor(vec4 outColor) {
fragColor = vec4(outColor.rgb * outColor.a, outColor.a);
}
#elif defined(KWIN_LEGACY) // -----------------------------------------------------------
@@ -62,11 +78,23 @@ bool uForOpening = forOpening == 1.0;
varying vec2 texcoord0;
#define uTexture sampler
#define uProgress animationProgress
#define uPadding 0.0
#define iTexCoord texcoord0
#define oColor gl_FragColor
vec4 getInputColor(vec2 coords) {
vec4 color = texture2D(sampler, coords);
if (color.a > 0.0) {
color.rgb /= color.a;
}
return color;
}
void setOutputColor(vec4 outColor) {
gl_FragColor = vec4(outColor.rgb * outColor.a, outColor.a);
}
#else // GNOME --------------------------------------------------------------------------
@@ -80,7 +108,19 @@ uniform float uPadding;
// On GNOME, we set iTexCoord and oColor to be aliases for the cogl variables.
#define iTexCoord cogl_tex_coord_in[0]
#define oColor cogl_color_out
// Shell.GLSLEffect uses straight alpha. So we have to convert from premultiplied.
vec4 getInputColor(vec2 coords) {
vec4 color = texture2D(uTexture, coords);
if (color.a > 0.0) {
color.rgb /= color.a;
}
return color;
}
void setOutputColor(vec4 outColor) { cogl_color_out = outColor; }
#endif // -------------------------------------------------------------------------------
+4 -8
View File
@@ -54,14 +54,8 @@ void main() {
// Assemble the final alpha value.
float mask = tbMask * lrMask * ffMask;
oColor = texture2D(uTexture, coords);
// Shell.GLSLEffect uses straight alpha. So we have to convert from premultiplied.
if (oColor.a > 0.0) {
oColor.rgb /= oColor.a;
}
oColor.rgb = mix(oColor.rgb, uColor.rgb * oColor.a, smoothstep(0.0, 1.0, prog));
vec4 oColor = getInputColor(coords);
oColor.rgb = mix(oColor.rgb, uColor.rgb * oColor.a, smoothstep(0.0, 1.0, prog));
oColor.a *= mask;
// These are pretty useful for understanding how this works.
@@ -69,4 +63,6 @@ void main() {
// oColor = vec4(vec3(lrMask), 1);
// oColor = vec4(vec3(ffMask), 1);
// oColor = vec4(vec3(mask), 1);
setOutputColor(oColor);
}