Created
October 15, 2019 14:22
-
-
Save ufna/80fa3a73dcf3f2fb0d1ef72815b3a289 to your computer and use it in GitHub Desktop.
Kawase blur proof-of-concept
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void mainImage( out vec4 fragColor, in vec2 fragCoord ) | |
{ | |
// 0.5 - 1.5 - 2.5 - 3.5 | |
KawaseSample(fragColor, fragCoord, 0.5); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Header: Enable access to inputs from Common tab | |
// See https://www.shadertoy.com/view/ttf3R4 | |
#if __LINE__<17 // Must be on line 3! | |
#define _ST_TAB_COMMON | |
#endif | |
#if __LINE__<25 | |
#define _ST_TAB_SOUND | |
uniform vec3 iResolution; // Sound tab | |
uniform float iTime; // never defines these | |
#endif | |
#ifdef _ST_TAB_COMMON | |
#undef _ST_TAB_SOUND | |
uniform float iTimeDelta; | |
uniform int iFrame; | |
uniform float iChannelTime[4]; | |
uniform vec3 iChannelResolution[4]; | |
uniform vec4 iMouse; | |
// iDate and iSampleRate: Alread have them. | |
uniform sampler2D iChannel0; | |
uniform sampler2D iChannel1; // Change type to | |
uniform sampler2D iChannel2; // samplerCube | |
uniform sampler2D iChannel3; // if Cube input | |
#endif | |
// End header | |
void KawaseSample( out vec4 fragColor, in vec2 fragCoord, in float Shift) | |
{ | |
vec2 uv = fragCoord/iResolution.xy; | |
vec2 Resolution = iChannelResolution[0].xy; | |
vec3 BlurColor = texture(iChannel0, uv + vec2(Shift, Shift) / Resolution).rgb; | |
BlurColor += texture(iChannel0, uv + vec2(Shift, -Shift) / Resolution).rgb; | |
BlurColor += texture(iChannel0, uv + vec2(-Shift, Shift) / Resolution).rgb; | |
BlurColor += texture(iChannel0, uv + vec2(-Shift, -Shift) / Resolution).rgb; | |
BlurColor /= 4.0; | |
fragColor = vec4(BlurColor, 1.0); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const float CircleSize = 0.75; | |
const float SmoothPadding = 0.33; | |
void mainImage( out vec4 fragColor, in vec2 fragCoord ) | |
{ | |
vec2 uv = fragCoord/iResolution.xy; | |
// Clear color | |
vec3 ClearColor = texture(iChannel1, uv).rgb; | |
// Kawase bluer | |
vec4 BlurColor = vec4(0); | |
KawaseSample(BlurColor, fragCoord, 4.5); | |
// Calculate clear vision circle | |
float AspectRatio = iResolution.x / iResolution.y; | |
vec2 VisionCenter = iMouse.xy/iResolution.xy; | |
vec2 v = uv - VisionCenter; | |
v.x = v.x * AspectRatio; | |
float CirleRadius = CircleSize / 2.0; | |
float SmoothRadius = CirleRadius * SmoothPadding; | |
float CircleMask = smoothstep(CirleRadius, CirleRadius - SmoothRadius, length(v)); | |
BlurColor.rgb = mix(BlurColor.rgb, ClearColor.rgb, CircleMask); | |
fragColor = vec4(BlurColor); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://www.shadertoy.com/view/3dG3Wt?fbclid