🎉 Add pixel wipe effect

This commit is contained in:
Simon Schneegans
2022-09-02 06:07:48 +02:00
parent 2db13ea884
commit d746344c76
10 changed files with 475 additions and 6 deletions
+1
View File
@@ -61,6 +61,7 @@ class Extension {
new Me.imports.src.Matrix.Matrix(),
new Me.imports.src.Pixelate.Pixelate(),
new Me.imports.src.PixelWheel.PixelWheel(),
new Me.imports.src.PixelWipe.PixelWipe(),
new Me.imports.src.SnapOfDisintegration.SnapOfDisintegration(),
new Me.imports.src.TRexAttack.TRexAttack(),
new Me.imports.src.TVEffect.TVEffect(),
+1
View File
@@ -57,6 +57,7 @@ var PreferencesDialog = class PreferencesDialog {
new Me.imports.src.Matrix.Matrix(),
new Me.imports.src.Pixelate.Pixelate(),
new Me.imports.src.PixelWheel.PixelWheel(),
new Me.imports.src.PixelWipe.PixelWipe(),
new Me.imports.src.SnapOfDisintegration.SnapOfDisintegration(),
new Me.imports.src.TRexAttack.TRexAttack(),
new Me.imports.src.TVEffect.TVEffect(),
+2 -1
View File
@@ -37,7 +37,8 @@ void main() {
}
// Progressively hide the spokes.
if (mod(angle * uSpokeCount, 1.0) < progress) {
float threshold = mod(angle * uSpokeCount, 1.0);
if (progress > threshold) {
oColor.a = 0.0;
}
+51
View File
@@ -0,0 +1,51 @@
//////////////////////////////////////////////////////////////////////////////////////////
// ) ( //
// ( /( ( ( ) ( ( ( ( )\ ) ( ( //
// )\()) ))\ )( ( ( )\ ) )\))( )\ ( (()/( ( )\))( ( //
// ((_)\ /((_|()\ )\ ) )\ '(()/( ((_)()((_) )\ ) ((_)))\((_)()\ )\ //
// | |(_|_))( ((_)_(_/( _((_)) )(_)) _(()((_|_)_(_/( _| |((_)(()((_|(_) //
// | '_ \ || | '_| ' \)) | ' \()| || | \ V V / | ' \)) _` / _ \ V V (_-< //
// |_.__/\_,_|_| |_||_| |_|_|_| \_, | \_/\_/|_|_||_|\__,_\___/\_/\_//__/ //
// |__/ //
// Copyright (c) 2021 Simon Schneegans //
// Released under the GPLv3 or later. See LICENSE file for details. //
//////////////////////////////////////////////////////////////////////////////////////////
// The content from common.glsl is automatically prepended to each shader effect.
uniform float uPixelSize;
uniform vec2 uStartPos;
const float FADE_WIDTH = 1.0; // Width of the transition.
void main() {
// Now we compute a 2D gradient in [0..1] which covers the entire window. The dark
// regions will be burned first, the bright regions in the end. We mix a radial gradient
// with some noise. The center of the radial gradient is positioned at uStartPos.
float circle = length(iTexCoord - uStartPos);
float progress = easeOutQuad(uProgress);
progress = ((1.0 - progress) * (1.0 + FADE_WIDTH) - 1.0 + circle) / FADE_WIDTH;
progress = smoothstep(0.0, 1.0, progress);
progress = uForOpening ? progress : 1.0 - progress;
// The current level of pixelation increases with the progress.
float pixelSize = ceil(uPixelSize * progress + 1.0);
vec2 pixelGrid = vec2(pixelSize) / uSize;
vec2 texcoord = iTexCoord.st - mod(iTexCoord.st, pixelGrid) + pixelGrid * 0.5;
vec4 oColor = getInputColor(texcoord);
// Hide pixels in the transition zone.
float random = simplex2DFractal(texcoord * uSize / 20.0) * 1.5 - 0.25;
if (progress > random) {
oColor.a *= max(0.0, 1.0 - (progress - random) * 10.0);
}
// These are pretty useful for understanding how this works.
// oColor = vec4(progress, 0.0, 0.0, 1.0);
// oColor = vec4(random, 0.0, 0.0, 1.0);
setOutputColor(oColor);
}
+3 -3
View File
@@ -27,9 +27,9 @@ void main() {
vec4 oColor = getInputColor(texcoord);
// Hide selected pixels based on some random noise.
float random = simplex2DFractal(texcoord * uNoise * uSize / 1000.0);
if (random * 1.5 - 0.25 < progress) {
oColor.a = 0.0;
float random = simplex2DFractal(texcoord * uNoise * uSize / 1000.0) * 1.5 - 0.25;
if (progress > random) {
oColor.a *= max(0.0, 1.0 - (progress - random) * 20.0);
}
setOutputColor(oColor);
+143
View File
@@ -0,0 +1,143 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface domain="burn-my-windows">
<object class="GtkAdjustment" id="pixel-wipe-animation-time">
<property name="upper">5000</property>
<property name="lower">100</property>
<property name="step-increment">1</property>
<property name="page-increment">100</property>
</object>
<object class="GtkAdjustment" id="pixel-wipe-direction">
<property name="upper">360</property>
<property name="lower">0</property>
<property name="step-increment">1</property>
<property name="page-increment">10</property>
</object>
<object class="GtkAdjustment" id="pixel-wipe-pixel-size">
<property name="upper">50</property>
<property name="lower">1</property>
<property name="step-increment">1</property>
<property name="page-increment">10</property>
</object>
<object class="GtkBox" id="pixel-wipe-prefs">
<property name="orientation">vertical</property>
<child>
<object class="GtkFrame">
<child>
<object class="GtkListBox">
<property name="selection-mode">none</property>
<style>
<class name="rich-list" />
</style>
<child>
<object class="GtkListBoxRow">
<property name="margin-start">10</property>
<property name="margin-end">10</property>
<property name="margin-top">10</property>
<property name="margin-bottom">10</property>
<property name="activatable">0</property>
<child>
<object class="GtkBox">
<property name="spacing">8</property>
<child>
<object class="GtkLabel">
<property name="label" translatable="yes">Animation Time [ms]</property>
<property name="xalign">0</property>
<property name="halign">start</property>
<property name="valign">center</property>
<property name="hexpand">1</property>
</object>
</child>
<child>
<object class="GtkScale">
<property name="halign">end</property>
<property name="valign">center</property>
<property name="draw-value">1</property>
<property name="digits">0</property>
<property name="value-pos">left</property>
<property name="width-request">300</property>
<property name="adjustment">pixel-wipe-animation-time</property>
</object>
</child>
<child>
<object class="GtkButton" id="reset-pixel-wipe-animation-time">
<child>
<object class="GtkImage">
<property name="icon-name">edit-clear-symbolic</property>
<property name="icon-size">1</property>
</object>
</child>
<property name="tooltip-text" translatable="yes">Reset to Default Value</property>
<style>
<class name="flat" />
</style>
</object>
</child>
</object>
</child>
</object>
</child>
<child>
<object class="GtkListBoxRow">
<property name="margin-start">10</property>
<property name="margin-end">10</property>
<property name="margin-top">10</property>
<property name="margin-bottom">10</property>
<property name="activatable">0</property>
<child>
<object class="GtkBox">
<property name="spacing">8</property>
<child>
<object class="GtkLabel">
<property name="label" translatable="yes">Pixel Size</property>
<property name="xalign">0</property>
<property name="halign">start</property>
<property name="valign">center</property>
<property name="hexpand">1</property>
</object>
</child>
<child>
<object class="GtkScale">
<property name="halign">end</property>
<property name="valign">center</property>
<property name="draw-value">1</property>
<property name="digits">0</property>
<property name="value-pos">left</property>
<property name="width-request">300</property>
<property name="adjustment">pixel-wipe-pixel-size</property>
</object>
</child>
<child>
<object class="GtkButton" id="reset-pixel-wipe-pixel-size">
<child>
<object class="GtkImage">
<property name="icon-name">edit-clear-symbolic</property>
<property name="icon-size">1</property>
</object>
</child>
<property name="tooltip-text" translatable="yes">Reset to Default Value</property>
<style>
<class name="flat" />
</style>
</object>
</child>
</object>
</child>
</object>
</child>
</object>
</child>
</object>
</child>
</object>
</interface>
+117
View File
@@ -0,0 +1,117 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface domain="burn-my-windows">
<object class="GtkBox" id="pixel-wipe-prefs">
<property name="orientation">vertical</property>
<child>
<object class="GtkFrame">
<child>
<object class="GtkListBox">
<property name="selection-mode">none</property>
<property name="show-separators">1</property>
<style>
<class name="rich-list" />
</style>
<child>
<object class="GtkListBoxRow">
<property name="activatable">0</property>
<child>
<object class="GtkBox">
<child>
<object class="GtkLabel">
<property name="label" translatable="yes">Animation Time [ms]</property>
<property name="xalign">0</property>
<property name="halign">start</property>
<property name="valign">center</property>
<property name="hexpand">1</property>
</object>
</child>
<child>
<object class="GtkScale">
<property name="halign">end</property>
<property name="valign">center</property>
<property name="draw-value">1</property>
<property name="digits">0</property>
<property name="value-pos">left</property>
<property name="width-request">300</property>
<property name="adjustment">
<object class="GtkAdjustment" id="pixel-wipe-animation-time">
<property name="upper">5000</property>
<property name="lower">100</property>
<property name="step-increment">1</property>
<property name="page-increment">100</property>
</object>
</property>
</object>
</child>
<child>
<object class="GtkButton" id="reset-pixel-wipe-animation-time">
<property name="icon-name">edit-clear-symbolic</property>
<property name="tooltip-text" translatable="yes">Reset to Default Value</property>
<style>
<class name="flat" />
</style>
</object>
</child>
</object>
</child>
</object>
</child>
<child>
<object class="GtkListBoxRow">
<property name="activatable">0</property>
<child>
<object class="GtkBox">
<child>
<object class="GtkLabel">
<property name="label" translatable="yes">Pixel Size</property>
<property name="xalign">0</property>
<property name="halign">start</property>
<property name="valign">center</property>
<property name="hexpand">1</property>
</object>
</child>
<child>
<object class="GtkScale">
<property name="halign">end</property>
<property name="valign">center</property>
<property name="draw-value">1</property>
<property name="digits">0</property>
<property name="value-pos">left</property>
<property name="width-request">300</property>
<property name="adjustment">
<object class="GtkAdjustment" id="pixel-wipe-pixel-size">
<property name="upper">50</property>
<property name="lower">1</property>
<property name="step-increment">1</property>
<property name="page-increment">10</property>
</object>
</property>
</object>
</child>
<child>
<object class="GtkButton" id="reset-pixel-wipe-pixel-size">
<property name="icon-name">edit-clear-symbolic</property>
<property name="tooltip-text" translatable="yes">Reset to Default Value</property>
<style>
<class name="flat" />
</style>
</object>
</child>
</object>
</child>
</object>
</child>
</object>
</child>
</object>
</child>
</object>
</interface>
@@ -112,13 +112,41 @@
<description>The noise of the effect.</description>
</key>
<key name="pixelate-pixel-size" type="d">
<key name="pixelate-pixel-size" type="i">
<default>10</default>
<summary>Pixelate Pixel Size</summary>
<description>The size of the maximum pixelation.</description>
</key>
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
<!-- Pixel Wipe Options -->
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
<key name="pixel-wipe-close-effect" type="b">
<default>false</default>
<summary>Pixel Wipe Close Effect</summary>
<description>Use the Pixel Wipe effect for window closing.</description>
</key>
<key name="pixel-wipe-open-effect" type="b">
<default>false</default>
<summary>Pixel Wipe Open Effect</summary>
<description>Use the Pixel Wipe effect for window opening.</description>
</key>
<key name="pixel-wipe-animation-time" type="i">
<default>1000</default>
<summary>Pixel Wipe Animation Time</summary>
<description>The time the Pixel Wipe effect takes.</description>
</key>
<key name="pixel-wipe-pixel-size" type="i">
<default>10</default>
<summary>Pixel Wipe Pixel Size</summary>
<description>The size of the maximum pixelation.</description>
</key>
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
<!-- Pixel Wheel Options -->
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
+127
View File
@@ -0,0 +1,127 @@
//////////////////////////////////////////////////////////////////////////////////////////
// ) ( //
// ( /( ( ( ) ( ( ( ( )\ ) ( ( //
// )\()) ))\ )( ( ( )\ ) )\))( )\ ( (()/( ( )\))( ( //
// ((_)\ /((_|()\ )\ ) )\ '(()/( ((_)()((_) )\ ) ((_)))\((_)()\ )\ //
// | |(_|_))( ((_)_(_/( _((_)) )(_)) _(()((_|_)_(_/( _| |((_)(()((_|(_) //
// | '_ \ || | '_| ' \)) | ' \()| || | \ V V / | ' \)) _` / _ \ V V (_-< //
// |_.__/\_,_|_| |_||_| |_|_|_| \_, | \_/\_/|_|_||_|\__,_\___/\_/\_//__/ //
// |__/ //
// Copyright (c) 2021 Simon Schneegans //
// Released under the GPLv3 or later. See LICENSE file for details. //
//////////////////////////////////////////////////////////////////////////////////////////
'use strict';
const GObject = imports.gi.GObject;
const _ = imports.gettext.domain('burn-my-windows').gettext;
const ExtensionUtils = imports.misc.extensionUtils;
const Me = imports.misc.extensionUtils.getCurrentExtension();
const utils = Me.imports.src.utils;
const ShaderFactory = Me.imports.src.ShaderFactory.ShaderFactory;
//////////////////////////////////////////////////////////////////////////////////////////
// This very simple effect pixelates the window texture and hides from left to right //
// (or any other direction). //
//////////////////////////////////////////////////////////////////////////////////////////
// The effect class can be used to get some metadata (like the effect's name or supported
// GNOME Shell versions), to initialize the respective page of the settings dialog, as
// well as to create the actual shader for the effect.
var PixelWipe = class {
// The constructor creates a ShaderFactory which will be used by extension.js to create
// shader instances for this effect. The shaders will be automagically created using the
// GLSL file in resources/shaders/<nick>.glsl. The callback will be called for each
// newly created shader instance.
constructor() {
this.shaderFactory = new ShaderFactory(this.getNick(), (shader) => {
// Store uniform locations of newly created shaders.
shader._uPixelSize = shader.get_uniform_location('uPixelSize');
shader._uStartPos = shader.get_uniform_location('uStartPos');
// Write all uniform values at the start of each animation.
shader.connect('begin-animation', (shader, settings, forOpening, actor) => {
// Because the actor position may change after the begin-animation signal is
// called, we set the uDirection uniform during the update callback.
this._startPointerPos = global.get_pointer();
this._actor = actor;
// clang-format off
shader.set_uniform_float(shader._uPixelSize, 1, [settings.get_int('pixel-wipe-pixel-size')]);
// clang-format on
});
// We set the uDirection uniform during the update callback as the actor position
// may not be set up properly before the begin animation callback.
shader.connect('update-animation', (shader) => {
if (this._startPointerPos) {
const [x, y] = this._startPointerPos;
const [ok, localX, localY] = this._actor.transform_stage_point(x, y);
if (ok) {
let startPos = [
Math.max(0.0, Math.min(1.0, localX / this._actor.width)),
Math.max(0.0, Math.min(1.0, localY / this._actor.height))
];
shader.set_uniform_float(shader._uStartPos, 2, startPos);
}
}
});
// Make sure to drop the reference to the actor.
shader.connect('end-animation', (shader) => {
shader._actor = null;
});
});
}
// ---------------------------------------------------------------------------- metadata
// The effect is available on all GNOME Shell versions supported by this extension.
getMinShellVersion() {
return [3, 36];
}
// This will be called in various places where a unique identifier for this effect is
// required. It should match the prefix of the settings keys which store whether the
// effect is enabled currently (e.g. '*-close-effect'), and its animation time
// (e.g. '*-animation-time').
getNick() {
return 'pixel-wipe';
}
// This will be shown in the sidebar of the preferences dialog as well as in the
// drop-down menus where the user can choose the effect.
getLabel() {
return _('Pixel Wipe');
}
// -------------------------------------------------------------------- API for prefs.js
// This is called by the preferences dialog. It loads the settings page for this effect,
// and binds all properties to the settings.
getPreferences(dialog) {
// Add the settings page to the builder.
dialog.getBuilder().add_from_resource(`/ui/${utils.getGTKString()}/PixelWipe.ui`);
// Bind all properties.
dialog.bindAdjustment('pixel-wipe-animation-time');
dialog.bindAdjustment('pixel-wipe-pixel-size');
// Finally, return the new settings page.
return dialog.getBuilder().get_object('pixel-wipe-prefs');
}
// ---------------------------------------------------------------- API for extension.js
// The getActorScale() is called from extension.js to adjust the actor's size during the
// animation. This is useful if the effect requires drawing something beyond the usual
// bounds of the actor. This only works for GNOME 3.38+.
getActorScale(settings) {
return {x: 1.0, y: 1.0};
}
}
+1 -1
View File
@@ -46,7 +46,7 @@ var Pixelate = class {
shader.connect('begin-animation', (shader, settings) => {
// clang-format off
shader.set_uniform_float(shader._uNoise, 1, [settings.get_double('pixelate-noise')]);
shader.set_uniform_float(shader._uPixelSize, 1, [settings.get_double('pixelate-pixel-size')]);
shader.set_uniform_float(shader._uPixelSize, 1, [settings.get_int('pixelate-pixel-size')]);
// clang-format on
});
});