Merge pull request #510 from Schneegans/feature/random-fire
Random Fire
This commit is contained in:
@@ -9,6 +9,10 @@ SPDX-License-Identifier: CC-BY-4.0
|
|||||||
|
|
||||||
**Release Date:** TBD
|
**Release Date:** TBD
|
||||||
|
|
||||||
|
#### New Features
|
||||||
|
|
||||||
|
- Added an option to choose a random color for the Fire effect each time a window is closed or opened. Thanks to [@jgarza9788](https://github.com/jgarza9788) for this contribution!
|
||||||
|
|
||||||
#### Bug Fixes
|
#### Bug Fixes
|
||||||
|
|
||||||
- Fixed an issue introduced by the GNOME 48 Beta release which caused some effects to break (Broken Glass, Matrix, Paint Brush, Snap of Disintegration, T-Rex Attack).
|
- Fixed an issue introduced by the GNOME 48 Beta release which caused some effects to break (Broken Glass, Matrix, Paint Brush, Snap of Disintegration, T-Rex Attack).
|
||||||
|
|||||||
+26
-19
@@ -17,13 +17,13 @@ SPDX-License-Identifier: GPL-3.0-or-later
|
|||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QGridLayout" name="gridLayout">
|
<layout class="QGridLayout" name="gridLayout">
|
||||||
<item row="4" column="0">
|
<item row="0" column="0">
|
||||||
<widget class="QLabel" name="label_4">
|
<widget class="QLabel" name="label">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Gradient</string>
|
<string>Animation Time [ms]</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="alignment">
|
<property name="alignment">
|
||||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
<set>Qt::AlignmentFlag::AlignRight|Qt::AlignmentFlag::AlignTrailing|Qt::AlignmentFlag::AlignVCenter</set>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
@@ -40,6 +40,16 @@ SPDX-License-Identifier: GPL-3.0-or-later
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item row="1" column="0">
|
||||||
|
<widget class="QLabel" name="label_3">
|
||||||
|
<property name="text">
|
||||||
|
<string>Scale</string>
|
||||||
|
</property>
|
||||||
|
<property name="alignment">
|
||||||
|
<set>Qt::AlignmentFlag::AlignRight|Qt::AlignmentFlag::AlignTrailing|Qt::AlignmentFlag::AlignVCenter</set>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
<item row="1" column="1">
|
<item row="1" column="1">
|
||||||
<widget class="QDoubleSpinBox" name="kcfg_Scale">
|
<widget class="QDoubleSpinBox" name="kcfg_Scale">
|
||||||
<property name="minimum">
|
<property name="minimum">
|
||||||
@@ -50,17 +60,17 @@ SPDX-License-Identifier: GPL-3.0-or-later
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="3" column="0">
|
<item row="2" column="0">
|
||||||
<widget class="QLabel" name="label_2">
|
<widget class="QLabel" name="label_2">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Speed</string>
|
<string>Speed</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="alignment">
|
<property name="alignment">
|
||||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
<set>Qt::AlignmentFlag::AlignRight|Qt::AlignmentFlag::AlignTrailing|Qt::AlignmentFlag::AlignVCenter</set>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="3" column="1">
|
<item row="2" column="1">
|
||||||
<widget class="QDoubleSpinBox" name="kcfg_MovementSpeed">
|
<widget class="QDoubleSpinBox" name="kcfg_MovementSpeed">
|
||||||
<property name="minimum">
|
<property name="minimum">
|
||||||
<double>-5.000000000000000</double>
|
<double>-5.000000000000000</double>
|
||||||
@@ -70,17 +80,17 @@ SPDX-License-Identifier: GPL-3.0-or-later
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="1" column="0">
|
<item row="3" column="0">
|
||||||
<widget class="QLabel" name="label_3">
|
<widget class="QLabel" name="label_4">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Scale</string>
|
<string>Gradient</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="alignment">
|
<property name="alignment">
|
||||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
<set>Qt::AlignmentFlag::AlignRight|Qt::AlignmentFlag::AlignTrailing|Qt::AlignmentFlag::AlignVCenter</set>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="4" column="1">
|
<item row="3" column="1">
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||||
<item>
|
<item>
|
||||||
<widget class="KColorButton" name="kcfg_Gradient1">
|
<widget class="KColorButton" name="kcfg_Gradient1">
|
||||||
@@ -119,20 +129,17 @@ SPDX-License-Identifier: GPL-3.0-or-later
|
|||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
<item row="7" column="1">
|
<item row="4" column="1">
|
||||||
<widget class="QCheckBox" name="kcfg_3DNoise">
|
<widget class="QCheckBox" name="kcfg_3DNoise">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>3D Noise</string>
|
<string>3D Noise</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="0" column="0">
|
<item row="5" column="1">
|
||||||
<widget class="QLabel" name="label">
|
<widget class="QCheckBox" name="kcfg_RandomColor">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Animation Time [ms]</string>
|
<string>Use Random Color</string>
|
||||||
</property>
|
|
||||||
<property name="alignment">
|
|
||||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
|||||||
@@ -36,5 +36,8 @@ SPDX-License-Identifier: GPL-3.0-or-later
|
|||||||
<entry name="3DNoise" type="Bool">
|
<entry name="3DNoise" type="Bool">
|
||||||
<default>false</default>
|
<default>false</default>
|
||||||
</entry>
|
</entry>
|
||||||
|
<entry name="RandomColor" type="Bool">
|
||||||
|
<default>false</default>
|
||||||
|
</entry>
|
||||||
</group>
|
</group>
|
||||||
</kcfg>
|
</kcfg>
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
// SPDX-FileCopyrightText: Simon Schneegans <code@simonschneegans.de>
|
||||||
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
// This part is automatically included in the effect's source during the build process.
|
||||||
|
// The code below is called whenever a window is closed or opened.
|
||||||
|
|
||||||
|
let seed = Math.random();
|
||||||
|
effect.setUniform(this.shader, 'uSeed', seed);
|
||||||
@@ -8,6 +8,8 @@
|
|||||||
effect.setUniform(this.shader, 'uDuration', this.duration * 0.001);
|
effect.setUniform(this.shader, 'uDuration', this.duration * 0.001);
|
||||||
effect.setUniform(this.shader, 'u3DNoise',
|
effect.setUniform(this.shader, 'u3DNoise',
|
||||||
effect.readConfig('3DNoise', true) ? 1.0 : 0.0);
|
effect.readConfig('3DNoise', true) ? 1.0 : 0.0);
|
||||||
|
effect.setUniform(this.shader, 'uRandomColor',
|
||||||
|
effect.readConfig('RandomColor', true) ? 1.0 : 0.0);
|
||||||
effect.setUniform(this.shader, 'uScale', effect.readConfig('Scale', 1.0));
|
effect.setUniform(this.shader, 'uScale', effect.readConfig('Scale', 1.0));
|
||||||
effect.setUniform(this.shader, 'uMovementSpeed', effect.readConfig('MovementSpeed', 1.0));
|
effect.setUniform(this.shader, 'uMovementSpeed', effect.readConfig('MovementSpeed', 1.0));
|
||||||
effect.setUniform(this.shader, 'uGradient1', this.readRGBAConfig('Gradient1'));
|
effect.setUniform(this.shader, 'uGradient1', this.readRGBAConfig('Gradient1'));
|
||||||
|
|||||||
@@ -22,6 +22,8 @@ uniform vec4 uGradient2;
|
|||||||
uniform vec4 uGradient3;
|
uniform vec4 uGradient3;
|
||||||
uniform vec4 uGradient4;
|
uniform vec4 uGradient4;
|
||||||
uniform vec4 uGradient5;
|
uniform vec4 uGradient5;
|
||||||
|
uniform bool uRandomColor;
|
||||||
|
uniform float uSeed;
|
||||||
|
|
||||||
// These may be configurable in the future.
|
// These may be configurable in the future.
|
||||||
const float EDGE_FADE = 70.0;
|
const float EDGE_FADE = 70.0;
|
||||||
@@ -29,7 +31,7 @@ const float FADE_WIDTH = 0.1;
|
|||||||
const float HIDE_TIME = 0.4;
|
const float HIDE_TIME = 0.4;
|
||||||
|
|
||||||
// This maps the input value from [0..1] to a color from the gradient.
|
// This maps the input value from [0..1] to a color from the gradient.
|
||||||
vec4 getFireColor(float v) {
|
vec4 getFireColor(float v, vec4 c0, vec4 c1, vec4 c2, vec4 c3, vec4 c4) {
|
||||||
float steps[5];
|
float steps[5];
|
||||||
steps[0] = 0.0;
|
steps[0] = 0.0;
|
||||||
steps[1] = 0.2;
|
steps[1] = 0.2;
|
||||||
@@ -38,11 +40,11 @@ vec4 getFireColor(float v) {
|
|||||||
steps[4] = 0.8;
|
steps[4] = 0.8;
|
||||||
|
|
||||||
vec4 colors[5];
|
vec4 colors[5];
|
||||||
colors[0] = uGradient1;
|
colors[0] = c0;
|
||||||
colors[1] = uGradient2;
|
colors[1] = c1;
|
||||||
colors[2] = uGradient3;
|
colors[2] = c2;
|
||||||
colors[3] = uGradient4;
|
colors[3] = c3;
|
||||||
colors[4] = uGradient5;
|
colors[4] = c4;
|
||||||
|
|
||||||
if (v < steps[0]) {
|
if (v < steps[0]) {
|
||||||
return colors[0];
|
return colors[0];
|
||||||
@@ -114,7 +116,25 @@ void main() {
|
|||||||
noise *= effectMask.y;
|
noise *= effectMask.y;
|
||||||
|
|
||||||
// Map noise value to color.
|
// Map noise value to color.
|
||||||
vec4 fire = getFireColor(noise);
|
vec4 fire = vec4(0.0);
|
||||||
|
|
||||||
|
if (uRandomColor) {
|
||||||
|
vec3 baseColor0 = offsetHue(vec3(1.0, 0.0, 0.0), hash11(uSeed));
|
||||||
|
vec3 baseColor1 = offsetHue(baseColor0, 0.1);
|
||||||
|
vec3 baseColor2 = offsetHue(baseColor1, 0.1);
|
||||||
|
|
||||||
|
// Hardcoding some alpha values.
|
||||||
|
vec4 c0 = vec4(baseColor0, 0.0);
|
||||||
|
vec4 c1 = vec4(baseColor0, 0.5);
|
||||||
|
vec4 c2 = vec4(baseColor1, 0.8);
|
||||||
|
vec4 c3 = vec4(baseColor1, 0.9);
|
||||||
|
vec4 c4 = vec4(baseColor2, 1.0);
|
||||||
|
|
||||||
|
fire = getFireColor(noise, c0, c1, c2, c3, c4);
|
||||||
|
} else {
|
||||||
|
fire =
|
||||||
|
getFireColor(noise, uGradient1, uGradient2, uGradient3, uGradient4, uGradient5);
|
||||||
|
}
|
||||||
|
|
||||||
// Get the window texture.
|
// Get the window texture.
|
||||||
vec4 oColor = getInputColor(iTexCoord.st);
|
vec4 oColor = getInputColor(iTexCoord.st);
|
||||||
|
|||||||
@@ -147,6 +147,28 @@ SPDX-License-Identifier: GPL-3.0-or-later
|
|||||||
</object>
|
</object>
|
||||||
</child>
|
</child>
|
||||||
|
|
||||||
|
<child>
|
||||||
|
<object class="AdwActionRow">
|
||||||
|
<property name="title" translatable="yes">Use Random Color</property>
|
||||||
|
<property name="activatable-widget">fire-random-color</property>
|
||||||
|
<child>
|
||||||
|
<object class="GtkSwitch" id="fire-random-color">
|
||||||
|
<property name="valign">center</property>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkButton" id="reset-fire-random-color">
|
||||||
|
<property name="icon-name">edit-clear-symbolic</property>
|
||||||
|
<property name="valign">center</property>
|
||||||
|
<property name="tooltip-text" translatable="yes">Reset to Default Value</property>
|
||||||
|
<style>
|
||||||
|
<class name="flat" />
|
||||||
|
</style>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
|
|
||||||
<child>
|
<child>
|
||||||
<object class="AdwActionRow">
|
<object class="AdwActionRow">
|
||||||
<property name="title" translatable="yes">Gradient</property>
|
<property name="title" translatable="yes">Gradient</property>
|
||||||
|
|||||||
@@ -242,6 +242,12 @@ SPDX-License-Identifier: CC0-1.0
|
|||||||
<description>The size of the fire.</description>
|
<description>The size of the fire.</description>
|
||||||
</key>
|
</key>
|
||||||
|
|
||||||
|
<key name="fire-random-color" type="b">
|
||||||
|
<default>false</default>
|
||||||
|
<summary>use a random color for the fire</summary>
|
||||||
|
<description>use a random color of the fire</description>
|
||||||
|
</key>
|
||||||
|
|
||||||
<key name="fire-3d-noise" type="b">
|
<key name="fire-3d-noise" type="b">
|
||||||
<default>false</default>
|
<default>false</default>
|
||||||
<summary>Fire 3D Noise</summary>
|
<summary>Fire 3D Noise</summary>
|
||||||
|
|||||||
@@ -12,6 +12,8 @@
|
|||||||
// SPDX-FileCopyrightText: Simon Schneegans <code@simonschneegans.de>
|
// SPDX-FileCopyrightText: Simon Schneegans <code@simonschneegans.de>
|
||||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
// modified by Justin Garza <JGarza9788@gmail.com>
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
import Gio from 'gi://Gio';
|
import Gio from 'gi://Gio';
|
||||||
@@ -58,6 +60,9 @@ export default class Effect {
|
|||||||
shader._uScale = shader.get_uniform_location('uScale');
|
shader._uScale = shader.get_uniform_location('uScale');
|
||||||
shader._uMovementSpeed = shader.get_uniform_location('uMovementSpeed');
|
shader._uMovementSpeed = shader.get_uniform_location('uMovementSpeed');
|
||||||
|
|
||||||
|
shader._uRandomColor = shader.get_uniform_location('uRandomColor');
|
||||||
|
shader._uSeed = shader.get_uniform_location('uSeed');
|
||||||
|
|
||||||
// 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) => {
|
shader.connect('begin-animation', (shader, settings) => {
|
||||||
for (let i = 1; i <= 5; i++) {
|
for (let i = 1; i <= 5; i++) {
|
||||||
@@ -68,6 +73,8 @@ export default class Effect {
|
|||||||
|
|
||||||
// clang-format off
|
// clang-format off
|
||||||
shader.set_uniform_float(shader._u3DNoise, 1, [settings.get_boolean('fire-3d-noise')]);
|
shader.set_uniform_float(shader._u3DNoise, 1, [settings.get_boolean('fire-3d-noise')]);
|
||||||
|
shader.set_uniform_float(shader._uRandomColor, 1, [settings.get_boolean('fire-random-color')]);
|
||||||
|
shader.set_uniform_float(shader._uSeed, 1, [Math.random()]);
|
||||||
shader.set_uniform_float(shader._uScale, 1, [settings.get_double('fire-scale')]);
|
shader.set_uniform_float(shader._uScale, 1, [settings.get_double('fire-scale')]);
|
||||||
shader.set_uniform_float(shader._uMovementSpeed, 1, [settings.get_double('fire-movement-speed')]);
|
shader.set_uniform_float(shader._uMovementSpeed, 1, [settings.get_double('fire-movement-speed')]);
|
||||||
// clang-format on
|
// clang-format on
|
||||||
@@ -107,6 +114,7 @@ export default class Effect {
|
|||||||
dialog.bindAdjustment('fire-movement-speed');
|
dialog.bindAdjustment('fire-movement-speed');
|
||||||
dialog.bindAdjustment('fire-scale');
|
dialog.bindAdjustment('fire-scale');
|
||||||
dialog.bindSwitch('fire-3d-noise');
|
dialog.bindSwitch('fire-3d-noise');
|
||||||
|
dialog.bindSwitch('fire-random-color');
|
||||||
dialog.bindColorButton('fire-color-1');
|
dialog.bindColorButton('fire-color-1');
|
||||||
dialog.bindColorButton('fire-color-2');
|
dialog.bindColorButton('fire-color-2');
|
||||||
dialog.bindColorButton('fire-color-3');
|
dialog.bindColorButton('fire-color-3');
|
||||||
@@ -129,6 +137,33 @@ export default class Effect {
|
|||||||
// Initialize the fire-preset dropdown.
|
// Initialize the fire-preset dropdown.
|
||||||
Effect._createFirePresets(dialog);
|
Effect._createFirePresets(dialog);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// enables and disables the color buttons
|
||||||
|
function enableDisableColorButtons(dialog, state) {
|
||||||
|
|
||||||
|
for (let i = 1; i <= 5; i++) {
|
||||||
|
dialog.getBuilder().get_object('fire-color-' + i).set_sensitive(!state);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const switchWidget = dialog.getBuilder().get_object('fire-random-color');
|
||||||
|
if (switchWidget) {
|
||||||
|
// Connect to the "state-set" signal to update preferences dynamically based on
|
||||||
|
// the switch state.
|
||||||
|
switchWidget.connect('state-set', (widget, state) => {
|
||||||
|
enableDisableColorButtons(dialog,
|
||||||
|
state); // Update sensitivity when the state changes.
|
||||||
|
});
|
||||||
|
|
||||||
|
// Manually call the update function on startup, using the initial state of the
|
||||||
|
// switch.
|
||||||
|
const initialState =
|
||||||
|
switchWidget.get_active(); // Get the current state of the switch.
|
||||||
|
enableDisableColorButtons(dialog, initialState);
|
||||||
|
} else {
|
||||||
|
// Log an error if the switch widget is not found in the UI.
|
||||||
|
log('Error: \'fire-random-color\' switch widget not found.');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------- API for extension.js
|
// ---------------------------------------------------------------- API for extension.js
|
||||||
|
|||||||
Reference in New Issue
Block a user