🔧 Tweak incinerate effect

This commit is contained in:
Simon Schneegans
2022-06-20 05:37:06 +02:00
parent cc18efd9e0
commit 1a20ee94cd
4 changed files with 46 additions and 104 deletions
+41 -44
View File
@@ -16,20 +16,19 @@
uniform vec2 uSeed;
uniform vec3 uColor;
uniform float uScale;
// uniform float uWidth;
uniform float uTurbulence;
const float SCORCH_WIDTH = 0.1;
const float BURN_WIDTH = 0.02;
const float SMOKE_WIDTH = 0.6;
const float FLAME_WIDTH = 0.1;
vec4 getFireColor(float val) {
return vec4(tritone(val, vec3(0.0), uColor, vec3(1.0)), val);
}
void main() {
float SCORCH_WIDTH = 0.15 * uScale;
float BURN_WIDTH = 0.02 * uScale;
float SMOKE_WIDTH = 0.6 * uScale;
float FLAME_WIDTH = 0.15 * uScale;
float hideThreshold = mix(-SCORCH_WIDTH, 1.0 + SMOKE_WIDTH, uProgress);
vec2 scorchRange = uForOpening ? vec2(hideThreshold - SCORCH_WIDTH, hideThreshold)
: vec2(hideThreshold, hideThreshold + SCORCH_WIDTH);
@@ -39,17 +38,30 @@ void main() {
vec2 uv = cogl_tex_coord_in[0].st / uScale * uSize;
float noise = simplex2DFractal(uv * 0.005 + uSeed);
float gradient = rotate(cogl_tex_coord_in[0].st - 0.5, uSeed.x * 2.0 * 3.141).x + 0.5;
float smokeNoise =
simplex2DFractal(uv * 0.01 + uSeed + uProgress * vec2(0.0, 0.3 * uDuration));
float mask = mix(gradient, noise, 0.15);
vec2 center = uSeed.x > uSeed.y ? vec2(uSeed.x, floor(uSeed.y + 0.5))
: vec2(floor(uSeed.x + 0.5), uSeed.y);
float circle = length(cogl_tex_coord_in[0].st - center);
float mask = mix(circle, smokeNoise, 0.2 * uTurbulence * uScale);
float smokeMask =
smoothstep(0, 1, (mask - smokeRange.x) / SMOKE_WIDTH) * getRelativeEdgeMask(0.2);
float flameMask =
smoothstep(0, 1, (mask - flameRange.x) / FLAME_WIDTH) * getRelativeEdgeMask(0.1);
float fireMask = smoothstep(1, 0, abs(mask - hideThreshold) / BURN_WIDTH);
float scorchMask = smoothstep(1, 0, (mask - scorchRange.x) / SCORCH_WIDTH);
if (uForOpening) {
scorchMask = 1.0 - scorchMask;
}
// Now we retrieve the window color. We add some distortion in the scorch zone.
vec2 distort = vec2(0.0);
if ((uForOpening && mask > scorchRange.x) || (!uForOpening && mask <= scorchRange.y)) {
distort =
0.5 * vec2(dFdx(mask), dFdy(mask)) * (scorchRange.y - mask) / SCORCH_WIDTH * 5.0;
if ((uForOpening && mask >= scorchRange.x) || (!uForOpening && mask <= scorchRange.y)) {
distort = vec2(dFdx(mask), dFdy(mask)) * scorchMask * 5.0;
}
vec4 oColor = getInputColor(cogl_tex_coord_in[0].st + distort);
@@ -59,54 +71,39 @@ void main() {
oColor = vec4(0.0);
}
float smokeMask =
smoothstep(0, 1, (mask - smokeRange.x) / SMOKE_WIDTH) * getRelativeEdgeMask(0.1);
float smokeNoise = simplex2DFractal(uv * 0.01 + uSeed -
smokeMask * smokeMask * vec2(0.0, 0.1 * uDuration));
float flameNoise =
simplex2DFractal(uv * 0.02 + uSeed - smokeNoise * vec2(0.0, 1.0 * uDuration) -
vec2(0.0, uProgress * uDuration));
float emberNoise =
simplex2DFractal(uv * 0.075 + uSeed - smokeMask * vec2(0.0, 0.2 * uDuration));
// Add smoke and embers.
if (smokeRange.x < mask && mask < smokeRange.y) {
float smoke = smokeMask * smokeNoise;
oColor = alphaOver(oColor, vec4(0.5 * vec3(smoke), smoke));
float emberNoise = simplex2DFractal(
uv * 0.05 + uSeed - smokeNoise * vec2(0.0, 0.3 * smokeMask * uDuration));
float embers = clamp(pow(emberNoise + 0.3, 100.0), 0.0, 2.0) * smoke;
// embers += clamp(pow(emberNoise + 0.32, 10.0), 0.0, 2.0) * smoke;
oColor += getFireColor(embers);
}
if (flameRange.x < mask && mask < flameRange.y) {
float flameMask =
smoothstep(0, 1, (mask - flameRange.x) / FLAME_WIDTH) * getRelativeEdgeMask(0.1);
float flame = clamp(pow(flameNoise + 0.3, 20.0), 0.0, 2.0) * flameMask;
flame += clamp(pow(flameNoise + 0.8, 5.0), 0.0, 2.0) * flameMask * 0.1;
oColor += getFireColor(flame);
}
// Add scorch effect.
if (scorchRange.x < mask && mask < scorchRange.y) {
float scorch = smoothstep(1, 0, (mask - scorchRange.x) / SCORCH_WIDTH);
if (uForOpening) {
scorch = 1.0 - scorch;
oColor.rgb = mix(oColor.rgb, mix(oColor.rgb, vec3(0.1, 0.05, 0.02), 0.4), scorchMask);
}
oColor.rgb = mix(oColor.rgb, mix(oColor.rgb, vec3(0.1, 0.05, 0.02), 0.4), scorch);
// Add trailing flames.
if (min(burnRange.x, flameRange.x) < mask && mask < max(burnRange.y, flameRange.y)) {
float flameNoise =
simplex2DFractal(uv * 0.02 + uSeed + smokeNoise * vec2(0.0, 1.0 * uDuration) +
vec2(0.0, uProgress * uDuration));
if (flameRange.x < mask && mask < flameRange.y) {
float flame = clamp(pow(flameNoise + 0.3, 20.0), 0.0, 2.0) * flameMask;
flame += clamp(pow(flameNoise + 0.4, 10.0), 0.0, 2.0) * flameMask * flameMask * 0.1;
oColor += getFireColor(flame);
}
// Add burning edge.
if (burnRange.x < mask && mask < burnRange.y) {
float fireEdge = smoothstep(1, 0, abs(mask - hideThreshold) / BURN_WIDTH) * oColor.a;
fireEdge = fireEdge * pow(flameNoise + 0.4, 4.0);
oColor += getFireColor(fireEdge * oColor.a);
float fire = fireMask * pow(flameNoise + 0.4, 4.0) * oColor.a;
oColor += getFireColor(fire);
}
}
setOutputColor(oColor);
-46
View File
@@ -106,52 +106,6 @@
</object>
</child>
<child>
<object class="GtkListBoxRow">
<property name="activatable">0</property>
<child>
<object class="GtkBox">
<child>
<object class="GtkLabel">
<property name="label" translatable="yes">Width</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">2</property>
<property name="value-pos">left</property>
<property name="width-request">300</property>
<property name="adjustment">
<object class="GtkAdjustment" id="incinerate-width">
<property name="upper">10</property>
<property name="lower">0.1</property>
<property name="step-increment">0.01</property>
<property name="page-increment">0.1</property>
</object>
</property>
</object>
</child>
<child>
<object class="GtkButton" id="reset-incinerate-width">
<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>
@@ -348,7 +348,7 @@
</key>
<key name="incinerate-animation-time" type="i">
<default>1750</default>
<default>2000</default>
<summary>Incinerate Animation Time</summary>
<description>The time the Incinerate effect takes.</description>
</key>
@@ -359,12 +359,6 @@
<description>The scale of the effect.</description>
</key>
<key name="incinerate-width" type="d">
<default>1.0</default>
<summary>Incinerate Width</summary>
<description>The width of the effect.</description>
</key>
<key name="incinerate-turbulence" type="d">
<default>0.2</default>
<summary>Incinerate Turbulence</summary>
-3
View File
@@ -44,7 +44,6 @@ var Incinerate = class {
// Store uniform locations of newly created shaders.
shader._uSeed = shader.get_uniform_location('uSeed');
shader._uColor = shader.get_uniform_location('uColor');
shader._uWidth = shader.get_uniform_location('uWidth');
shader._uScale = shader.get_uniform_location('uScale');
shader._uTurbulence = shader.get_uniform_location('uTurbulence');
@@ -59,7 +58,6 @@ var Incinerate = class {
// 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]);
shader.set_uniform_float(shader._uWidth, 1, [settings.get_double('incinerate-width')]);
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
@@ -99,7 +97,6 @@ var Incinerate = class {
// Bind all properties.
dialog.bindAdjustment('incinerate-animation-time');
dialog.bindAdjustment('incinerate-width');
dialog.bindAdjustment('incinerate-scale');
dialog.bindAdjustment('incinerate-turbulence');
dialog.bindColorButton('incinerate-color');