summaryrefslogtreecommitdiff
path: root/render/fx_renderer/gles2/shaders/blur_effects.frag
diff options
context:
space:
mode:
authorErik Reider <[email protected]>2024-02-27 18:05:58 +0100
committerGitHub <[email protected]>2024-02-27 18:05:58 +0100
commit7f0883b383b73af7bc68dcf8c2ee845c5eab5807 (patch)
treeff13a416200ac372d0ae303e5996bb9a22f819dd /render/fx_renderer/gles2/shaders/blur_effects.frag
parent5b6862c981eb5541888f625cd93e7775cabe06b0 (diff)
[FX Renderer] Add blur (#30)
* Initial blur implementation * Added additional blur effects from SwayFX * Simplified blur pass functions to match the other pass functions * Minor fixes * Added support for optimized blur * tinywl: Don't set decoration values every frame * Updated public blur function docs * Simplified blur buffer management * Moved ignore transparent bool into a per buffer option * Clip the scene_buffer when blur is enabled * Added back corner and shadow checks in opaque_region function * Renamed fx_render_blur_options to fx_render_blur_pass_options * Fixed nits * Removed unused fx_framebuffer_bind_wlr_fbo function * Removed wlr_scene impl. Should be moved into future PR instead * Made blur impl independent of wlr_scene * Moved shader init back into fx_renderer.c * Renamed fx_framebuffer_get_or_create_bufferless to fx_framebuffer_get_or_create_custom
Diffstat (limited to 'render/fx_renderer/gles2/shaders/blur_effects.frag')
-rw-r--r--render/fx_renderer/gles2/shaders/blur_effects.frag60
1 files changed, 60 insertions, 0 deletions
diff --git a/render/fx_renderer/gles2/shaders/blur_effects.frag b/render/fx_renderer/gles2/shaders/blur_effects.frag
new file mode 100644
index 0000000..fcead5d
--- /dev/null
+++ b/render/fx_renderer/gles2/shaders/blur_effects.frag
@@ -0,0 +1,60 @@
+#ifdef GL_FRAGMENT_PRECISION_HIGH
+precision highp float;
+#else
+precision mediump float;
+#endif
+
+varying vec2 v_texcoord;
+
+uniform sampler2D tex;
+
+uniform float noise;
+uniform float brightness;
+uniform float contrast;
+uniform float saturation;
+
+mat4 brightnessMatrix() {
+ float b = brightness - 1.0;
+ return mat4(1, 0, 0, 0,
+ 0, 1, 0, 0,
+ 0, 0, 1, 0,
+ b, b, b, 1);
+}
+
+mat4 contrastMatrix() {
+ float t = (1.0 - contrast) / 2.0;
+ return mat4(contrast, 0, 0, 0,
+ 0, contrast, 0, 0,
+ 0, 0, contrast, 0,
+ t, t, t, 1);
+}
+
+mat4 saturationMatrix() {
+ vec3 luminance = vec3(0.3086, 0.6094, 0.0820);
+ float oneMinusSat = 1.0 - saturation;
+ vec3 red = vec3(luminance.x * oneMinusSat);
+ red+= vec3(saturation, 0, 0);
+ vec3 green = vec3(luminance.y * oneMinusSat);
+ green += vec3(0, saturation, 0);
+ vec3 blue = vec3(luminance.z * oneMinusSat);
+ blue += vec3(0, 0, saturation);
+ return mat4(red, 0,
+ green, 0,
+ blue, 0,
+ 0, 0, 0, 1);
+}
+
+// Fast generative noise function
+float hash(vec2 p) {
+ return fract(sin(dot(p, vec2(12.9898, 78.233))) * 43758.5453);
+}
+
+void main() {
+ vec4 color = texture2D(tex, v_texcoord);
+ color *= brightnessMatrix() * contrastMatrix() * saturationMatrix();
+ float noiseHash = hash(v_texcoord);
+ float noiseAmount = (mod(noiseHash, 1.0) - 0.5);
+ color.rgb += noiseAmount * noise;
+
+ gl_FragColor = color;
+}