🔧 Use methods shader I/O
This commit is contained in:
+2
-2
@@ -109,7 +109,7 @@ class BMW%NICK%Effect {
|
|||||||
{
|
{
|
||||||
type: Effect.ShaderUniform,
|
type: Effect.ShaderUniform,
|
||||||
fragmentShader: this.shader,
|
fragmentShader: this.shader,
|
||||||
uniform: "uForOpening",
|
uniform: "forOpening",
|
||||||
from: 1.0,
|
from: 1.0,
|
||||||
to: 1.0
|
to: 1.0
|
||||||
}
|
}
|
||||||
@@ -143,7 +143,7 @@ class BMW%NICK%Effect {
|
|||||||
{
|
{
|
||||||
type: Effect.ShaderUniform,
|
type: Effect.ShaderUniform,
|
||||||
fragmentShader: this.shader,
|
fragmentShader: this.shader,
|
||||||
uniform: "uForOpening",
|
uniform: "forOpening",
|
||||||
from: 0.0,
|
from: 0.0,
|
||||||
to: 0.0
|
to: 0.0
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,17 +17,21 @@
|
|||||||
|
|
||||||
// --------------------------------------------------------------------- standard uniforms
|
// --------------------------------------------------------------------- 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.
|
// vec2 iTexCoord: Texture coordinates for retrieving the window input color.
|
||||||
// sampler2D uTexture: Contains the texture of the window.
|
// 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 uProgress: A value which transitions from 0 to 1 during the animation.
|
||||||
// float uTime: A steadily increasing value in seconds.
|
// float uTime: A steadily increasing value in seconds.
|
||||||
// vec2 uSize: The size of uTexture in pixels.
|
// vec2 uSize: The size of uTexture in pixels.
|
||||||
// float uPadding: The empty area around the actual window (e.g. where the shadow
|
// 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.
|
// 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) // --------------------------------------------------------------------
|
#if defined(KWIN) // --------------------------------------------------------------------
|
||||||
|
|
||||||
@@ -43,11 +47,23 @@ bool uForOpening = forOpening == 1.0;
|
|||||||
in vec2 texcoord0;
|
in vec2 texcoord0;
|
||||||
out vec4 fragColor;
|
out vec4 fragColor;
|
||||||
|
|
||||||
#define uTexture sampler
|
|
||||||
#define uProgress animationProgress
|
#define uProgress animationProgress
|
||||||
#define uPadding 0.0
|
#define uPadding 0.0
|
||||||
#define iTexCoord texcoord0
|
#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) // -----------------------------------------------------------
|
#elif defined(KWIN_LEGACY) // -----------------------------------------------------------
|
||||||
|
|
||||||
@@ -62,11 +78,23 @@ bool uForOpening = forOpening == 1.0;
|
|||||||
|
|
||||||
varying vec2 texcoord0;
|
varying vec2 texcoord0;
|
||||||
|
|
||||||
#define uTexture sampler
|
|
||||||
#define uProgress animationProgress
|
#define uProgress animationProgress
|
||||||
#define uPadding 0.0
|
#define uPadding 0.0
|
||||||
#define iTexCoord texcoord0
|
#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 --------------------------------------------------------------------------
|
#else // GNOME --------------------------------------------------------------------------
|
||||||
|
|
||||||
@@ -80,7 +108,19 @@ uniform float uPadding;
|
|||||||
|
|
||||||
// On GNOME, we set iTexCoord and oColor to be aliases for the cogl variables.
|
// On GNOME, we set iTexCoord and oColor to be aliases for the cogl variables.
|
||||||
#define iTexCoord cogl_tex_coord_in[0]
|
#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 // -------------------------------------------------------------------------------
|
#endif // -------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|||||||
@@ -54,14 +54,8 @@ void main() {
|
|||||||
// Assemble the final alpha value.
|
// Assemble the final alpha value.
|
||||||
float mask = tbMask * lrMask * ffMask;
|
float mask = tbMask * lrMask * ffMask;
|
||||||
|
|
||||||
oColor = texture2D(uTexture, coords);
|
vec4 oColor = getInputColor(coords);
|
||||||
|
oColor.rgb = mix(oColor.rgb, uColor.rgb * oColor.a, smoothstep(0.0, 1.0, prog));
|
||||||
// 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));
|
|
||||||
oColor.a *= mask;
|
oColor.a *= mask;
|
||||||
|
|
||||||
// These are pretty useful for understanding how this works.
|
// These are pretty useful for understanding how this works.
|
||||||
@@ -69,4 +63,6 @@ void main() {
|
|||||||
// oColor = vec4(vec3(lrMask), 1);
|
// oColor = vec4(vec3(lrMask), 1);
|
||||||
// oColor = vec4(vec3(ffMask), 1);
|
// oColor = vec4(vec3(ffMask), 1);
|
||||||
// oColor = vec4(vec3(mask), 1);
|
// oColor = vec4(vec3(mask), 1);
|
||||||
|
|
||||||
|
setOutputColor(oColor);
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user