Skip to content

Instantly share code, notes, and snippets.

@ufna
Created October 15, 2019 14:22
Show Gist options
  • Save ufna/80fa3a73dcf3f2fb0d1ef72815b3a289 to your computer and use it in GitHub Desktop.
Save ufna/80fa3a73dcf3f2fb0d1ef72815b3a289 to your computer and use it in GitHub Desktop.
Kawase blur proof-of-concept
void mainImage( out vec4 fragColor, in vec2 fragCoord )
{
// 0.5 - 1.5 - 2.5 - 3.5
KawaseSample(fragColor, fragCoord, 0.5);
}
// 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);
}
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);
}
@ufna
Copy link
Author

ufna commented Oct 15, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment