This commit is contained in:
2024-07-08 22:46:35 +02:00
parent 02f44c49d2
commit 27254d817a
56249 changed files with 808097 additions and 1 deletions

View File

@ -0,0 +1,41 @@
uniform sampler2D tex;
uniform float red;
uniform float green;
uniform float blue;
uniform float blend;
uniform vec2 textureSize; // Size of the texture being sampled
// Function to perform a simple blur
vec4 blur(sampler2D texture, vec2 texCoord) {
vec4 sum = vec4(0.0);
float blurSize = 0.05; // Adjust this for different blur strengths
// Sample neighboring pixels and average their colors
sum += texture2D(texture, texCoord + vec2(-blurSize, -blurSize));
sum += texture2D(texture, texCoord + vec2(0.0, -blurSize));
sum += texture2D(texture, texCoord + vec2(blurSize, -blurSize));
sum += texture2D(texture, texCoord + vec2(-blurSize, 0.0));
sum += texture2D(texture, texCoord);
sum += texture2D(texture, texCoord + vec2(blurSize, 0.0));
sum += texture2D(texture, texCoord + vec2(-blurSize, blurSize));
sum += texture2D(texture, texCoord + vec2(0.0, blurSize));
sum += texture2D(texture, texCoord + vec2(blurSize, blurSize));
return sum / 9.0; // Adjust divisor for different blur strengths
}
void main() {
vec2 texCoord = cogl_tex_coord_in[0].st;
vec4 original = texture2D(tex, texCoord);
if (original.a >= 0.5) {
vec4 blurred = blur(tex, texCoord);
// blurred.a = original.a;
vec3 pix_color = blurred.rgb;
vec3 color = vec3(red * blurred.a, green * blurred.a, blue * blurred.a);
vec3 finalColor = mix(pix_color, color, blend * 0.75);
cogl_color_out = vec4(finalColor, (blurred.a + original.a)/2);
} else {
cogl_color_out = original;
}
}

View File

@ -0,0 +1,139 @@
'use strict';
import Shell from 'gi://Shell';
import GLib from 'gi://GLib';
import GObject from 'gi://GObject';
import Clutter from 'gi://Clutter';
const getTintShaderSource = (extensionDir) => {
const SHADER_PATH = GLib.build_filenamev([
extensionDir,
'effects',
'blur_effect.glsl',
]);
try {
return Shell.get_file_contents_utf8_sync(SHADER_PATH);
} catch (e) {
console.log(`[d2dl] error loading shader from ${SHADER_PATH}: ${e}`);
return null;
}
};
export const BlurEffect = GObject.registerClass(
{},
class SearchLighBlurEffect extends Clutter.ShaderEffect {
_init(params) {
this._red = null;
this._green = null;
this._blue = null;
this._blend = null;
this._static = true;
// initialize without color as a parameter
let _color = params.color;
delete params.color;
super._init(params);
// set shader color
if (_color) this.color = _color;
}
preload(path) {
// set shader source
this._source = getTintShaderSource(path);
if (this._source) this.set_shader_source(this._source);
this.update_enabled();
}
get red() {
return this._red;
}
set red(value) {
if (this._red !== value) {
this._red = value;
this.set_uniform_value('red', parseFloat(this._red - 1e-6));
}
}
get green() {
return this._green;
}
set green(value) {
if (this._green !== value) {
this._green = value;
this.set_uniform_value('green', parseFloat(this._green - 1e-6));
}
}
get blue() {
return this._blue;
}
set blue(value) {
if (this._blue !== value) {
this._blue = value;
this.set_uniform_value('blue', parseFloat(this._blue - 1e-6));
}
}
get blend() {
return this._blend;
}
set blend(value) {
if (value > 0.5) {
value *= 0.75;
if (value < 0.5) {
value = 0.5;
}
}
if (this._blend !== value) {
this._blend = value;
this.set_uniform_value('blend', parseFloat(this._blend - 1e-6));
}
this.update_enabled();
}
set color(rgba) {
let [r, g, b, a] = rgba;
this.red = r;
this.green = g;
this.blue = b;
this.blend = a;
}
get color() {
return [this.red, this.green, this.blue, this.blend];
}
/// False set function, only cares about the color. Too hard to change.
set(params) {
this.color = params.color;
}
update_enabled() {
this.set_enabled(this.blend > 0 && this._static);
}
vfunc_paint_target(paint_node = null, paint_context = null) {
this.set_uniform_value('tex', 0);
if (paint_node && paint_context)
super.vfunc_paint_target(paint_node, paint_context);
else if (paint_node) super.vfunc_paint_target(paint_node);
else super.vfunc_paint_target();
}
}
);

View File

@ -0,0 +1,10 @@
uniform sampler2D tex;
uniform float red;
uniform float green;
uniform float blue;
uniform float blend;
void main() {
vec4 c = texture2D(tex, cogl_tex_coord_in[0].st);
cogl_color_out = vec4(red * c.a * blend, green * c.a * blend, blue * c.a * blend, c.a * blend);
}

View File

@ -0,0 +1,143 @@
// Adapted from from Blur-My-Shell
'use strict';
import Shell from 'gi://Shell';
import GLib from 'gi://GLib';
import GObject from 'gi://GObject';
import Clutter from 'gi://Clutter';
const getColorEffectShaderSource = (extensionDir) => {
const SHADER_PATH = GLib.build_filenamev([
extensionDir,
'effects',
'color_effect.glsl',
]);
try {
return Shell.get_file_contents_utf8_sync(SHADER_PATH);
} catch (e) {
console.log(`[d2dl] error loading shader from ${SHADER_PATH}: ${e}`);
return null;
}
};
/// New Clutter Shader Effect that simply mixes a color in, the class applies
/// the GLSL shader programmed into vfunc_get_static_shader_source and applies
/// it to an Actor.
///
/// Clutter Shader Source Code:
/// https://github.com/GNOME/clutter/blob/master/clutter/clutter-shader-effect.c
///
/// GJS Doc:
/// https://gjs-docs.gnome.org/clutter10~10_api/clutter.shadereffect
export const ColorEffect = GObject.registerClass(
{},
class SearchLightColorShader extends Clutter.ShaderEffect {
_init(params) {
this._red = null;
this._green = null;
this._blue = null;
this._blend = null;
this._static = true;
// initialize without color as a parameter
let _color = params.color;
delete params.color;
super._init(params);
// set shader color
if (_color) this.color = _color;
}
preload(path) {
// set shader source
this._source = getColorEffectShaderSource(path);
if (this._source) this.set_shader_source(this._source);
this.update_enabled();
}
get red() {
return this._red;
}
set red(value) {
if (this._red !== value) {
this._red = value;
this.set_uniform_value('red', parseFloat(this._red - 1e-6));
}
}
get green() {
return this._green;
}
set green(value) {
if (this._green !== value) {
this._green = value;
this.set_uniform_value('green', parseFloat(this._green - 1e-6));
}
}
get blue() {
return this._blue;
}
set blue(value) {
if (this._blue !== value) {
this._blue = value;
this.set_uniform_value('blue', parseFloat(this._blue - 1e-6));
}
}
get blend() {
return this._blend;
}
set blend(value) {
if (this._blend !== value) {
this._blend = value;
this.set_uniform_value('blend', parseFloat(this._blend - 1e-6));
}
this.update_enabled();
}
set color(rgba) {
let [r, g, b, a] = rgba;
this.red = r;
this.green = g;
this.blue = b;
this.blend = a;
}
get color() {
return [this.red, this.green, this.blue, this.blend];
}
/// False set function, only cares about the color. Too hard to change.
set(params) {
this.color = params.color;
}
update_enabled() {
this.set_enabled(this.blend > 0 && this._static);
}
vfunc_paint_target(paint_node = null, paint_context = null) {
this.set_uniform_value('tex', 0);
if (paint_node && paint_context)
super.vfunc_paint_target(paint_node, paint_context);
else if (paint_node) super.vfunc_paint_target(paint_node);
else super.vfunc_paint_target();
}
}
);

View File

@ -0,0 +1,64 @@
'use strict';
/* PennerEasing */
export const Linear = {
easeNone: (t, b, c, d) => {
return (c * t) / d + b;
},
easeIn: (t, b, c, d) => {
return (c * t) / d + b;
},
easeOut: (t, b, c, d) => {
return (c * t) / d + b;
},
easeInOut: (t, b, c, d) => {
return (c * t) / d + b;
},
};
export const Bounce = {
easeIn: (t, b, c, d) => {
return c - Bounce.easeOut(d - t, 0, c, d) + b;
},
easeOut: (t, b, c, d) => {
if ((t /= d) < 1 / 2.75) {
return c * (7.5625 * t * t) + b;
} else if (t < 2 / 2.75) {
let postFix = (t -= 1.5 / 2.75);
return c * (7.5625 * postFix * t + 0.75) + b;
} else if (t < 2.5 / 2.75) {
let postFix = (t -= 2.25 / 2.75);
return c * (7.5625 * postFix * t + 0.9375) + b;
} else {
let postFix = (t -= 2.625 / 2.75);
return c * (7.5625 * postFix * t + 0.984375) + b;
}
},
easeInOut: (t, b, c, d) => {
if (t < d / 2) return Bounce.easeIn(t * 2, 0, c, d) * 0.5 + b;
else return Bounce.easeOut(t * 2 - d, 0, c, d) * 0.5 + c * 0.5 + b;
},
};
var Back = {
easeIn: (t, b, c, d) => {
let s = 1.70158;
let postFix = (t /= d);
return c * postFix * t * ((s + 1) * t - s) + b;
},
easeOut: (t, b, c, d) => {
let s = 1.70158;
return c * ((t = t / d - 1) * t * ((s + 1) * t + s) + 1) + b;
},
easeInOut: (t, b, c, d) => {
let s = 1.70158;
if ((t /= d / 2) < 1)
return (c / 2) * (t * t * (((s *= 1.525) + 1) * t - s)) + b;
let postFix = (t -= 2);
return (c / 2) * (postFix * t * (((s *= 1.525) + 1) * t + s) + 2) + b;
},
};

View File

@ -0,0 +1,22 @@
uniform sampler2D tex;
uniform float red;
uniform float green;
uniform float blue;
uniform float blend;
vec3 greyscale(vec3 color, float str) {
float g = dot(color, vec3(0.299, 0.587, 0.114));
return mix(color, vec3(g), str);
}
vec3 greyscale(vec3 color) {
return greyscale(color, 1.0);
}
void main() {
vec4 c = texture2D(tex, cogl_tex_coord_in[0].st);
vec3 pix_color = greyscale(c.rgb);
vec3 color = vec3(red * c.a, green * c.a, blue * c.a);
cogl_color_out = vec4(mix(pix_color, color, blend), c.a);
}

View File

@ -0,0 +1,150 @@
// Adapted from from Blur-My-Shell
// Adapted from https://gist.github.com/yiwenl/1c2ce935e66b82c7df5f
'use strict';
import Shell from 'gi://Shell';
import GLib from 'gi://GLib';
import GObject from 'gi://GObject';
import Clutter from 'gi://Clutter';
const getMonochromeShaderSource = (extensionDir) => {
const SHADER_PATH = GLib.build_filenamev([
extensionDir,
'effects',
'monochrome_effect.glsl',
]);
try {
return Shell.get_file_contents_utf8_sync(SHADER_PATH);
} catch (e) {
console.log(`[d2dl] error loading shader from ${SHADER_PATH}: ${e}`);
return null;
}
};
/// New Clutter Shader Effect that simply mixes a color in, the class applies
/// the GLSL shader programmed into vfunc_get_static_shader_source and applies
/// it to an Actor.
///
/// Clutter Shader Source Code:
/// https://github.com/GNOME/clutter/blob/master/clutter/clutter-shader-effect.c
///
/// GJS Doc:
/// https://gjs-docs.gnome.org/clutter10~10_api/clutter.shadereffect
export const MonochromeEffect = GObject.registerClass(
{},
class SearchLightMonochromeEffect extends Clutter.ShaderEffect {
_init(params) {
this._red = null;
this._green = null;
this._blue = null;
this._blend = null;
this._static = true;
// initialize without color as a parameter
let _color = params.color;
delete params.color;
super._init(params);
// set shader color
if (_color) this.color = _color;
}
preload(path) {
// set shader source
this._source = getMonochromeShaderSource(path);
if (this._source) this.set_shader_source(this._source);
this.update_enabled();
}
get red() {
return this._red;
}
set red(value) {
if (this._red !== value) {
this._red = value;
this.set_uniform_value('red', parseFloat(this._red - 1e-6));
}
}
get green() {
return this._green;
}
set green(value) {
if (this._green !== value) {
this._green = value;
this.set_uniform_value('green', parseFloat(this._green - 1e-6));
}
}
get blue() {
return this._blue;
}
set blue(value) {
if (this._blue !== value) {
this._blue = value;
this.set_uniform_value('blue', parseFloat(this._blue - 1e-6));
}
}
get blend() {
return this._blend;
}
set blend(value) {
if (value > 0.5) {
value *= 0.75;
if (value < 0.5) {
value = 0.5;
}
}
if (this._blend !== value) {
this._blend = value;
this.set_uniform_value('blend', parseFloat(this._blend - 1e-6));
}
this.update_enabled();
}
set color(rgba) {
let [r, g, b, a] = rgba;
this.red = r;
this.green = g;
this.blue = b;
this.blend = a;
}
get color() {
return [this.red, this.green, this.blue, this.blend];
}
/// False set function, only cares about the color. Too hard to change.
set(params) {
this.color = params.color;
}
update_enabled() {
this.set_enabled(this.blend > 0 && this._static);
}
vfunc_paint_target(paint_node = null, paint_context = null) {
this.set_uniform_value('tex', 0);
if (paint_node && paint_context)
super.vfunc_paint_target(paint_node, paint_context);
else if (paint_node) super.vfunc_paint_target(paint_node);
else super.vfunc_paint_target();
}
}
);

