diff options
| author | vaxerski <43317083+vaxerski@users.noreply.github.com> | 2022-05-02 16:54:40 +0200 |
|---|---|---|
| committer | vaxerski <43317083+vaxerski@users.noreply.github.com> | 2022-05-02 16:54:40 +0200 |
| commit | 43fc7662ccb8178f2984156d45c2406e302250fd (patch) | |
| tree | ebc0e31dd44762a669b6f455e53867678e65f7ec /src/render/Shaders.hpp | |
| parent | b5b78f383638eebc83fee7d964c08ce2599b0c06 (diff) | |
Major blur rework: optimization & fixes
Blur should be considerably faster now and work on full damage tracking
Diffstat (limited to 'src/render/Shaders.hpp')
| -rw-r--r-- | src/render/Shaders.hpp | 43 |
1 files changed, 23 insertions, 20 deletions
diff --git a/src/render/Shaders.hpp b/src/render/Shaders.hpp index b964c8c2..3864d801 100644 --- a/src/render/Shaders.hpp +++ b/src/render/Shaders.hpp @@ -154,46 +154,49 @@ void main() { gl_FragColor = vec4(texture2D(tex, v_texcoord).rgb, 1.0) * alpha; })#"; -// thanks to Loadus -// https://www.shadertoy.com/view/Mtl3Rj -// for this pseudo-gaussian blur! inline const std::string FRAGBLUR1 = R"#( +#version 100 precision mediump float; -varying vec2 v_texcoord; // is in 0-1 +varying mediump vec2 v_texcoord; // is in 0-1 uniform sampler2D tex; uniform float radius; -uniform vec2 resolution; uniform vec2 halfpixel; void main() { - vec4 sum = texture2D(tex, v_texcoord) * 4.0; - sum += texture2D(tex, v_texcoord - halfpixel.xy * radius); - sum += texture2D(tex, v_texcoord + halfpixel.xy * radius); - sum += texture2D(tex, v_texcoord + vec2(halfpixel.x, -halfpixel.y) * radius); - sum += texture2D(tex, v_texcoord - vec2(halfpixel.x, -halfpixel.y) * radius); + vec2 uv = v_texcoord * 2.0; + + vec4 sum = texture2D(tex, uv) * 4.0; + sum += texture2D(tex, uv - halfpixel.xy * radius); + sum += texture2D(tex, uv + halfpixel.xy * radius); + sum += texture2D(tex, uv + vec2(halfpixel.x, -halfpixel.y) * radius); + sum += texture2D(tex, uv - vec2(halfpixel.x, -halfpixel.y) * radius); gl_FragColor = sum / 8.0; } )#"; inline const std::string FRAGBLUR2 = R"#( +#version 100 precision mediump float; -varying vec2 v_texcoord; // is in 0-1 +varying mediump vec2 v_texcoord; // is in 0-1 uniform sampler2D tex; uniform float radius; -uniform vec2 resolution; uniform vec2 halfpixel; void main() { - vec4 sum = texture2D(tex, v_texcoord + vec2(-halfpixel.x * 2.0, 0.0) * radius); - sum += texture2D(tex, v_texcoord + vec2(-halfpixel.x, halfpixel.y) * radius) * 2.0; - sum += texture2D(tex, v_texcoord + vec2(0.0, halfpixel.y * 2.0) * radius); - sum += texture2D(tex, v_texcoord + vec2(halfpixel.x, halfpixel.y) * radius) * 2.0; - sum += texture2D(tex, v_texcoord + vec2(halfpixel.x * 2.0, 0.0) * radius); - sum += texture2D(tex, v_texcoord + vec2(halfpixel.x, -halfpixel.y) * radius) * 2.0; - sum += texture2D(tex, v_texcoord + vec2(0.0, -halfpixel.y * 2.0) * radius); - sum += texture2D(tex, v_texcoord + vec2(-halfpixel.x, -halfpixel.y) * radius) * 2.0; + vec2 uv = v_texcoord / 2.0; + + vec4 sum = texture2D(tex, uv + vec2(-halfpixel.x * 2.0, 0.0) * radius); + + sum += texture2D(tex, uv + vec2(-halfpixel.x, halfpixel.y) * radius) * 2.0; + sum += texture2D(tex, uv + vec2(0.0, halfpixel.y * 2.0) * radius); + sum += texture2D(tex, uv + vec2(halfpixel.x, halfpixel.y) * radius) * 2.0; + sum += texture2D(tex, uv + vec2(halfpixel.x * 2.0, 0.0) * radius); + sum += texture2D(tex, uv + vec2(halfpixel.x, -halfpixel.y) * radius) * 2.0; + sum += texture2D(tex, uv + vec2(0.0, -halfpixel.y * 2.0) * radius); + sum += texture2D(tex, uv + vec2(-halfpixel.x, -halfpixel.y) * radius) * 2.0; + gl_FragColor = sum / 12.0; } )#"; |
