🎉 Add initial matrix shader

This commit is contained in:
Simon Schneegans
2021-12-22 21:34:03 +01:00
parent 75b803d523
commit 547db3a2b8
6 changed files with 432 additions and 46 deletions
+263
View File
@@ -0,0 +1,263 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
width="512"
height="512"
viewBox="0 0 135.46666 135.46667"
version="1.1"
id="svg5"
inkscape:version="1.1.1 (3bf5ae0d25, 2021-09-20)"
sodipodi:docname="matrixFont.svg"
inkscape:export-filename="/home/simon/Linux-Projects/Burn-My-Windows/resources/img/matrixFont.png"
inkscape:export-xdpi="96"
inkscape:export-ydpi="96"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns="http://www.w3.org/2000/svg"
xmlns:svg="http://www.w3.org/2000/svg">
<sodipodi:namedview
id="namedview7"
pagecolor="#000000"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageshadow="2"
inkscape:pageopacity="1"
inkscape:pagecheckerboard="0"
inkscape:document-units="mm"
showgrid="true"
units="px"
inkscape:zoom="7.2071955"
inkscape:cx="45.163199"
inkscape:cy="43.428821"
inkscape:window-width="1920"
inkscape:window-height="1131"
inkscape:window-x="0"
inkscape:window-y="32"
inkscape:window-maximized="1"
inkscape:current-layer="layer1">
<inkscape:grid
type="xygrid"
id="grid8183"
empspacing="2"
spacingx="4.2333333"
spacingy="4.2333333" />
</sodipodi:namedview>
<defs
id="defs2">
<filter
inkscape:collect="always"
style="color-interpolation-filters:sRGB"
id="filter94388"
x="-0.022532737"
y="-0.022056037"
width="1.0450655"
height="1.0441121">
<feGaussianBlur
inkscape:collect="always"
stdDeviation="1.2355019"
id="feGaussianBlur94390" />
</filter>
</defs>
<g
inkscape:label="Layer 1"
inkscape:groupmode="layer"
id="layer1">
<text
xml:space="preserve"
style="font-weight:300;font-size:7.60522px;line-height:1.112;font-family:'Open Sans';-inkscape-font-specification:'Open Sans Light';letter-spacing:3.89202px;opacity:1;stroke-width:0.190131"
x="1.7241572"
y="6.4795361"
id="text94444"><tspan
sodipodi:role="line"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-family:monospace;-inkscape-font-specification:monospace;fill:#ffffff;fill-opacity:1;stroke-width:0.190131"
x="1.7241572"
y="6.4795361"
id="tspan94410">ABCDEFGHIJKLMNOP</tspan><tspan
sodipodi:role="line"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-family:monospace;-inkscape-font-specification:monospace;fill:#ffffff;fill-opacity:1;stroke-width:0.190131"
x="1.7241572"
y="14.946301"
id="tspan94412">QRSTUVWXYZabcdef</tspan><tspan
sodipodi:role="line"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-family:monospace;-inkscape-font-specification:monospace;fill:#ffffff;fill-opacity:1;stroke-width:0.190131"
x="1.7241572"
y="23.413067"
id="tspan94414">ghijklmnopqrstuv</tspan><tspan
sodipodi:role="line"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-family:monospace;-inkscape-font-specification:monospace;fill:#ffffff;fill-opacity:1;stroke-width:0.190131"
x="1.7241572"
y="31.879831"
id="tspan94416">wxyzÀÁÂÃÄÅÆÇÈÉÊË</tspan><tspan
sodipodi:role="line"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-family:monospace;-inkscape-font-specification:monospace;fill:#ffffff;fill-opacity:1;stroke-width:0.190131"
x="1.7241572"
y="40.346596"
id="tspan94418">ÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜ</tspan><tspan
sodipodi:role="line"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-family:monospace;-inkscape-font-specification:monospace;fill:#ffffff;fill-opacity:1;stroke-width:0.190131"
x="1.7241572"
y="48.813362"
id="tspan94420">ÝÞßàáâãäåæçèéêëì</tspan><tspan
sodipodi:role="line"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-family:monospace;-inkscape-font-specification:monospace;fill:#ffffff;fill-opacity:1;stroke-width:0.190131"
x="1.7241572"
y="57.280125"
id="tspan94422">íîïðΑαΒβΓγΔδΕεΖζ</tspan><tspan
sodipodi:role="line"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-family:monospace;-inkscape-font-specification:monospace;fill:#ffffff;fill-opacity:1;stroke-width:0.190131"
x="1.7241572"
y="65.746887"
id="tspan94424">ΗηΘθΙιΚκΛλΜμΝνΞξ</tspan><tspan
sodipodi:role="line"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-family:monospace;-inkscape-font-specification:monospace;fill:#ffffff;fill-opacity:1;stroke-width:0.190131"
x="1.7241572"
y="74.213654"
id="tspan94426">ΟοΠπΡρΣσΤτΥυΦφΧχ</tspan><tspan
sodipodi:role="line"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-family:monospace;-inkscape-font-specification:monospace;fill:#ffffff;fill-opacity:1;stroke-width:0.190131"
x="1.7241572"
y="82.68042"
id="tspan94428">ΨψΩω1234567890Аа</tspan><tspan
sodipodi:role="line"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-family:monospace;-inkscape-font-specification:monospace;fill:#ffffff;fill-opacity:1;stroke-width:0.190131"
x="1.7241572"
y="91.147186"
id="tspan94430">БбВвГгДдЕеЖжЗзИи</tspan><tspan
sodipodi:role="line"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-family:monospace;-inkscape-font-specification:monospace;fill:#ffffff;fill-opacity:1;stroke-width:0.190131"
x="1.7241572"
y="99.613953"
id="tspan94432">ЙйКкЛлМмНнОоПпРр</tspan><tspan
sodipodi:role="line"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-family:monospace;-inkscape-font-specification:monospace;fill:#ffffff;fill-opacity:1;stroke-width:0.190131"
x="1.7241572"
y="108.08072"
id="tspan94434">СсТтУуФфХхЦцЧчШш</tspan><tspan
sodipodi:role="line"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-family:monospace;-inkscape-font-specification:monospace;fill:#ffffff;fill-opacity:1;stroke-width:0.190131"
x="1.7241572"
y="116.54748"
id="tspan94436">ЩщЬьЭэЮюЯя!&quot;#$%&amp;</tspan><tspan
sodipodi:role="line"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-family:monospace;-inkscape-font-specification:monospace;fill:#ffffff;fill-opacity:1;stroke-width:0.190131"
x="1.7241572"
y="125.01424"
id="tspan94438">()*+,-/:;&lt;=&gt;?@©§</tspan><tspan
sodipodi:role="line"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-family:monospace;-inkscape-font-specification:monospace;fill:#ffffff;fill-opacity:1;stroke-width:0.190131"
x="1.7241572"
y="133.48102"
id="tspan94440">[\]{|}~ªº¿®¬½¼¡¶</tspan><tspan
sodipodi:role="line"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-family:monospace;-inkscape-font-specification:monospace;fill:#ffffff;fill-opacity:1;stroke-width:0.190131"
x="1.7241572"
y="141.94777"
id="tspan94442" /></text>
<text
xml:space="preserve"
style="font-weight:300;font-size:7.60522px;line-height:1.112;font-family:'Open Sans';-inkscape-font-specification:'Open Sans Light';letter-spacing:3.89202px;opacity:0.87766207;mix-blend-mode:normal;stroke-width:0.190131;filter:url(#filter94388)"
x="1.7241572"
y="6.4795361"
id="text3003"
inkscape:export-filename="/home/simon/Linux-Projects/Burn-My-Windows/resources/img/text3003.png"
inkscape:export-xdpi="96"
inkscape:export-ydpi="96"><tspan
sodipodi:role="line"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-family:monospace;-inkscape-font-specification:monospace;fill:#ffffff;fill-opacity:1;stroke-width:0.190131"
x="1.7241572"
y="6.4795361"
id="tspan30643">ABCDEFGHIJKLMNOP</tspan><tspan
sodipodi:role="line"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-family:monospace;-inkscape-font-specification:monospace;fill:#ffffff;fill-opacity:1;stroke-width:0.190131"
x="1.7241572"
y="14.946301"
id="tspan40072">QRSTUVWXYZabcdef</tspan><tspan
sodipodi:role="line"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-family:monospace;-inkscape-font-specification:monospace;fill:#ffffff;fill-opacity:1;stroke-width:0.190131"
x="1.7241572"
y="23.413067"
id="tspan42210">ghijklmnopqrstuv</tspan><tspan
sodipodi:role="line"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-family:monospace;-inkscape-font-specification:monospace;fill:#ffffff;fill-opacity:1;stroke-width:0.190131"
x="1.7241572"
y="31.879831"
id="tspan43166">wxyzÀÁÂÃÄÅÆÇÈÉÊË</tspan><tspan
sodipodi:role="line"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-family:monospace;-inkscape-font-specification:monospace;fill:#ffffff;fill-opacity:1;stroke-width:0.190131"
x="1.7241572"
y="40.346596"
id="tspan43762">ÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜ</tspan><tspan
sodipodi:role="line"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-family:monospace;-inkscape-font-specification:monospace;fill:#ffffff;fill-opacity:1;stroke-width:0.190131"
x="1.7241572"
y="48.813362"
id="tspan44946">ÝÞßàáâãäåæçèéêëì</tspan><tspan
sodipodi:role="line"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-family:monospace;-inkscape-font-specification:monospace;fill:#ffffff;fill-opacity:1;stroke-width:0.190131"
x="1.7241572"
y="57.280125"
id="tspan48062">íîïðΑαΒβΓγΔδΕεΖζ</tspan><tspan
sodipodi:role="line"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-family:monospace;-inkscape-font-specification:monospace;fill:#ffffff;fill-opacity:1;stroke-width:0.190131"
x="1.7241572"
y="65.746887"
id="tspan56533">ΗηΘθΙιΚκΛλΜμΝνΞξ</tspan><tspan
sodipodi:role="line"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-family:monospace;-inkscape-font-specification:monospace;fill:#ffffff;fill-opacity:1;stroke-width:0.190131"
x="1.7241572"
y="74.213654"
id="tspan58635">ΟοΠπΡρΣσΤτΥυΦφΧχ</tspan><tspan
sodipodi:role="line"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-family:monospace;-inkscape-font-specification:monospace;fill:#ffffff;fill-opacity:1;stroke-width:0.190131"
x="1.7241572"
y="82.68042"
id="tspan61169">ΨψΩω1234567890Аа</tspan><tspan
sodipodi:role="line"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-family:monospace;-inkscape-font-specification:monospace;fill:#ffffff;fill-opacity:1;stroke-width:0.190131"
x="1.7241572"
y="91.147186"
id="tspan67243">БбВвГгДдЕеЖжЗзИи</tspan><tspan
sodipodi:role="line"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-family:monospace;-inkscape-font-specification:monospace;fill:#ffffff;fill-opacity:1;stroke-width:0.190131"
x="1.7241572"
y="99.613953"
id="tspan69399">ЙйКкЛлМмНнОоПпРр</tspan><tspan
sodipodi:role="line"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-family:monospace;-inkscape-font-specification:monospace;fill:#ffffff;fill-opacity:1;stroke-width:0.190131"
x="1.7241572"
y="108.08072"
id="tspan70763">СсТтУуФфХхЦцЧчШш</tspan><tspan
sodipodi:role="line"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-family:monospace;-inkscape-font-specification:monospace;fill:#ffffff;fill-opacity:1;stroke-width:0.190131"
x="1.7241572"
y="116.54748"
id="tspan72709">ЩщЬьЭэЮюЯя!&quot;#$%&amp;</tspan><tspan
sodipodi:role="line"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-family:monospace;-inkscape-font-specification:monospace;fill:#ffffff;fill-opacity:1;stroke-width:0.190131"
x="1.7241572"
y="125.01424"
id="tspan77955">()*+,-/:;&lt;=&gt;?@©§</tspan><tspan
sodipodi:role="line"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-family:monospace;-inkscape-font-specification:monospace;fill:#ffffff;fill-opacity:1;stroke-width:0.190131"
x="1.7241572"
y="133.48102"
id="tspan77957">[\]{|}~ªº¿®¬½¼¡¶</tspan><tspan
sodipodi:role="line"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-family:monospace;-inkscape-font-specification:monospace;fill:#ffffff;fill-opacity:1;stroke-width:0.190131"
x="1.7241572"
y="141.94777"
id="tspan75487" /></text>
<text
xml:space="preserve"
style="font-weight:300;font-size:10.5833px;line-height:1.25;font-family:'Open Sans';-inkscape-font-specification:'Open Sans Light';stroke-width:0.264583"
x="169.33333"
y="29.009251"
id="text17385"><tspan
sodipodi:role="line"
id="tspan17383"
style="stroke-width:0.264583"
x="169.33333"
y="29.009251" /></text>
</g>
</svg>