View File

@ -0,0 +1,12 @@
uniform sampler2D tex;
uniform float red;
uniform float green;
uniform float blue;
uniform float blend;
void main() {
vec4 c = texture2D(tex, cogl_tex_coord_in[0].st);
vec3 pix_color = c.rgb;
vec3 color = vec3(red * c.a, green * c.a, blue * c.a);
cogl_color_out = vec4(mix(pix_color, color, blend), c.a);
}

View File

@ -0,0 +1,150 @@
// Adapted from from Blur-My-Shell
'use strict';
import Shell from 'gi://Shell';
import GLib from 'gi://GLib';
import GObject from 'gi://GObject';
import Clutter from 'gi://Clutter';
const getTintShaderSource = (extensionDir) => {
const SHADER_PATH = GLib.build_filenamev([
extensionDir,
'effects',
'tint_effect.glsl',
]);
try {
return Shell.get_file_contents_utf8_sync(SHADER_PATH);
} catch (e) {
console.log(`[d2dl] error loading shader from ${SHADER_PATH}: ${e}`);
return null;
}
};
/// New Clutter Shader Effect that simply mixes a color in, the class applies
/// the GLSL shader programmed into vfunc_get_static_shader_source and applies
/// it to an Actor.
///
/// Clutter Shader Source Code:
/// https://github.com/GNOME/clutter/blob/master/clutter/clutter-shader-effect.c
///
/// GJS Doc:
/// https://gjs-docs.gnome.org/clutter10~10_api/clutter.shadereffect
export const TintEffect = GObject.registerClass(
{},
class SearchLightTintEffect extends Clutter.ShaderEffect {
_init(params) {
this._red = null;
this._green = null;
this._blue = null;
this._blend = null;
this._static = true;
// initialize without color as a parameter
let _color = params.color;
delete params.color;
super._init(params);
// set shader color
if (_color) this.color = _color;
}
preload(path) {
// set shader source
this._source = getTintShaderSource(path);
if (this._source) this.set_shader_source(this._source);
this.update_enabled();
}
get red() {
return this._red;
}
set red(value) {
if (this._red !== value) {
this._red = value;
this.set_uniform_value('red', parseFloat(this._red - 1e-6));
}
}
get green() {
return this._green;
}
set green(value) {
if (this._green !== value) {
this._green = value;
this.set_uniform_value('green', parseFloat(this._green - 1e-6));
}
}
get blue() {
return this._blue;
}
set blue(value) {
if (this._blue !== value) {
this._blue = value;
this.set_uniform_value('blue', parseFloat(this._blue - 1e-6));
}
}
get blend() {
return this._blend;
}
set blend(value) {
if (value > 0.5) {
value *= 0.75;
if (value < 0.5) {
value = 0.5;
}
}
if (this._blend !== value) {
this._blend = value;
this.set_uniform_value('blend', parseFloat(this._blend - 1e-6));
}
this.update_enabled();
}
set color(rgba) {
let [r, g, b, a] = rgba;
this.red = r;
this.green = g;
this.blue = b;
this.blend = a;
}
get color() {
return [this.red, this.green, this.blue, this.blend];
}
/// False set function, only cares about the color. Too hard to change.
set(params) {
this.color = params.color;
}
update_enabled() {
this.set_enabled(this.blend > 0 && this._static);
}
vfunc_paint_target(paint_node = null, paint_context = null) {
this.set_uniform_value('tex', 0);
if (paint_node && paint_context)
super.vfunc_paint_target(paint_node, paint_context);
else if (paint_node) super.vfunc_paint_target(paint_node);
else super.vfunc_paint_target();
}
}
);