From c90f3a1c973ff64d21a04e4e4d9de4e12c59acad Mon Sep 17 00:00:00 2001 From: Simon Schneegans Date: Fri, 27 May 2022 21:18:18 +0200 Subject: [PATCH] :truck: Move common includes to one file --- docs/how-to-create-new-effects.md | 5 +- resources/shaders/apparition.glsl | 18 ++- resources/shaders/broken-glass.glsl | 18 ++- .../{common/noise.glsl => common.glsl} | 130 +++++++++++++++--- resources/shaders/common/compositing.glsl | 6 - resources/shaders/common/easing.glsl | 5 - resources/shaders/common/edgeMask.glsl | 33 ----- resources/shaders/common/math2D.glsl | 10 -- resources/shaders/common/uniforms.glsl | 13 -- resources/shaders/energize-a.glsl | 21 ++- resources/shaders/energize-b.glsl | 21 ++- resources/shaders/fire.glsl | 22 +-- resources/shaders/hexagon.glsl | 19 ++- resources/shaders/matrix.glsl | 21 ++- resources/shaders/snap.glsl | 20 ++- resources/shaders/trex.glsl | 21 ++- resources/shaders/tv.glsl | 19 ++- resources/shaders/wisps.glsl | 22 +-- src/Shader.js | 21 +-- 19 files changed, 274 insertions(+), 171 deletions(-) rename resources/shaders/{common/noise.glsl => common.glsl} (50%) delete mode 100644 resources/shaders/common/compositing.glsl delete mode 100644 resources/shaders/common/easing.glsl delete mode 100644 resources/shaders/common/edgeMask.glsl delete mode 100644 resources/shaders/common/math2D.glsl delete mode 100644 resources/shaders/common/uniforms.glsl diff --git a/docs/how-to-create-new-effects.md b/docs/how-to-create-new-effects.md index d92b43a..7067551 100644 --- a/docs/how-to-create-new-effects.md +++ b/docs/how-to-create-new-effects.md @@ -85,15 +85,14 @@ Please study this code carefully, all of it is explained with inline comments. Expand this to show the GLSL code. ```glsl -// The code below injects some standard uniforms which will be updated during the -// animation. This includes: +// The content from common.glsl is automatically prepended to each shader effect. This +// provides some standard uniforms which will be updated during the animation. // bool uForOpening: True if a window-open animation is ongoing, false otherwise. // sampler2D uTexture: Contains the texture of the window. // float uProgress: A value which transitions from 0 to 1 during the entire animation. // float uTime: A steadily increasing value in seconds. // vec2 uSize: The size of uTexture in pixels. // 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. uniform float uFadeWidth; diff --git a/resources/shaders/apparition.glsl b/resources/shaders/apparition.glsl index eddce19..0134c04 100644 --- a/resources/shaders/apparition.glsl +++ b/resources/shaders/apparition.glsl @@ -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 float uShake; diff --git a/resources/shaders/broken-glass.glsl b/resources/shaders/broken-glass.glsl index 306d5ac..b8326ca 100644 --- a/resources/shaders/broken-glass.glsl +++ b/resources/shaders/broken-glass.glsl @@ -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 vec2 uSeed; diff --git a/resources/shaders/common/noise.glsl b/resources/shaders/common.glsl similarity index 50% rename from resources/shaders/common/noise.glsl rename to resources/shaders/common.glsl index 5491b80..e8356fb 100644 --- a/resources/shaders/common/noise.glsl +++ b/resources/shaders/common.glsl @@ -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 // shadertoy.com, which are all available under the MIT License. See the respective links // in the comments below. -//////////////////////////////////////////////////////////////////////////////////////// -// Hash without Sine // -// MIT License, https://www.shadertoy.com/view/4djSRW // -// Copyright (c) 2014 David Hoskins. // -//////////////////////////////////////////////////////////////////////////////////////// +// Hash functions +// MIT License, https://www.shadertoy.com/view/4djSRW +// Copyright (c) 2014 David Hoskins. // 1 out, 1 in... float hash11(float p) { @@ -100,12 +198,9 @@ vec4 hash44(vec4 p4) { return fract((p4.xxyz + p4.yzzw) * p4.zywx); } -//////////////////////////////////////////////////////////////////////////////////////// -// 2D Simplex Noise // -// MIT License, https://www.shadertoy.com/view/Msf3WH // -// Copyright © 2013 Inigo Quilez // -//////////////////////////////////////////////////////////////////////////////////////// - +// 2D Simplex Noise +// MIT License, https://www.shadertoy.com/view/Msf3WH +// Copyright © 2013 Inigo Quilez float simplex2D(vec2 p) { const float K1 = 0.366025404; // (sqrt(3)-1)/2; const float K2 = 0.211324865; // (3-sqrt(3))/6; @@ -137,12 +232,9 @@ float simplex2DFractal(vec2 p) { return f; } -//////////////////////////////////////////////////////////////////////////////////////// -// 3D Simplex Noise // -// MIT License, https://www.shadertoy.com/view/XsX3zB // -// Copyright © 2013 Nikita Miropolskiy // -//////////////////////////////////////////////////////////////////////////////////////// - +// 3D Simplex Noise +// MIT License, https://www.shadertoy.com/view/XsX3zB +// Copyright © 2013 Nikita Miropolskiy float simplex3D(vec3 p) { // skew constants for 3D simplex functions @@ -194,7 +286,7 @@ float simplex3D(vec3 p) { 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) { // const matrices for 3D rotation @@ -204,4 +296,4 @@ float simplex3DFractal(vec3 m) { return 0.5333333 * simplex3D(m * rot1) + 0.2666667 * simplex3D(2.0 * m * rot2) + 0.1333333 * simplex3D(4.0 * m * rot3) + 0.0666667 * simplex3D(8.0 * m); -} \ No newline at end of file +} diff --git a/resources/shaders/common/compositing.glsl b/resources/shaders/common/compositing.glsl deleted file mode 100644 index 8222665..0000000 --- a/resources/shaders/common/compositing.glsl +++ /dev/null @@ -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); -} \ No newline at end of file diff --git a/resources/shaders/common/easing.glsl b/resources/shaders/common/easing.glsl deleted file mode 100644 index 87c7a17..0000000 --- a/resources/shaders/common/easing.glsl +++ /dev/null @@ -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); } \ No newline at end of file diff --git a/resources/shaders/common/edgeMask.glsl b/resources/shaders/common/edgeMask.glsl deleted file mode 100644 index d14e981..0000000 --- a/resources/shaders/common/edgeMask.glsl +++ /dev/null @@ -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); -} \ No newline at end of file diff --git a/resources/shaders/common/math2D.glsl b/resources/shaders/common/math2D.glsl deleted file mode 100644 index 01a3620..0000000 --- a/resources/shaders/common/math2D.glsl +++ /dev/null @@ -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)); -} \ No newline at end of file diff --git a/resources/shaders/common/uniforms.glsl b/resources/shaders/common/uniforms.glsl deleted file mode 100644 index ab7589a..0000000 --- a/resources/shaders/common/uniforms.glsl +++ /dev/null @@ -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; \ No newline at end of file diff --git a/resources/shaders/energize-a.glsl b/resources/shaders/energize-a.glsl index 054058d..77ab3fb 100644 --- a/resources/shaders/energize-a.glsl +++ b/resources/shaders/energize-a.glsl @@ -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 float uScale; diff --git a/resources/shaders/energize-b.glsl b/resources/shaders/energize-b.glsl index 7283fd7..4ac4faf 100644 --- a/resources/shaders/energize-b.glsl +++ b/resources/shaders/energize-b.glsl @@ -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 float uScale; diff --git a/resources/shaders/fire.glsl b/resources/shaders/fire.glsl index 12e395a..b4d5ded 100644 --- a/resources/shaders/fire.glsl +++ b/resources/shaders/fire.glsl @@ -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" -#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 bool u3DNoise; uniform float uScale; diff --git a/resources/shaders/hexagon.glsl b/resources/shaders/hexagon.glsl index 79a0aa6..752d886 100644 --- a/resources/shaders/hexagon.glsl +++ b/resources/shaders/hexagon.glsl @@ -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 vec2 uSeed; diff --git a/resources/shaders/matrix.glsl b/resources/shaders/matrix.glsl index 8b5010c..3afefb2 100644 --- a/resources/shaders/matrix.glsl +++ b/resources/shaders/matrix.glsl @@ -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 vec3 uTrailColor; diff --git a/resources/shaders/snap.glsl b/resources/shaders/snap.glsl index bf1489f..2432cb0 100644 --- a/resources/shaders/snap.glsl +++ b/resources/shaders/snap.glsl @@ -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 vec4 uDustColor; diff --git a/resources/shaders/trex.glsl b/resources/shaders/trex.glsl index 3916b15..20dbb3b 100644 --- a/resources/shaders/trex.glsl +++ b/resources/shaders/trex.glsl @@ -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. uniform sampler2D uClawTexture; diff --git a/resources/shaders/tv.glsl b/resources/shaders/tv.glsl index 0201350..df54666 100644 --- a/resources/shaders/tv.glsl +++ b/resources/shaders/tv.glsl @@ -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; diff --git a/resources/shaders/wisps.glsl b/resources/shaders/wisps.glsl index 008ca73..a19617f 100644 --- a/resources/shaders/wisps.glsl +++ b/resources/shaders/wisps.glsl @@ -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" -#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 vec2 uSeed; uniform vec3 uColor; diff --git a/src/Shader.js b/src/Shader.js index 922bb69..8fa7e14 100644 --- a/src/Shader.js +++ b/src/Shader.js @@ -106,7 +106,7 @@ var Shader = GObject.registerClass( // 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 // here to split the source code in two parts. - const code = this._loadGLSLResource(`/shaders/${this._nick}.glsl`); + const code = this._loadShaderResource(`/shaders/${this._nick}.glsl`); // Match anything between the curly brackets of "void main() {...}". const regex = RegExp('void main *\\(\\) *\\{([\\S\\s]+)\\}'); @@ -136,20 +136,13 @@ var Shader = GObject.registerClass( return ByteArray.toString(ByteArray.fromGBytes(data)); } - // This loads a GLSL file from the extension's resources to a JavaScript string. Any - // #include statements in this file are replaced with the corresponding file contents. - _loadGLSLResource(path) { - 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); - }); + // This loads a GLSL file from the extension's resources to a JavaScript string. The + // code from "common.glsl" is prepended automatically. + _loadShaderResource(path) { + let common = this._loadStringResource('/shaders/common.glsl'); + let code = this._loadStringResource(path); // Add a trailing newline. Else the GLSL compiler complains... - return code + '\n'; + return common + '\n' + code + '\n'; } });