🔧 Pass testMode flag to shaders

This commit is contained in:
Simon Schneegans
2023-01-29 20:41:40 +01:00
parent 96d098daba
commit 72f9c8eefc
13 changed files with 83 additions and 109 deletions
+2 -1
View File
@@ -521,7 +521,8 @@ class Extension {
actor.add_effect_with_name('burn-my-windows-effect', shader); actor.add_effect_with_name('burn-my-windows-effect', shader);
// Set one-time uniforms. // Set one-time uniforms.
shader.beginAnimation(this._settings, forOpening, duration * 0.001, actor); shader.beginAnimation(profile.settings, forOpening, testMode, duration * 0.001,
actor);
// Set other uniforms each frame. // Set other uniforms each frame.
transition.connect('new-frame', (t) => { transition.connect('new-frame', (t) => {
+9 -5
View File
@@ -29,7 +29,7 @@ const utils = Me.imports.src.utils;
// main benefit when compared to Clutter.ShaderEffect is that setting uniforms of types // // main benefit when compared to Clutter.ShaderEffect is that setting uniforms of types //
// vec2, vec3 or vec4 is supported via the API (with Clutter.ShaderEffect the GJS // // vec2, vec3 or vec4 is supported via the API (with Clutter.ShaderEffect the GJS //
// binding does not work properly). However, there are two drawbacks: On the one hand, // // binding does not work properly). However, there are two drawbacks: On the one hand, //
// the shader source code is cached statically - this mean if we want to have a // // the shader source code is cached statically - this means if we want to have a //
// different shader, we have to derive a new class. Therefore, each effect has to // // different shader, we have to derive a new class. Therefore, each effect has to //
// derive its own class from the class below. This is encapsulated in the // // derive its own class from the class below. This is encapsulated in the //
// ShaderFactory, however it is some really awkward code. The other drawback is the // // ShaderFactory, however it is some really awkward code. The other drawback is the //
@@ -47,8 +47,12 @@ const utils = Me.imports.src.utils;
var Shader = GObject.registerClass( var Shader = GObject.registerClass(
{ {
Signals: { Signals: {
'begin-animation': 'begin-animation': {
{param_types: [Gio.Settings.$gtype, GObject.TYPE_BOOLEAN, Clutter.Actor.$gtype]}, param_types: [
Gio.Settings.$gtype, GObject.TYPE_BOOLEAN, GObject.TYPE_BOOLEAN,
Clutter.Actor.$gtype
]
},
'update-animation': {param_types: [GObject.TYPE_DOUBLE]}, 'update-animation': {param_types: [GObject.TYPE_DOUBLE]},
'end-animation': {} 'end-animation': {}
} }
@@ -76,7 +80,7 @@ var Shader = GObject.registerClass(
} }
// This is called once each time the shader is used. // This is called once each time the shader is used.
beginAnimation(settings, forOpening, duration, actor) { beginAnimation(settings, forOpening, testMode, duration, actor) {
// Reset progress value. // Reset progress value.
this._progress = 0; this._progress = 0;
@@ -90,7 +94,7 @@ var Shader = GObject.registerClass(
this.set_uniform_float(this._uDuration, 1, [duration]); this.set_uniform_float(this._uDuration, 1, [duration]);
this.set_uniform_float(this._uSize, 2, [actor.width, actor.height]); this.set_uniform_float(this._uSize, 2, [actor.width, actor.height]);
this.emit('begin-animation', settings, forOpening, actor); this.emit('begin-animation', settings, forOpening, testMode, actor);
} }
// This is called at each frame during the animation. // This is called at each frame during the animation.
+1 -4
View File
@@ -44,10 +44,7 @@ var Apparition = class {
shader._uRandomness = shader.get_uniform_location('uRandomness'); shader._uRandomness = shader.get_uniform_location('uRandomness');
// Write all uniform values at the start of each animation. // Write all uniform values at the start of each animation.
shader.connect('begin-animation', (shader, settings) => { shader.connect('begin-animation', (shader, settings, forOpening, testMode) => {
// If we are performing an integration tests, we use a fixed seed.
const testMode = settings.get_boolean('test-mode');
// clang-format off // clang-format off
shader.set_uniform_float(shader._uSeed, 2, [testMode ? 0 : Math.random(), testMode ? 0 : Math.random()]); shader.set_uniform_float(shader._uSeed, 2, [testMode ? 0 : Math.random(), testMode ? 0 : Math.random()]);
shader.set_uniform_float(shader._uShake, 1, [settings.get_double('apparition-shake-intensity')]); shader.set_uniform_float(shader._uShake, 1, [settings.get_double('apparition-shake-intensity')]);
+21 -24
View File
@@ -70,34 +70,31 @@ var BrokenGlass = class {
shader._uGravity = shader.get_uniform_location('uGravity'); shader._uGravity = shader.get_uniform_location('uGravity');
// And update all uniforms at the start of each animation. // And update all uniforms at the start of each animation.
shader.connect('begin-animation', (shader, settings, forOpening, actor) => { shader.connect(
// Usually, the shards fly away from the center of the window. 'begin-animation', (shader, settings, forOpening, testMode, actor) => {
let epicenterX = 0.5; // Usually, the shards fly away from the center of the window.
let epicenterY = 0.5; let epicenterX = 0.5;
let epicenterY = 0.5;
// However, if this option is set, we use the mouse pointer position. // However, if this option is set, we use the mouse pointer position.
if (!forOpening && settings.get_boolean('broken-glass-use-pointer')) { if (!forOpening && settings.get_boolean('broken-glass-use-pointer')) {
const [x, y] = global.get_pointer(); const [x, y] = global.get_pointer();
const [ok, localX, localY] = actor.transform_stage_point(x, y); const [ok, localX, localY] = actor.transform_stage_point(x, y);
if (ok) { if (ok) {
epicenterX = localX / actor.width; epicenterX = localX / actor.width;
epicenterY = localY / actor.height; epicenterY = localY / actor.height;
}
} }
}
// If we are currently performing integration test, the animation uses a fixed // clang-format off
// seed. shader.set_uniform_float(shader._uSeed, 2, [testMode ? 0 : Math.random(), testMode ? 0 : Math.random()]);
const testMode = settings.get_boolean('test-mode'); shader.set_uniform_float(shader._uEpicenter, 2, [epicenterX, epicenterY]);
shader.set_uniform_float(shader._uShardScale, 1, [settings.get_double('broken-glass-scale')]);
// clang-format off shader.set_uniform_float(shader._uBlowForce, 1, [settings.get_double('broken-glass-blow-force')]);
shader.set_uniform_float(shader._uSeed, 2, [testMode ? 0 : Math.random(), testMode ? 0 : Math.random()]); shader.set_uniform_float(shader._uGravity, 1, [settings.get_double('broken-glass-gravity')]);
shader.set_uniform_float(shader._uEpicenter, 2, [epicenterX, epicenterY]); // clang-format on
shader.set_uniform_float(shader._uShardScale, 1, [settings.get_double('broken-glass-scale')]); });
shader.set_uniform_float(shader._uBlowForce, 1, [settings.get_double('broken-glass-blow-force')]);
shader.set_uniform_float(shader._uGravity, 1, [settings.get_double('broken-glass-gravity')]);
// clang-format on
});
// This is required to bind the shard texture for drawing. Sadly, this seems to be // This is required to bind the shard texture for drawing. Sadly, this seems to be
// impossible under GNOME 3.3x as this.get_pipeline() is not available. It was // impossible under GNOME 3.3x as this.get_pipeline() is not available. It was
+16 -16
View File
@@ -46,23 +46,23 @@ var Doom = class {
shader._uPixelSize = shader.get_uniform_location('uPixelSize'); shader._uPixelSize = shader.get_uniform_location('uPixelSize');
// Write all uniform values at the start of each animation. // Write all uniform values at the start of each animation.
shader.connect('begin-animation', (shader, settings, forOpening, actor) => { shader.connect(
// For this effect, we scale the actor vertically so that it covers the entire 'begin-animation', (shader, settings, forOpening, testMode, actor) => {
// screen. This ensures that the melted window will not be cut off. // For this effect, we scale the actor vertically so that it covers the entire
let actorScale = 2.0 * Math.max(1.0, global.stage.height / actor.height); // screen. This ensures that the melted window will not be cut off.
let actorScale = 2.0 * Math.max(1.0, global.stage.height / actor.height);
// If we are currently performing integration test, nothing will be visible in the // If we are currently performing integration test, nothing will be visible in
// test images as the animation has passed the center of the window already. To // the test images as the animation has passed the center of the window already.
// fix this, we set the actor scale to a fixed low value when performing tests. // To fix this, we set the actor scale to a fixed low value when performing
const testMode = settings.get_boolean('test-mode'); // tests.
// clang-format off
// clang-format off shader.set_uniform_float(shader._uActorScale, 1, [testMode ? 1.0 : actorScale]);
shader.set_uniform_float(shader._uActorScale, 1, [testMode ? 1.0 : actorScale]); shader.set_uniform_float(shader._uHorizontalScale, 1, [testMode ? 50.0 :settings.get_double('doom-horizontal-scale')]);
shader.set_uniform_float(shader._uHorizontalScale, 1, [testMode ? 50.0 :settings.get_double('doom-horizontal-scale')]); shader.set_uniform_float(shader._uVerticalScale, 1, [testMode ? 150.0 : settings.get_double('doom-vertical-scale')]);
shader.set_uniform_float(shader._uVerticalScale, 1, [testMode ? 150.0 : settings.get_double('doom-vertical-scale')]); shader.set_uniform_float(shader._uPixelSize, 1, [settings.get_int('doom-pixel-size')]);
shader.set_uniform_float(shader._uPixelSize, 1, [settings.get_int('doom-pixel-size')]); // clang-format on
// clang-format on });
});
}); });
} }
+1 -4
View File
@@ -51,12 +51,9 @@ var Glitch = class {
shader._uSpeed = shader.get_uniform_location('uSpeed'); shader._uSpeed = shader.get_uniform_location('uSpeed');
// Write all uniform values at the start of each animation. // Write all uniform values at the start of each animation.
shader.connect('begin-animation', (shader, settings) => { shader.connect('begin-animation', (shader, settings, forOpening, testMode) => {
const c = Clutter.Color.from_string(settings.get_string('glitch-color'))[1]; const c = Clutter.Color.from_string(settings.get_string('glitch-color'))[1];
// If we are performing an integration tests, we use a fixed seed.
const testMode = settings.get_boolean('test-mode');
// clang-format off // clang-format off
shader.set_uniform_float(shader._uSeed, 1, [testMode ? 0 : Math.random()]); shader.set_uniform_float(shader._uSeed, 1, [testMode ? 0 : Math.random()]);
shader.set_uniform_float(shader._uColor, 4, [c.red / 255, c.green / 255, c.blue / 255, c.alpha / 255]); shader.set_uniform_float(shader._uColor, 4, [c.red / 255, c.green / 255, c.blue / 255, c.alpha / 255]);
+1 -5
View File
@@ -53,7 +53,7 @@ var Hexagon = class {
shader._uLineColor = shader.get_uniform_location('uLineColor'); shader._uLineColor = shader.get_uniform_location('uLineColor');
// Write all uniform values at the start of each animation. // Write all uniform values at the start of each animation.
shader.connect('begin-animation', (shader, settings) => { shader.connect('begin-animation', (shader, settings, forOpening, testMode) => {
// Get the two configurable colors. They are directly injected into the shader // Get the two configurable colors. They are directly injected into the shader
// code below. // code below.
const gc = const gc =
@@ -61,10 +61,6 @@ var Hexagon = class {
const lc = const lc =
Clutter.Color.from_string(settings.get_string('hexagon-line-color'))[1]; Clutter.Color.from_string(settings.get_string('hexagon-line-color'))[1];
// If we are currently performing integration test, the animation uses a fixed
// seed.
const testMode = settings.get_boolean('test-mode');
// clang-format off // clang-format off
shader.set_uniform_float(shader._uAdditiveBlending, 1, [settings.get_boolean('hexagon-additive-blending')]); shader.set_uniform_float(shader._uAdditiveBlending, 1, [settings.get_boolean('hexagon-additive-blending')]);
shader.set_uniform_float(shader._uSeed, 2, [testMode ? 0 : Math.random(), testMode ? 0 : Math.random()]); shader.set_uniform_float(shader._uSeed, 2, [testMode ? 0 : Math.random(), testMode ? 0 : Math.random()]);
+27 -27
View File
@@ -51,39 +51,39 @@ var Incinerate = class {
shader._uStartPos = shader.get_uniform_location('uStartPos'); shader._uStartPos = shader.get_uniform_location('uStartPos');
// Write all uniform values at the start of each animation. // Write all uniform values at the start of each animation.
shader.connect('begin-animation', (shader, settings, forOpening, actor) => { shader.connect(
// If we are currently performing integration test, the animation uses a fixed 'begin-animation', (shader, settings, forOpening, testMode, actor) => {
// seed. // If we are currently performing integration test, the animation uses a fixed
const testMode = settings.get_boolean('test-mode'); // seed.
let seed = [testMode ? 0 : Math.random(), testMode ? 0 : Math.random()]; let seed = [testMode ? 0 : Math.random(), testMode ? 0 : Math.random()];
// If this option is set, we use the mouse pointer position. Because the actor // If this option is set, we use the mouse pointer position. Because the actor
// position may change after the begin-animation signal is called, we set the // position may change after the begin-animation signal is called, we set the
// uStartPos uniform during the update callback. // uStartPos uniform during the update callback.
if (settings.get_boolean('incinerate-use-pointer')) { if (settings.get_boolean('incinerate-use-pointer')) {
this._startPointerPos = global.get_pointer(); this._startPointerPos = global.get_pointer();
this._actor = actor; this._actor = actor;
} else { } else {
// Else, a random position along the window boundary is used as start position // Else, a random position along the window boundary is used as start position
// for the incinerate effect. // for the incinerate effect.
let startPos = seed[0] > seed[1] ? [seed[0], Math.floor(seed[1] + 0.5)] : let startPos = seed[0] > seed[1] ? [seed[0], Math.floor(seed[1] + 0.5)] :
[Math.floor(seed[0] + 0.5), seed[1]]; [Math.floor(seed[0] + 0.5), seed[1]];
shader.set_uniform_float(shader._uStartPos, 2, startPos); shader.set_uniform_float(shader._uStartPos, 2, startPos);
this._startPointerPos = null; this._startPointerPos = null;
} }
const c = Clutter.Color.from_string(settings.get_string('incinerate-color'))[1]; const c = Clutter.Color.from_string(settings.get_string('incinerate-color'))[1];
// clang-format off // clang-format off
shader.set_uniform_float(shader._uSeed, 2, seed); shader.set_uniform_float(shader._uSeed, 2, seed);
shader.set_uniform_float(shader._uColor, 3, [c.red / 255, c.green / 255, c.blue / 255]); shader.set_uniform_float(shader._uColor, 3, [c.red / 255, c.green / 255, c.blue / 255]);
shader.set_uniform_float(shader._uScale, 1, [settings.get_double('incinerate-scale')]); shader.set_uniform_float(shader._uScale, 1, [settings.get_double('incinerate-scale')]);
shader.set_uniform_float(shader._uTurbulence, 1, [settings.get_double('incinerate-turbulence')]); shader.set_uniform_float(shader._uTurbulence, 1, [settings.get_double('incinerate-turbulence')]);
// clang-format on // clang-format on
}); });
// If the mouse pointer position is used as start position, we set the uStartPos // If the mouse pointer position is used as start position, we set the uStartPos
// uniform during the update callback as the actor position may not be set up // uniform during the update callback as the actor position may not be set up
+1 -4
View File
@@ -52,12 +52,9 @@ var Portal = class {
shader._uWhirling = shader.get_uniform_location('uWhirling'); shader._uWhirling = shader.get_uniform_location('uWhirling');
// Write all uniform values at the start of each animation. // Write all uniform values at the start of each animation.
shader.connect('begin-animation', (shader, settings) => { shader.connect('begin-animation', (shader, settings, forOpening, testMode) => {
const c = Clutter.Color.from_string(settings.get_string('portal-color'))[1]; const c = Clutter.Color.from_string(settings.get_string('portal-color'))[1];
// If we are performing an integration tests, we use a fixed seed.
const testMode = settings.get_boolean('test-mode');
// clang-format off // clang-format off
shader.set_uniform_float(shader._uSeed, 2, [testMode ? 0 : Math.random(), testMode ? 0 : Math.random()]); shader.set_uniform_float(shader._uSeed, 2, [testMode ? 0 : Math.random(), testMode ? 0 : Math.random()]);
shader.set_uniform_float(shader._uColor, 3, [c.red / 255, c.green / 255, c.blue / 255]); shader.set_uniform_float(shader._uColor, 3, [c.red / 255, c.green / 255, c.blue / 255]);
+1 -5
View File
@@ -63,14 +63,10 @@ var SnapOfDisintegration = class {
shader._uDustScale = shader.get_uniform_location('uDustScale'); shader._uDustScale = shader.get_uniform_location('uDustScale');
// Write all uniform values at the start of each animation. // Write all uniform values at the start of each animation.
shader.connect('begin-animation', (shader, settings) => { shader.connect('begin-animation', (shader, settings, forOpening, testMode) => {
// The dust particles will fade to this color over time. // The dust particles will fade to this color over time.
const c = Clutter.Color.from_string(settings.get_string('snap-color'))[1]; const c = Clutter.Color.from_string(settings.get_string('snap-color'))[1];
// If we are currently performing integration test, the animation uses a fixed
// seed.
const testMode = settings.get_boolean('test-mode');
// clang-format off // clang-format off
shader.set_uniform_float(shader._uDustColor, 4, [c.red / 255, c.green / 255, c.blue / 255, c.alpha / 255]); shader.set_uniform_float(shader._uDustColor, 4, [c.red / 255, c.green / 255, c.blue / 255, c.alpha / 255]);
shader.set_uniform_float(shader._uSeed, 2, [testMode ? 0 : Math.random(), testMode ? 0 : Math.random()]); shader.set_uniform_float(shader._uSeed, 2, [testMode ? 0 : Math.random(), testMode ? 0 : Math.random()]);
+1 -5
View File
@@ -61,13 +61,9 @@ var TRexAttack = class {
shader._uWarpIntensity = shader.get_uniform_location('uWarpIntensity'); shader._uWarpIntensity = shader.get_uniform_location('uWarpIntensity');
// Write all uniform values at the start of each animation. // Write all uniform values at the start of each animation.
shader.connect('begin-animation', (shader, settings) => { shader.connect('begin-animation', (shader, settings, forOpening, testMode) => {
const c = Clutter.Color.from_string(settings.get_string('claw-scratch-color'))[1]; const c = Clutter.Color.from_string(settings.get_string('claw-scratch-color'))[1];
// If we are currently performing integration test, the animation uses a fixed
// seed.
const testMode = settings.get_boolean('test-mode');
// clang-format off // clang-format off
shader.set_uniform_float(shader._uFlashColor, 4, [c.red / 255, c.green / 255, c.blue / 255, c.alpha / 255]); shader.set_uniform_float(shader._uFlashColor, 4, [c.red / 255, c.green / 255, c.blue / 255, c.alpha / 255]);
shader.set_uniform_float(shader._uSeed, 2, [testMode ? 0 : Math.random(), testMode ? 0 : Math.random()]); shader.set_uniform_float(shader._uSeed, 2, [testMode ? 0 : Math.random(), testMode ? 0 : Math.random()]);
+1 -4
View File
@@ -52,12 +52,9 @@ var TVGlitch = class {
shader._uSpeed = shader.get_uniform_location('uSpeed'); shader._uSpeed = shader.get_uniform_location('uSpeed');
// Write all uniform values at the start of each animation. // Write all uniform values at the start of each animation.
shader.connect('begin-animation', (shader, settings) => { shader.connect('begin-animation', (shader, settings, forOpening, testMode) => {
const c = Clutter.Color.from_string(settings.get_string('tv-glitch-color'))[1]; const c = Clutter.Color.from_string(settings.get_string('tv-glitch-color'))[1];
// If we are performing an integration tests, we use a fixed seed.
const testMode = settings.get_boolean('test-mode');
// clang-format off // clang-format off
shader.set_uniform_float(shader._uSeed, 1, [testMode ? 0 : Math.random()]); shader.set_uniform_float(shader._uSeed, 1, [testMode ? 0 : Math.random()]);
shader.set_uniform_float(shader._uColor, 4, [c.red / 255, c.green / 255, c.blue / 255, c.alpha / 255]); shader.set_uniform_float(shader._uColor, 4, [c.red / 255, c.green / 255, c.blue / 255, c.alpha / 255]);
+1 -5
View File
@@ -50,13 +50,9 @@ var Wisps = class {
shader._uScale = shader.get_uniform_location('uScale'); shader._uScale = shader.get_uniform_location('uScale');
// Write all uniform values at the start of each animation. // Write all uniform values at the start of each animation.
shader.connect('begin-animation', (shader, settings) => { shader.connect('begin-animation', (shader, settings, forOpening, testMode) => {
const c = Clutter.Color.from_string(settings.get_string('wisps-color'))[1]; const c = Clutter.Color.from_string(settings.get_string('wisps-color'))[1];
// If we are currently performing integration test, the animation uses a fixed
// seed.
const testMode = settings.get_boolean('test-mode');
// clang-format off // clang-format off
shader.set_uniform_float(shader._uSeed, 2, [testMode ? 0 : Math.random(), testMode ? 0 : Math.random()]); shader.set_uniform_float(shader._uSeed, 2, [testMode ? 0 : Math.random(), testMode ? 0 : Math.random()]);
shader.set_uniform_float(shader._uColor, 3, [c.red / 255, c.green / 255, c.blue / 255]); shader.set_uniform_float(shader._uColor, 3, [c.red / 255, c.green / 255, c.blue / 255]);