🔧 Pass window padding to the shaders
This commit is contained in:
@@ -92,6 +92,7 @@ Please study this code carefully, all of it is explained with inline comments.
|
|||||||
// float uProgress: A value which transitions from 0 to 1 during the entire animation.
|
// float uProgress: A value which transitions from 0 to 1 during the entire 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 is drawn).
|
||||||
#include "common/uniforms.glsl"
|
#include "common/uniforms.glsl"
|
||||||
|
|
||||||
// The width of the fading effect is loaded from the settings.
|
// The width of the fading effect is loaded from the settings.
|
||||||
|
|||||||
@@ -11,11 +11,22 @@ float getEdgeMask(vec2 uv, vec2 maxUV, float fadeWidth) {
|
|||||||
return mask;
|
return mask;
|
||||||
}
|
}
|
||||||
|
|
||||||
float getAbsoluteEdgeMask(float fadePixels) {
|
// Returns an edge mask which fades to zero at the boundaries of the actor. The width of
|
||||||
vec2 uv = cogl_tex_coord_in[0].st * uSize;
|
// the fade zone is given in pixels. This uses the standard uniforms uSize and uPadding.
|
||||||
return getEdgeMask(uv, uSize, fadePixels);
|
// This means that the fading zone is not actually at the actors boundaries but at the
|
||||||
|
// position of the window border in the texture.
|
||||||
|
// The offset paramter controls whether the fading is placed inside the window borders
|
||||||
|
// (offset = 0), ontop the window borders (offset = 0.5) or outside the window borders
|
||||||
|
// (offset = 1).
|
||||||
|
float getAbsoluteEdgeMask(float fadePixels, float offset) {
|
||||||
|
float padding = max(0, uPadding - fadePixels * offset);
|
||||||
|
vec2 uv = cogl_tex_coord_in[0].st * uSize - padding;
|
||||||
|
return getEdgeMask(uv, uSize - 2.0 * padding, fadePixels);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Returns an edge mask which fades to zero at the boundaries of the actor. The width of
|
||||||
|
// the fade zone is given relative to the actor size. This neither uses uSize and
|
||||||
|
// uPadding.
|
||||||
float getRelativeEdgeMask(float fadeAmount) {
|
float getRelativeEdgeMask(float fadeAmount) {
|
||||||
vec2 uv = cogl_tex_coord_in[0].st;
|
vec2 uv = cogl_tex_coord_in[0].st;
|
||||||
return getEdgeMask(uv, vec2(1.0), fadeAmount);
|
return getEdgeMask(uv, vec2(1.0), fadeAmount);
|
||||||
|
|||||||
@@ -4,8 +4,10 @@
|
|||||||
// uProgress: A value which transitions from 0 to 1 during the entire animation.
|
// uProgress: A value which transitions from 0 to 1 during the entire animation.
|
||||||
// uTime: A steadily increasing value in seconds.
|
// uTime: A steadily increasing value in seconds.
|
||||||
// uSize: The size of uTexture in pixels.
|
// uSize: The size of uTexture in pixels.
|
||||||
|
// uPadding: The empty area around the actual window (e.g. where the shadow is drawn).
|
||||||
uniform bool uForOpening;
|
uniform bool uForOpening;
|
||||||
uniform sampler2D uTexture;
|
uniform sampler2D uTexture;
|
||||||
uniform float uProgress;
|
uniform float uProgress;
|
||||||
uniform float uTime;
|
uniform float uTime;
|
||||||
uniform vec2 uSize;
|
uniform vec2 uSize;
|
||||||
|
uniform float uPadding;
|
||||||
@@ -30,7 +30,7 @@ vec2 getMasks(float progress) {
|
|||||||
atomMask *= smoothstep(1.0, 0.0, fadeOutProgress);
|
atomMask *= smoothstep(1.0, 0.0, fadeOutProgress);
|
||||||
|
|
||||||
// Fade-out the masks at the window edges.
|
// Fade-out the masks at the window edges.
|
||||||
float edgeFade = getAbsoluteEdgeMask(EDGE_FADE_WIDTH);
|
float edgeFade = getAbsoluteEdgeMask(EDGE_FADE_WIDTH, 0.5);
|
||||||
atomMask *= edgeFade;
|
atomMask *= edgeFade;
|
||||||
|
|
||||||
float heartMask = getRelativeEdgeMask(0.5);
|
float heartMask = getRelativeEdgeMask(0.5);
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ vec4 getMasks(float progress) {
|
|||||||
streakMask = max(streakMask, showerMask);
|
streakMask = max(streakMask, showerMask);
|
||||||
|
|
||||||
// Fade-out the masks at the window edges.
|
// Fade-out the masks at the window edges.
|
||||||
float edgeFade = getAbsoluteEdgeMask(EDGE_FADE);
|
float edgeFade = getAbsoluteEdgeMask(EDGE_FADE, 0.5);
|
||||||
streakMask *= edgeFade;
|
streakMask *= edgeFade;
|
||||||
showerMask *= edgeFade;
|
showerMask *= edgeFade;
|
||||||
|
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ vec2 effectMask(float hideTime, float fadeWidth, float edgeFadeWidth) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Fade at window borders.
|
// Fade at window borders.
|
||||||
effectMask *= getAbsoluteEdgeMask(edgeFadeWidth);
|
effectMask *= getAbsoluteEdgeMask(edgeFadeWidth, 0.5);
|
||||||
|
|
||||||
if (uForOpening) {
|
if (uForOpening) {
|
||||||
windowMask = 1.0 - windowMask;
|
windowMask = 1.0 - windowMask;
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ vec2 getRain(vec2 fragCoord) {
|
|||||||
float windowAlpha = 1 - clamp(uSize.y * distToDrop, 0, FADE_WIDTH) / FADE_WIDTH;
|
float windowAlpha = 1 - clamp(uSize.y * distToDrop, 0, FADE_WIDTH) / FADE_WIDTH;
|
||||||
|
|
||||||
// Fade at window borders.
|
// Fade at window borders.
|
||||||
rainAlpha *= getAbsoluteEdgeMask(EDGE_FADE);
|
rainAlpha *= getAbsoluteEdgeMask(EDGE_FADE, 0.5);
|
||||||
|
|
||||||
// Add some variation to the drop start and end position.
|
// Add some variation to the drop start and end position.
|
||||||
float shorten =
|
float shorten =
|
||||||
|
|||||||
@@ -70,10 +70,17 @@ var Shader = GObject.registerClass(
|
|||||||
this._uProgress = this.get_uniform_location('uProgress');
|
this._uProgress = this.get_uniform_location('uProgress');
|
||||||
this._uTime = this.get_uniform_location('uTime');
|
this._uTime = this.get_uniform_location('uTime');
|
||||||
this._uSize = this.get_uniform_location('uSize');
|
this._uSize = this.get_uniform_location('uSize');
|
||||||
|
this._uPadding = this.get_uniform_location('uPadding');
|
||||||
}
|
}
|
||||||
|
|
||||||
// This is called once each time the shader is used.
|
// This is called once each time the shader is used.
|
||||||
beginAnimation(settings, forOpening, actor) {
|
beginAnimation(settings, forOpening, actor) {
|
||||||
|
|
||||||
|
// This is not necessarily symmetric, but I haven't figured out a way to
|
||||||
|
// get the actual values...
|
||||||
|
const padding = (actor.width - actor.meta_window.get_frame_rect().width) / 2;
|
||||||
|
|
||||||
|
this.set_uniform_float(this._uPadding, 1, [padding]);
|
||||||
this.set_uniform_float(this._uForOpening, 1, [forOpening]);
|
this.set_uniform_float(this._uForOpening, 1, [forOpening]);
|
||||||
this.set_uniform_float(this._uSize, 2, [actor.width, actor.height]);
|
this.set_uniform_float(this._uSize, 2, [actor.width, actor.height]);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user