🔧 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);
// 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.
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 //
// 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, //
// 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 //
// 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 //
@@ -47,8 +47,12 @@ const utils = Me.imports.src.utils;
var Shader = GObject.registerClass(
{
Signals: {
'begin-animation':
{param_types: [Gio.Settings.$gtype, GObject.TYPE_BOOLEAN, Clutter.Actor.$gtype]},
'begin-animation': {
param_types: [
Gio.Settings.$gtype, GObject.TYPE_BOOLEAN, GObject.TYPE_BOOLEAN,
Clutter.Actor.$gtype
]
},
'update-animation': {param_types: [GObject.TYPE_DOUBLE]},
'end-animation': {}
}
@@ -76,7 +80,7 @@ var Shader = GObject.registerClass(
}
// This is called once each time the shader is used.
beginAnimation(settings, forOpening, duration, actor) {
beginAnimation(settings, forOpening, testMode, duration, actor) {
// Reset progress value.
this._progress = 0;
@@ -90,7 +94,7 @@ var Shader = GObject.registerClass(
this.set_uniform_float(this._uDuration, 1, [duration]);
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.
+1 -4
View File
@@ -44,10 +44,7 @@ var Apparition = class {
shader._uRandomness = shader.get_uniform_location('uRandomness');
// Write all uniform values at the start of each animation.
shader.connect('begin-animation', (shader, settings) => {
// If we are performing an integration tests, we use a fixed seed.
const testMode = settings.get_boolean('test-mode');
shader.connect('begin-animation', (shader, settings, forOpening, testMode) => {
// clang-format off
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')]);
+21 -24
View File
@@ -70,34 +70,31 @@ var BrokenGlass = class {
shader._uGravity = shader.get_uniform_location('uGravity');
// And update all uniforms at the start of each animation.
shader.connect('begin-animation', (shader, settings, forOpening, actor) => {
// Usually, the shards fly away from the center of the window.
let epicenterX = 0.5;
let epicenterY = 0.5;
shader.connect(
'begin-animation', (shader, settings, forOpening, testMode, actor) => {
// Usually, the shards fly away from the center of the window.
let epicenterX = 0.5;
let epicenterY = 0.5;
// However, if this option is set, we use the mouse pointer position.
if (!forOpening && settings.get_boolean('broken-glass-use-pointer')) {
const [x, y] = global.get_pointer();
const [ok, localX, localY] = actor.transform_stage_point(x, y);
// However, if this option is set, we use the mouse pointer position.
if (!forOpening && settings.get_boolean('broken-glass-use-pointer')) {
const [x, y] = global.get_pointer();
const [ok, localX, localY] = actor.transform_stage_point(x, y);
if (ok) {
epicenterX = localX / actor.width;
epicenterY = localY / actor.height;
if (ok) {
epicenterX = localX / actor.width;
epicenterY = localY / actor.height;
}
}
}
// If we are currently performing integration test, the animation uses a fixed
// seed.
const testMode = settings.get_boolean('test-mode');
// clang-format off
shader.set_uniform_float(shader._uSeed, 2, [testMode ? 0 : Math.random(), testMode ? 0 : Math.random()]);
shader.set_uniform_float(shader._uEpicenter, 2, [epicenterX, epicenterY]);
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
});
// clang-format off
shader.set_uniform_float(shader._uSeed, 2, [testMode ? 0 : Math.random(), testMode ? 0 : Math.random()]);
shader.set_uniform_float(shader._uEpicenter, 2, [epicenterX, epicenterY]);
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
// 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');
// Write all uniform values at the start of each animation.
shader.connect('begin-animation', (shader, settings, forOpening, actor) => {
// For this effect, we scale the actor vertically so that it covers the entire
// 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);
shader.connect(
'begin-animation', (shader, settings, forOpening, testMode, actor) => {
// For this effect, we scale the actor vertically so that it covers the entire
// 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
// test images as the animation has passed the center of the window already. To
// fix this, we set the actor scale to a fixed low value when performing tests.
const testMode = settings.get_boolean('test-mode');
// clang-format off
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._uVerticalScale, 1, [testMode ? 150.0 : settings.get_double('doom-vertical-scale')]);
shader.set_uniform_float(shader._uPixelSize, 1, [settings.get_int('doom-pixel-size')]);
// clang-format on
});
// If we are currently performing integration test, nothing will be visible in
// the test images as the animation has passed the center of the window already.
// To fix this, we set the actor scale to a fixed low value when performing
// tests.
// clang-format off
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._uVerticalScale, 1, [testMode ? 150.0 : settings.get_double('doom-vertical-scale')]);
shader.set_uniform_float(shader._uPixelSize, 1, [settings.get_int('doom-pixel-size')]);
// clang-format on
});
});
}
+1 -4
View File
@@ -51,12 +51,9 @@ var Glitch = class {
shader._uSpeed = shader.get_uniform_location('uSpeed');
// 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];
// If we are performing an integration tests, we use a fixed seed.
const testMode = settings.get_boolean('test-mode');
// clang-format off
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]);
+1 -5
View File
@@ -53,7 +53,7 @@ var Hexagon = class {
shader._uLineColor = shader.get_uniform_location('uLineColor');
// 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
// code below.
const gc =
@@ -61,10 +61,6 @@ var Hexagon = class {
const lc =
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
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()]);
+27 -27
View File
@@ -51,39 +51,39 @@ var Incinerate = class {
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) => {
// If we are currently performing integration test, the animation uses a fixed
// seed.
const testMode = settings.get_boolean('test-mode');
let seed = [testMode ? 0 : Math.random(), testMode ? 0 : Math.random()];
shader.connect(
'begin-animation', (shader, settings, forOpening, testMode, actor) => {
// If we are currently performing integration test, the animation uses a fixed
// seed.
let seed = [testMode ? 0 : Math.random(), testMode ? 0 : Math.random()];
// 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
// uStartPos uniform during the update callback.
if (settings.get_boolean('incinerate-use-pointer')) {
this._startPointerPos = global.get_pointer();
this._actor = 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
// uStartPos uniform during the update callback.
if (settings.get_boolean('incinerate-use-pointer')) {
this._startPointerPos = global.get_pointer();
this._actor = actor;
} else {
// Else, a random position along the window boundary is used as start position
// for the incinerate effect.
let startPos = seed[0] > seed[1] ? [seed[0], Math.floor(seed[1] + 0.5)] :
[Math.floor(seed[0] + 0.5), seed[1]];
} else {
// Else, a random position along the window boundary is used as start position
// for the incinerate effect.
let startPos = seed[0] > seed[1] ? [seed[0], Math.floor(seed[1] + 0.5)] :
[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
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._uScale, 1, [settings.get_double('incinerate-scale')]);
shader.set_uniform_float(shader._uTurbulence, 1, [settings.get_double('incinerate-turbulence')]);
// clang-format on
});
// clang-format off
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._uScale, 1, [settings.get_double('incinerate-scale')]);
shader.set_uniform_float(shader._uTurbulence, 1, [settings.get_double('incinerate-turbulence')]);
// clang-format on
});
// 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
+1 -4
View File
@@ -52,12 +52,9 @@ var Portal = class {
shader._uWhirling = shader.get_uniform_location('uWhirling');
// 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];
// If we are performing an integration tests, we use a fixed seed.
const testMode = settings.get_boolean('test-mode');
// clang-format off
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]);
+1 -5
View File
@@ -63,14 +63,10 @@ var SnapOfDisintegration = class {
shader._uDustScale = shader.get_uniform_location('uDustScale');
// 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.
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
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()]);
+1 -5
View File
@@ -61,13 +61,9 @@ var TRexAttack = class {
shader._uWarpIntensity = shader.get_uniform_location('uWarpIntensity');
// 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];
// If we are currently performing integration test, the animation uses a fixed
// seed.
const testMode = settings.get_boolean('test-mode');
// 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._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');
// 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];
// If we are performing an integration tests, we use a fixed seed.
const testMode = settings.get_boolean('test-mode');
// clang-format off
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]);
+1 -5
View File
@@ -50,13 +50,9 @@ var Wisps = class {
shader._uScale = shader.get_uniform_location('uScale');
// 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];
// If we are currently performing integration test, the animation uses a fixed
// seed.
const testMode = settings.get_boolean('test-mode');
// clang-format off
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]);