After

Width:  |  Height:  |  Size: 15 KiB

+10 -2
View File
@@ -13,7 +13,7 @@
'use strict';
const {Clutter} = imports.gi;
const {Clutter, Gio} = imports.gi;
const Workspace = imports.ui.workspace.Workspace;
const WindowManager = imports.ui.windowManager.WindowManager;
@@ -23,6 +23,7 @@ const ExtensionUtils = imports.misc.extensionUtils;
const Me = imports.misc.extensionUtils.getCurrentExtension();
const utils = Me.imports.src.common.utils;
const FireShader = Me.imports.src.extension.FireShader.FireShader;
const MatrixShader = Me.imports.src.extension.MatrixShader.MatrixShader;
//////////////////////////////////////////////////////////////////////////////////////////
// This extensions modifies the window-close animation to look like the window was set //
@@ -39,6 +40,10 @@ class Extension {
// from GNOME Tweaks, when you log in or when the screen is unlocked.
enable() {
// Load all of our resources.
this._resources = Gio.Resource.load(Me.path + '/resources/burn-my-windows.gresource');
Gio.resources_register(this._resources);
// Store a reference to the settings object.
this._settings = ExtensionUtils.getSettings();
@@ -127,7 +132,7 @@ class Extension {
tweakTransition('scale-y', 1);
// Instead, we add a cool shader to our window actor!
const shader = new FireShader(this._settings);
const shader = new MatrixShader(this._settings);
actor.add_effect(shader);
// Update uniforms at each frame.
@@ -144,6 +149,9 @@ class Extension {
// Tweaks, when you log out or when the screen locks.
disable() {
// Unregister our resources.
Gio.resources_unregister(this._resources);
// Restore the original behavior.
global.window_manager.disconnect(this._destroyConnection);
Binary file not shown.

After

Width:  |  Height:  |  Size: 203 KiB

+39 -2
View File
@@ -44,7 +44,6 @@ var FireShader = GObject.registerClass({Properties: {}, Signals: {}},
// Inject some common shader snippets.
${shaderSnippets.standardUniforms()}
${shaderSnippets.noise()}
${shaderSnippets.effectMask()}
// These may be configurable in the future.
const float EDGE_FADE = 70;
@@ -78,7 +77,45 @@ var FireShader = GObject.registerClass({Properties: {}, Signals: {}},
return colors[4];
}
void main(void) {
// This method requires the uniforms from standardUniforms() to be available.
// It returns two values: The first is an alpha value which can be used for the window
// texture. This gradually dissolves the window from top to bottom. The second can be used
// to mask any effect, it will be most opaque where the window is currently fading and
// gradually dissolve to zero over time.
// hideTime: A value in [0..1]. It determines the percentage of the animation which
// is spent for hiding the window. 1-hideTime will be spent thereafter for
// dissolving the effect mask.
// fadeWidth: The relative size of the window-hiding gradient in [0..1].
// edgeFadeWidth: The pixel width of the effect fading range at the edges of the window.
vec2 effectMask(float hideTime, float fadeWidth, float edgeFadeWidth) {
float burnProgress = clamp(uProgress/hideTime, 0, 1);
float afterBurnProgress = clamp((uProgress-hideTime)/(1-hideTime), 0, 1);
// Gradient from top to bottom.
float t = cogl_tex_coord_in[0].t * (1 - fadeWidth);
// Visible part of the window. Gradually dissolves towards the bottom.
float windowMask = 1 - clamp((burnProgress - t) / fadeWidth, 0, 1);
// Gradient from top burning window.
float effectMask = clamp(t*(1-windowMask)/burnProgress, 0, 1);
// Fade-out when the window burned down.
if (uProgress > hideTime) {
effectMask *= mix(1, 1-t, afterBurnProgress) * pow(1-afterBurnProgress, 2);
}
// Fade at window borders.
vec2 pos = cogl_tex_coord_in[0].st * vec2(uSizeX, uSizeY);
effectMask *= clamp(pos.x / edgeFadeWidth, 0, 1);
effectMask *= clamp(pos.y / edgeFadeWidth, 0, 1);
effectMask *= clamp((uSizeX - pos.x) / edgeFadeWidth, 0, 1);
effectMask *= clamp((uSizeY - pos.y) / edgeFadeWidth, 0, 1);
return vec2(windowMask, effectMask);
}
void main() {
// Get a noise value which moves vertically in time.
vec2 uv = cogl_tex_coord_in[0].st * vec2(uSizeX, uSizeY) / FIRE_SCALE;
+120
View File
@@ -0,0 +1,120 @@
//////////////////////////////////////////////////////////////////////////////////////////
// ) ( //
// ( /( ( ( ) ( ( ( ( )\ ) ( ( //
// )\()) ))\ )( ( ( )\ ) )\))( )\ ( (()/( ( )\))( ( //
// ((_)\ /((_|()\ )\ ) )\ '(()/( ((_)()((_) )\ ) ((_)))\((_)()\ )\ //
// | |(_|_))( ((_)_(_/( _((_)) )(_)) _(()((_|_)_(_/( _| |((_)(()((_|(_) //
// | '_ \ || | '_| ' \)) | ' \()| || | \ V V / | ' \)) _` / _ \ V V (_-< //
// |_.__/\_,_|_| |_||_| |_|_|_| \_, | \_/\_/|_|_||_|\__,_\___/\_/\_//__/ //
// |__/ //
// Copyright (c) 2021 Simon Schneegans //
// Released under the GPLv3 or later. See LICENSE file for details. //
//////////////////////////////////////////////////////////////////////////////////////////
'use strict';
const {Clutter, GObject, GdkPixbuf, Cogl} = imports.gi;
const ExtensionUtils = imports.misc.extensionUtils;
const Me = imports.misc.extensionUtils.getCurrentExtension();
const shaderSnippets = Me.imports.src.extension.shaderSnippets;
//////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////
var MatrixShader = GObject.registerClass({Properties: {}, Signals: {}},
class MatrixShader extends Clutter.ShaderEffect {
_init(settings) {
super._init({shader_type: Clutter.ShaderType.FRAGMENT_SHADER});
const fontData = GdkPixbuf.Pixbuf.new_from_resource('/img/matrixFont.png');
this._fontTexture = new Clutter.Image();
this._fontTexture.set_data(
fontData.get_pixels(),
fontData.has_alpha ? Cogl.PixelFormat.RGBA_8888 : Cogl.PixelFormat.RGB_888,
fontData.width, fontData.height, fontData.rowstride);
// This is roughly based on https://www.shadertoy.com/view/ldccW4 (CC-BY-NC-SA).
this.set_shader_source(`
// Inject some common shader snippets.
${shaderSnippets.standardUniforms()}
${shaderSnippets.noise()}
uniform sampler2D uFontTexture;
// These may be configurable in the future.
const float EDGE_FADE = 30;
const float FADE_WIDTH = 50;
const float TRAIL_LENGTH = 0.2;
const float FINAL_FADE_START_TIME = 0.8;
const float LETTER_TILES = 16.0;
const float LETTER_SIZE = 16.0;
const float BRIGHTNESS_BOOST = 2;
const float RANDOMNESS = 1.0;
float getText(vec2 fragCoord) {
vec2 coords = fragCoord * vec2(uSizeX, uSizeY);
vec2 uv = mod(coords.xy, LETTER_SIZE)/LETTER_SIZE;
vec2 block = coords/LETTER_SIZE - uv;
// scale the letters up a bit
uv = uv*.8+.1;
// bring back into 0-1 range
uv += floor(rand2(block/512 + uTime*.0000001)*LETTER_TILES);
uv /= LETTER_TILES;
// flip letters horizontally
uv.x = -uv.x+1.0;
return texture2D(uFontTexture, uv).r;
}
vec2 getRain(vec2 fragCoord) {
vec2 coords = fragCoord * vec2(uSizeX, uSizeY);
coords.x -= mod(coords.x, LETTER_SIZE);
float delay = abs(sin(coords.x * 3.0)) * mix(0.0, 1.0, RANDOMNESS);
float speed = cos(coords.x * 7.0) * mix(0.0, 0.3, RANDOMNESS) + 1.5;
float distToDrop = (uProgress*2-delay)*speed - fragCoord.y;
return vec2(distToDrop >= 0 ? exp(-distToDrop/TRAIL_LENGTH) : 0,
clamp(uSizeY*distToDrop, 0, FADE_WIDTH) / FADE_WIDTH);
}
void main() {
vec3 color = vec3(0.1,1,0.35);
// Get a cool matrix effect.
vec2 rain = getRain(cogl_tex_coord_in[0].st);
float text = getText(cogl_tex_coord_in[0].st);
// Get the window texture and fade it according to the effect mask.
float windowAlpha = 1 - rain.y;
cogl_color_out = texture2D(uTexture, cogl_tex_coord_in[0].st) * windowAlpha;
float finalFade = 1-clamp((uProgress-FINAL_FADE_START_TIME)/(1-FINAL_FADE_START_TIME), 0, 1);
float textAlpha = finalFade * rain.x * BRIGHTNESS_BOOST;
// Fade at window borders.
vec2 pos = cogl_tex_coord_in[0].st * vec2(uSizeX, uSizeY);
textAlpha *= clamp(pos.x / EDGE_FADE, 0, 1);
textAlpha *= clamp(pos.y / EDGE_FADE, 0, 1);
textAlpha *= clamp((uSizeX - pos.x) / EDGE_FADE, 0, 1);
textAlpha *= clamp((uSizeY - pos.y) / EDGE_FADE, 0, 1);
// Add the fire to the window.
cogl_color_out.rgb += color * textAlpha * text;
}
`);
};
vfunc_paint_target(node, paint_context) {
const pipeline = this.get_pipeline();
pipeline.set_layer_texture(1, this._fontTexture.get_texture());
this.set_uniform_value('uFontTexture', 1);
super.vfunc_paint_target(node, paint_context);
}
});
-42
View File
@@ -81,45 +81,3 @@ function noise() {
}
`;
}
// This method requires the uniforms from standardUniforms() to be available.
// It returns two values: The first is an alpha value which can be used for the window
// texture. This gradually dissolves the window from top to bottom. The second can be used
// to mask any effect, it will be most opaque where the window is currently fading and
// gradually dissolve to zero over time.
// hideTime: A value in [0..1]. It determines the percentage of the animation which
// is spent for hiding the window. 1-hideTime will be spent thereafter for
// dissolving the effect mask.
// fadeWidth: The relative size of the window-hiding gradient in [0..1].
// edgeFadeWidth: The pixel width of the effect fading range at the edges of the window.
function effectMask() {
return `
vec2 effectMask(float hideTime, float fadeWidth, float edgeFadeWidth) {
float burnProgress = clamp(uProgress/hideTime, 0, 1);
float afterBurnProgress = clamp((uProgress-hideTime)/(1-hideTime), 0, 1);
// Gradient from top to bottom.
float t = cogl_tex_coord_in[0].t * (1 - fadeWidth);
// Visible part of the window. Gradually dissolves towards the bottom.
float windowMask = 1 - clamp((burnProgress - t) / fadeWidth, 0, 1);
// Gradient from top burning window.
float effectMask = clamp(t*(1-windowMask)/burnProgress, 0, 1);
// Fade-out when the window burned down.
if (uProgress > hideTime) {
effectMask *= mix(1, 1-t, afterBurnProgress) * pow(1-afterBurnProgress, 2);
}
// Fade at window borders.
vec2 pos = cogl_tex_coord_in[0].st * vec2(uSizeX, uSizeY);
effectMask *= clamp(pos.x / edgeFadeWidth, 0, 1);
effectMask *= clamp(pos.y / edgeFadeWidth, 0, 1);
effectMask *= clamp((uSizeX - pos.x) / edgeFadeWidth, 0, 1);
effectMask *= clamp((uSizeY - pos.y) / edgeFadeWidth, 0, 1);
return vec2(windowMask, effectMask);
}
`;
}