From 230612d20d9cada2253ca79d9dbe93cf52318038 Mon Sep 17 00:00:00 2001 From: JeremyStarTM Date: Fri, 10 May 2024 20:08:14 +0200 Subject: [PATCH] Forgot to commit the blur shader, oopsie --- assets/shaders/blur.gdshader | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 assets/shaders/blur.gdshader diff --git a/assets/shaders/blur.gdshader b/assets/shaders/blur.gdshader new file mode 100644 index 0000000..bd7213a --- /dev/null +++ b/assets/shaders/blur.gdshader @@ -0,0 +1,32 @@ +// From https://www.reddit.com/r/godot/comments/12cb1t2/comment/jf1y66f/?utm_source=share&utm_medium=web3x&utm_name=web3xcss&utm_term=1&utm_content=share_button +shader_type canvas_item; +render_mode blend_mix; + +uniform float radius = 4.0; +uniform int steps = 32; +uniform float vertex_expand = 1.0; + +mat2 rotationMatrix(float angle){ + angle *= PI / 180.0; + float s = sin(angle); + float c = cos(angle); + return mat2( vec2(c, -s), vec2( s, c) ); +} + +void vertex() { + VERTEX.x *= vertex_expand; + VERTEX.y *= vertex_expand; +} + +void fragment() { + float uvx = UV.x * vertex_expand - vertex_expand/2.0 + 0.5; + float uvy = UV.y * vertex_expand - vertex_expand/2.0 + 0.5; + vec2 new_uv = vec2(uvx,uvy); + vec4 col = texture(TEXTURE, new_uv); + float angle = 360.0 / float(steps); + for (int i = 0; i < steps; i++){ + col += texture(TEXTURE, new_uv + vec2(radius, 0.0) * rotationMatrix(angle*float(i)) * TEXTURE_PIXEL_SIZE); + } + col /= float(steps) + 1.0; + COLOR = col; +}