🔀 Merge pull request #161 from Schneegans/feature/simplify-includes

This commit is contained in:
Simon Schneegans
2022-05-27 21:28:40 +02:00
committed by GitHub
20 changed files with 279 additions and 172 deletions
+4
View File
@@ -8,6 +8,10 @@
* An option has been added which allows to automatically disable all effects if running on battery power. * An option has been added which allows to automatically disable all effects if running on battery power.
#### Enhancements
* The shader include system has been simplified. There's now just one "common.glsl" which is automatically loaded into each shader.
## [Burn My Windows 16](https://github.com/schneegans/Burn-My-Windows/releases/tag/v16) ## [Burn My Windows 16](https://github.com/schneegans/Burn-My-Windows/releases/tag/v16)
**Release Date:** 2022-05-21 **Release Date:** 2022-05-21
+3 -4
View File
@@ -77,7 +77,7 @@ Just remember to replace `simple-fade` with your custom name!
### 2. Creating the Effect Class ### 2. Creating the Effect Class
You will have to create a new GLSL file called `resources/shaders/simple-fade.glsl` and a new JavaScript source file called `src/SimpleFade.js`. You will have to create a new GLSL file called `resources/shaders/simple-fade.frag` and a new JavaScript source file called `src/SimpleFade.js`.
Simply paste the following source code to the respective file. Simply paste the following source code to the respective file.
Please study this code carefully, all of it is explained with inline comments. Please study this code carefully, all of it is explained with inline comments.
@@ -85,15 +85,14 @@ Please study this code carefully, all of it is explained with inline comments.
<summary>Expand this to show the GLSL code.</summary> <summary>Expand this to show the GLSL code.</summary>
```glsl ```glsl
// The code below injects some standard uniforms which will be updated during the // The content from common.glsl is automatically prepended to each shader effect. This
// animation. This includes: // provides some standard uniforms which will be updated during the animation.
// bool uForOpening: True if a window-open animation is ongoing, false otherwise. // bool uForOpening: True if a window-open animation is ongoing, false otherwise.
// sampler2D uTexture: Contains the texture of the window. // sampler2D uTexture: Contains the texture of the window.
// float uProgress: A value which transitions from 0 to 1 during the entire animation. // float uProgress: A value which transitions from 0 to 1 during the entire animation.
// float uTime: A steadily increasing value in seconds. // float uTime: A steadily increasing value in seconds.
// vec2 uSize: The size of uTexture in pixels. // vec2 uSize: The size of uTexture in pixels.
// float uPadding: The empty area around the actual window (e.g. where the shadow is drawn). // float uPadding: The empty area around the actual window (e.g. where the shadow is drawn).
#include "common/uniforms.glsl"
// The width of the fading effect is loaded from the settings. // The width of the fading effect is loaded from the settings.
uniform float uFadeWidth; uniform float uFadeWidth;
@@ -1,7 +1,17 @@
// Inject some common shader snippets. It is only possible to include glsl files from the //////////////////////////////////////////////////////////////////////////////////////////
// "common" directory. Also, the files in the "common" directory are not allowed to // ) ( //
// include any further files. // ( /( ( ( ) ( ( ( ( )\ ) ( ( //
#include "common/uniforms.glsl" // )\()) ))\ )( ( ( )\ ) )\))( )\ ( (()/( ( )\))( ( //
// ((_)\ /((_|()\ )\ ) )\ '(()/( ((_)()((_) )\ ) ((_)))\((_)()\ )\ //
// | |(_|_))( ((_)_(_/( _((_)) )(_)) _(()((_|_)_(_/( _| |((_)(()((_|(_) //
// | '_ \ || | '_| ' \)) | ' \()| || | \ 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 vec2 uSeed; uniform vec2 uSeed;
uniform float uShake; uniform float uShake;
@@ -1,7 +1,17 @@
// Inject some common shader snippets. It is only possible to include glsl files from the //////////////////////////////////////////////////////////////////////////////////////////
// "common" directory. Also, the files in the "common" directory are not allowed to // ) ( //
// include any further files. // ( /( ( ( ) ( ( ( ( )\ ) ( ( //
#include "common/uniforms.glsl" // )\()) ))\ )( ( ( )\ ) )\))( )\ ( (()/( ( )\))( ( //
// ((_)\ /((_|()\ )\ ) )\ '(()/( ((_)()((_) )\ ) ((_)))\((_)()\ )\ //
// | |(_|_))( ((_)_(_/( _((_)) )(_)) _(()((_|_)_(_/( _| |((_)(()((_|(_) //
// | '_ \ || | '_| ' \)) | ' \()| || | \ 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 sampler2D uShardTexture; uniform sampler2D uShardTexture;
uniform vec2 uSeed; uniform vec2 uSeed;
@@ -1,12 +1,110 @@
//////////////////////////////////////////////////////////////////////////////////////////
// ) ( //
// ( /( ( ( ) ( ( ( ( )\ ) ( ( //
// )\()) ))\ )( ( ( )\ ) )\))( )\ ( (()/( ( )\))( ( //
// ((_)\ /((_|()\ )\ ) )\ '(()/( ((_)()((_) )\ ) ((_)))\((_)()\ )\ //
// | |(_|_))( ((_)_(_/( _((_)) )(_)) _(()((_|_)_(_/( _| |((_)(()((_|(_) //
// | '_ \ || | '_| ' \)) | ' \()| || | \ V V / | ' \)) _` / _ \ V V (_-< //
// |_.__/\_,_|_| |_||_| |_|_|_| \_, | \_/\_/|_|_||_|\__,_\___/\_/\_//__/ //
// |__/ //
// Copyright (c) 2021 Simon Schneegans //
// Released under the GPLv3 or later. See LICENSE file for details. //
//////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////
// This file is automatically included in each shader. //
//////////////////////////////////////////////////////////////////////////////////////////
// --------------------------------------------------------------------- standard uniforms
// uForOpening: True if a window-open animation is ongoing, false otherwise.
// uTexture: Contains the texture of the window.
// uProgress: A value which transitions from 0 to 1 during the entire animation.
// uTime: A steadily increasing value in seconds.
// uSize: The size of uTexture in pixels.
// uPadding: The empty area around the actual window (e.g. where the shadow is drawn).
uniform bool uForOpening;
uniform sampler2D uTexture;
uniform float uProgress;
uniform float uTime;
uniform vec2 uSize;
uniform float uPadding;
// ----------------------------------------------------------------- compositing operators
// The Shell.GLSLEffect uses straight alpha blending. This helper method allows
// compositing color values in the shader in the same way.
vec4 alphaOver(vec4 under, vec4 over) {
float alpha = over.a + under.a * (1.0 - over.a);
return vec4((over.rgb * over.a + under.rgb * under.a * (1.0 - over.a)) / alpha, alpha);
}
// ---------------------------------------------------------------------- easing functions
// Here are some basic easing function. More can be added if required!
// Taken from here:
// https://gitlab.gnome.org/GNOME/mutter/-/blob/main/clutter/clutter/clutter-easing.c
float easeOutQuad(float x) { return -1.0 * x * (x - 2); }
// --------------------------------------------------------------------- edge mask helpers
// This method returns a mask which smoothly transitions towards zero when approaching
// the window's borders. There is a variant which takes the transition area width in
// pixels and one which takes this as a percentage.
float getEdgeMask(vec2 uv, vec2 maxUV, float fadeWidth) {
float mask = 1.0;
mask *= smoothstep(0, 1, clamp(uv.x / fadeWidth, 0, 1));
mask *= smoothstep(0, 1, clamp(uv.y / fadeWidth, 0, 1));
mask *= smoothstep(0, 1, clamp((maxUV.x - uv.x) / fadeWidth, 0, 1));
mask *= smoothstep(0, 1, clamp((maxUV.y - uv.y) / fadeWidth, 0, 1));
return mask;
}
// Returns an edge mask which fades to zero at the boundaries of the actor. The width of
// the fade zone is given in pixels. This uses the standard uniforms uSize and uPadding.
// This means that the fading zone is not actually at the actors boundaries but at the
// position of the window border in the texture.
// The offset paramter controls whether the fading is placed inside the window borders
// (offset = 0), ontop the window borders (offset = 0.5) or outside the window borders
// (offset = 1).
float getAbsoluteEdgeMask(float fadePixels, float offset) {
float padding = max(0, uPadding - fadePixels * offset);
vec2 uv = cogl_tex_coord_in[0].st * uSize - padding;
return getEdgeMask(uv, uSize - 2.0 * padding, fadePixels);
}
// Returns an edge mask which fades to zero at the boundaries of the actor. The width of
// the fade zone is given relative to the actor size. This neither uses uSize and
// uPadding.
float getRelativeEdgeMask(float fadeAmount) {
vec2 uv = cogl_tex_coord_in[0].st;
return getEdgeMask(uv, vec2(1.0), fadeAmount);
}
// ------------------------------------------------------------------------------- 2D math
float distToLine(vec2 origin, vec2 direction, vec2 point) {
vec2 perpendicular = vec2(direction.y, -direction.x);
return abs(dot(normalize(perpendicular), origin - point));
}
float getWinding(vec2 a, vec2 b) { return cross(vec3(a, 0.0), vec3(b, 0.0)).z; }
vec2 rotate(vec2 a, float angle) {
return vec2(a.x * cos(angle) - a.y * sin(angle), a.x * sin(angle) + a.y * cos(angle));
}
// --------------------------------------------------------------------------------- noise
// These noise algorithms are based on implementations by various authors from // These noise algorithms are based on implementations by various authors from
// shadertoy.com, which are all available under the MIT License. See the respective links // shadertoy.com, which are all available under the MIT License. See the respective links
// in the comments below. // in the comments below.
//////////////////////////////////////////////////////////////////////////////////////// // Hash functions
// Hash without Sine // // MIT License, https://www.shadertoy.com/view/4djSRW
// MIT License, https://www.shadertoy.com/view/4djSRW // // Copyright (c) 2014 David Hoskins.
// Copyright (c) 2014 David Hoskins. //
////////////////////////////////////////////////////////////////////////////////////////
// 1 out, 1 in... // 1 out, 1 in...
float hash11(float p) { float hash11(float p) {
@@ -100,12 +198,9 @@ vec4 hash44(vec4 p4) {
return fract((p4.xxyz + p4.yzzw) * p4.zywx); return fract((p4.xxyz + p4.yzzw) * p4.zywx);
} }
//////////////////////////////////////////////////////////////////////////////////////// // 2D Simplex Noise
// 2D Simplex Noise // // MIT License, https://www.shadertoy.com/view/Msf3WH
// MIT License, https://www.shadertoy.com/view/Msf3WH // // Copyright © 2013 Inigo Quilez
// Copyright © 2013 Inigo Quilez //
////////////////////////////////////////////////////////////////////////////////////////
float simplex2D(vec2 p) { float simplex2D(vec2 p) {
const float K1 = 0.366025404; // (sqrt(3)-1)/2; const float K1 = 0.366025404; // (sqrt(3)-1)/2;
const float K2 = 0.211324865; // (3-sqrt(3))/6; const float K2 = 0.211324865; // (3-sqrt(3))/6;
@@ -137,12 +232,9 @@ float simplex2DFractal(vec2 p) {
return f; return f;
} }
//////////////////////////////////////////////////////////////////////////////////////// // 3D Simplex Noise
// 3D Simplex Noise // // MIT License, https://www.shadertoy.com/view/XsX3zB
// MIT License, https://www.shadertoy.com/view/XsX3zB // // Copyright © 2013 Nikita Miropolskiy
// Copyright © 2013 Nikita Miropolskiy //
////////////////////////////////////////////////////////////////////////////////////////
float simplex3D(vec3 p) { float simplex3D(vec3 p) {
// skew constants for 3D simplex functions // skew constants for 3D simplex functions
@@ -194,7 +286,7 @@ float simplex3D(vec3 p) {
return dot(d, vec4(52.0)) * 0.5 + 0.5; return dot(d, vec4(52.0)) * 0.5 + 0.5;
} }
// directional artifacts can be reduced by rotating each octave // Directional artifacts can be reduced by rotating each octave
float simplex3DFractal(vec3 m) { float simplex3DFractal(vec3 m) {
// const matrices for 3D rotation // const matrices for 3D rotation
@@ -1,6 +0,0 @@
// The Shell.GLSLEffect uses straight alpha blending. This helper method allows
// compositing color values in the shader in the same way.
vec4 alphaOver(vec4 under, vec4 over) {
float alpha = over.a + under.a * (1.0 - over.a);
return vec4((over.rgb * over.a + under.rgb * under.a * (1.0 - over.a)) / alpha, alpha);
}
-5
View File
@@ -1,5 +0,0 @@
// This provides some basic easing function. More can be added if required!
// Taken from here:
// https://gitlab.gnome.org/GNOME/mutter/-/blob/main/clutter/clutter/clutter-easing.c
float easeOutQuad(float x) { return -1.0 * x * (x - 2); }
-33
View File
@@ -1,33 +0,0 @@
// This method returns a mask which smoothly transitions towards zero when approaching
// the window's borders. There is a variant which takes the transition area width in
// pixels and one which takes this as a percentage.
float getEdgeMask(vec2 uv, vec2 maxUV, float fadeWidth) {
float mask = 1.0;
mask *= smoothstep(0, 1, clamp(uv.x / fadeWidth, 0, 1));
mask *= smoothstep(0, 1, clamp(uv.y / fadeWidth, 0, 1));
mask *= smoothstep(0, 1, clamp((maxUV.x - uv.x) / fadeWidth, 0, 1));
mask *= smoothstep(0, 1, clamp((maxUV.y - uv.y) / fadeWidth, 0, 1));
return mask;
}
// Returns an edge mask which fades to zero at the boundaries of the actor. The width of
// the fade zone is given in pixels. This uses the standard uniforms uSize and uPadding.
// This means that the fading zone is not actually at the actors boundaries but at the
// position of the window border in the texture.
// The offset paramter controls whether the fading is placed inside the window borders
// (offset = 0), ontop the window borders (offset = 0.5) or outside the window borders
// (offset = 1).
float getAbsoluteEdgeMask(float fadePixels, float offset) {
float padding = max(0, uPadding - fadePixels * offset);
vec2 uv = cogl_tex_coord_in[0].st * uSize - padding;
return getEdgeMask(uv, uSize - 2.0 * padding, fadePixels);
}
// Returns an edge mask which fades to zero at the boundaries of the actor. The width of
// the fade zone is given relative to the actor size. This neither uses uSize and
// uPadding.
float getRelativeEdgeMask(float fadeAmount) {
vec2 uv = cogl_tex_coord_in[0].st;
return getEdgeMask(uv, vec2(1.0), fadeAmount);
}
-10
View File
@@ -1,10 +0,0 @@
float distToLine(vec2 origin, vec2 direction, vec2 point) {
vec2 perpendicular = vec2(direction.y, -direction.x);
return abs(dot(normalize(perpendicular), origin - point));
}
float getWinding(vec2 a, vec2 b) { return cross(vec3(a, 0.0), vec3(b, 0.0)).z; }
vec2 rotate(vec2 a, float angle) {
return vec2(a.x * cos(angle) - a.y * sin(angle), a.x * sin(angle) + a.y * cos(angle));
}
-13
View File
@@ -1,13 +0,0 @@
// These should be included in every shader.
// uForOpening: True if a window-open animation is ongoing, false otherwise.
// uTexture: Contains the texture of the window.
// uProgress: A value which transitions from 0 to 1 during the entire animation.
// uTime: A steadily increasing value in seconds.
// uSize: The size of uTexture in pixels.
// uPadding: The empty area around the actual window (e.g. where the shadow is drawn).
uniform bool uForOpening;
uniform sampler2D uTexture;
uniform float uProgress;
uniform float uTime;
uniform vec2 uSize;
uniform float uPadding;
@@ -1,10 +1,17 @@
// Inject some common shader snippets. It is only possible to include glsl files from the //////////////////////////////////////////////////////////////////////////////////////////
// "common" directory. Also, the files in the "common" directory are not allowed to // ) ( //
// include any further files. // ( /( ( ( ) ( ( ( ( )\ ) ( ( //
#include "common/uniforms.glsl" // )\()) ))\ )( ( ( )\ ) )\))( )\ ( (()/( ( )\))( ( //
#include "common/noise.glsl" // ((_)\ /((_|()\ )\ ) )\ '(()/( ((_)()((_) )\ ) ((_)))\((_)()\ )\ //
#include "common/edgeMask.glsl" // | |(_|_))( ((_)_(_/( _((_)) )(_)) _(()((_|_)_(_/( _| |((_)(()((_|(_) //
#include "common/easing.glsl" // | '_ \ || | '_| ' \)) | ' \()| || | \ 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 vec3 uColor; uniform vec3 uColor;
uniform float uScale; uniform float uScale;
@@ -1,10 +1,17 @@
// Inject some common shader snippets. It is only possible to include glsl files from the //////////////////////////////////////////////////////////////////////////////////////////
// "common" directory. Also, the files in the "common" directory are not allowed to // ) ( //
// include any further files. // ( /( ( ( ) ( ( ( ( )\ ) ( ( //
#include "common/uniforms.glsl" // )\()) ))\ )( ( ( )\ ) )\))( )\ ( (()/( ( )\))( ( //
#include "common/noise.glsl" // ((_)\ /((_|()\ )\ ) )\ '(()/( ((_)()((_) )\ ) ((_)))\((_)()\ )\ //
#include "common/edgeMask.glsl" // | |(_|_))( ((_)_(_/( _((_)) )(_)) _(()((_|_)_(_/( _| |((_)(()((_|(_) //
#include "common/easing.glsl" // | '_ \ || | '_| ' \)) | ' \()| || | \ 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 vec3 uColor; uniform vec3 uColor;
uniform float uScale; uniform float uScale;
@@ -1,11 +1,17 @@
// Inject some common shader snippets. It is only possible to include glsl files from the //////////////////////////////////////////////////////////////////////////////////////////
// "common" directory. Also, the files in the "common" directory are not allowed to // ) ( //
// include any further files. // ( /( ( ( ) ( ( ( ( )\ ) ( ( //
#include "common/uniforms.glsl" // )\()) ))\ )( ( ( )\ ) )\))( )\ ( (()/( ( )\))( ( //
#include "common/compositing.glsl" // ((_)\ /((_|()\ )\ ) )\ '(()/( ((_)()((_) )\ ) ((_)))\((_)()\ )\ //
#include "common/edgeMask.glsl" // | |(_|_))( ((_)_(_/( _((_)) )(_)) _(()((_|_)_(_/( _| |((_)(()((_|(_) //
#include "common/noise.glsl" // | '_ \ || | '_| ' \)) | ' \()| || | \ V V / | ' \)) _` / _ \ V V (_-< //
#include "common/easing.glsl" // |_.__/\_,_|_| |_||_| |_|_|_| \_, | \_/\_/|_|_||_|\__,_\___/\_/\_//__/ //
// |__/ //
// 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 bool u3DNoise; uniform bool u3DNoise;
uniform float uScale; uniform float uScale;
@@ -1,8 +1,17 @@
// Inject some common shader snippets. It is only possible to include glsl files from the //////////////////////////////////////////////////////////////////////////////////////////
// "common" directory. Also, the files in the "common" directory are not allowed to // ) ( //
// include any further files. // ( /( ( ( ) ( ( ( ( )\ ) ( ( //
#include "common/uniforms.glsl" // )\()) ))\ )( ( ( )\ ) )\))( )\ ( (()/( ( )\))( ( //
#include "common/noise.glsl" // ((_)\ /((_|()\ )\ ) )\ '(()/( ((_)()((_) )\ ) ((_)))\((_)()\ )\ //
// | |(_|_))( ((_)_(_/( _((_)) )(_)) _(()((_|_)_(_/( _| |((_)(()((_|(_) //
// | '_ \ || | '_| ' \)) | ' \()| || | \ 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 bool uAdditiveBlending; uniform bool uAdditiveBlending;
uniform vec2 uSeed; uniform vec2 uSeed;
@@ -1,10 +1,17 @@
// Inject some common shader snippets. It is only possible to include glsl files from the //////////////////////////////////////////////////////////////////////////////////////////
// "common" directory. Also, the files in the "common" directory are not allowed to // ) ( //
// include any further files. // ( /( ( ( ) ( ( ( ( )\ ) ( ( //
#include "common/uniforms.glsl" // )\()) ))\ )( ( ( )\ ) )\))( )\ ( (()/( ( )\))( ( //
#include "common/noise.glsl" // ((_)\ /((_|()\ )\ ) )\ '(()/( ((_)()((_) )\ ) ((_)))\((_)()\ )\ //
#include "common/edgeMask.glsl" // | |(_|_))( ((_)_(_/( _((_)) )(_)) _(()((_|_)_(_/( _| |((_)(()((_|(_) //
#include "common/compositing.glsl" // | '_ \ || | '_| ' \)) | ' \()| || | \ 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 sampler2D uFontTexture; uniform sampler2D uFontTexture;
uniform vec3 uTrailColor; uniform vec3 uTrailColor;
@@ -1,9 +1,17 @@
// Inject some common shader snippets. It is only possible to include glsl files from the //////////////////////////////////////////////////////////////////////////////////////////
// "common" directory. Also, the files in the "common" directory are not allowed to // ) ( //
// include any further files. // ( /( ( ( ) ( ( ( ( )\ ) ( ( //
#include "common/uniforms.glsl" // )\()) ))\ )( ( ( )\ ) )\))( )\ ( (()/( ( )\))( ( //
#include "common/noise.glsl" // ((_)\ /((_|()\ )\ ) )\ '(()/( ((_)()((_) )\ ) ((_)))\((_)()\ )\ //
#include "common/math2D.glsl" // | |(_|_))( ((_)_(_/( _((_)) )(_)) _(()((_|_)_(_/( _| |((_)(()((_|(_) //
// | '_ \ || | '_| ' \)) | ' \()| || | \ 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 sampler2D uDustTexture; uniform sampler2D uDustTexture;
uniform vec4 uDustColor; uniform vec4 uDustColor;
@@ -1,10 +1,17 @@
// Inject some common shader snippets. It is only possible to include glsl files from the //////////////////////////////////////////////////////////////////////////////////////////
// "common" directory. Also, the files in the "common" directory are not allowed to // ) ( //
// include any further files. // ( /( ( ( ) ( ( ( ( )\ ) ( ( //
#include "common/uniforms.glsl" // )\()) ))\ )( ( ( )\ ) )\))( )\ ( (()/( ( )\))( ( //
#include "common/noise.glsl" // ((_)\ /((_|()\ )\ ) )\ '(()/( ((_)()((_) )\ ) ((_)))\((_)()\ )\ //
#include "common/compositing.glsl" // | |(_|_))( ((_)_(_/( _((_)) )(_)) _(()((_|_)_(_/( _| |((_)(()((_|(_) //
#include "common/easing.glsl" // | '_ \ || | '_| ' \)) | ' \()| || | \ 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.
// See assets/README.md for how this texture was created. // See assets/README.md for how this texture was created.
uniform sampler2D uClawTexture; uniform sampler2D uClawTexture;
@@ -1,8 +1,17 @@
// Inject some common shader snippets. It is only possible to include glsl files from the //////////////////////////////////////////////////////////////////////////////////////////
// "common" directory. Also, the files in the "common" directory are not allowed to // ) ( //
// include any further files. // ( /( ( ( ) ( ( ( ( )\ ) ( ( //
#include "common/uniforms.glsl" // )\()) ))\ )( ( ( )\ ) )\))( )\ ( (()/( ( )\))( ( //
#include "common/easing.glsl" // ((_)\ /((_|()\ )\ ) )\ '(()/( ((_)()((_) )\ ) ((_)))\((_)()\ )\ //
// | |(_|_))( ((_)_(_/( _((_)) )(_)) _(()((_|_)_(_/( _| |((_)(()((_|(_) //
// | '_ \ || | '_| ' \)) | ' \()| || | \ 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 vec3 uColor; uniform vec3 uColor;
@@ -1,11 +1,17 @@
// Inject some common shader snippets. It is only possible to include glsl files from the //////////////////////////////////////////////////////////////////////////////////////////
// "common" directory. Also, the files in the "common" directory are not allowed to // ) ( //
// include any further files. // ( /( ( ( ) ( ( ( ( )\ ) ( ( //
#include "common/uniforms.glsl" // )\()) ))\ )( ( ( )\ ) )\))( )\ ( (()/( ( )\))( ( //
#include "common/noise.glsl" // ((_)\ /((_|()\ )\ ) )\ '(()/( ((_)()((_) )\ ) ((_)))\((_)()\ )\ //
#include "common/edgeMask.glsl" // | |(_|_))( ((_)_(_/( _((_)) )(_)) _(()((_|_)_(_/( _| |((_)(()((_|(_) //
#include "common/compositing.glsl" // | '_ \ || | '_| ' \)) | ' \()| || | \ V V / | ' \)) _` / _ \ V V (_-< //
#include "common/easing.glsl" // |_.__/\_,_|_| |_||_| |_|_|_| \_, | \_/\_/|_|_||_|\__,_\___/\_/\_//__/ //
// |__/ //
// 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 vec2 uSeed; uniform vec2 uSeed;
uniform vec3 uColor; uniform vec3 uColor;
+7 -14
View File
@@ -106,7 +106,7 @@ var Shader = GObject.registerClass(
// Shell.GLSLEffect requires the declarations and the main source code as separate // Shell.GLSLEffect requires the declarations and the main source code as separate
// strings. As it's more convenient to store the in one GLSL file, we use a regex // strings. As it's more convenient to store the in one GLSL file, we use a regex
// here to split the source code in two parts. // here to split the source code in two parts.
const code = this._loadGLSLResource(`/shaders/${this._nick}.glsl`); const code = this._loadShaderResource(`/shaders/${this._nick}.frag`);
// Match anything between the curly brackets of "void main() {...}". // Match anything between the curly brackets of "void main() {...}".
const regex = RegExp('void main *\\(\\) *\\{([\\S\\s]+)\\}'); const regex = RegExp('void main *\\(\\) *\\{([\\S\\s]+)\\}');
@@ -136,20 +136,13 @@ var Shader = GObject.registerClass(
return ByteArray.toString(ByteArray.fromGBytes(data)); return ByteArray.toString(ByteArray.fromGBytes(data));
} }
// This loads a GLSL file from the extension's resources to a JavaScript string. Any // This loads a GLSL file from the extension's resources to a JavaScript string. The
// #include statements in this file are replaced with the corresponding file contents. // code from "common.glsl" is prepended automatically.
_loadGLSLResource(path) { _loadShaderResource(path) {
let code = this._loadStringResource(path); let common = this._loadStringResource('/shaders/common.glsl');
let code = this._loadStringResource(path);
// This regex matches either #include "..." or #include <...>. The part between the
// brackets is captured in the capture group.
const regex = RegExp('#include ["<](.+)[">]', 'g');
code = code.replace(regex, (m, file) => {
return this._loadStringResource('/shaders/' + file);
});
// Add a trailing newline. Else the GLSL compiler complains... // Add a trailing newline. Else the GLSL compiler complains...
return code + '\n'; return common + '\n' + code + '\n';
} }
}); });