diff --git a/app/src/main/res/raw/tiltshift_fragment.glsl b/app/src/main/res/raw/tiltshift_fragment.glsl index 3b4b33e..a051474 100644 --- a/app/src/main/res/raw/tiltshift_fragment.glsl +++ b/app/src/main/res/raw/tiltshift_fragment.glsl @@ -1,8 +1,8 @@ +#extension GL_OES_EGL_image_external : require + // Fragment shader for tilt-shift effect // Applies gradient blur based on distance from focus line -#extension GL_OES_EGL_image_external : require - precision mediump float; // Camera texture (external texture for camera preview) @@ -17,16 +17,6 @@ uniform vec2 uResolution; // Texture resolution for proper sampling varying vec2 vTexCoord; -// Blur kernel size (must be odd) -const int KERNEL_SIZE = 9; -const float KERNEL_HALF = 4.0; - -// Gaussian weights for 9-tap blur (sigma ~= 2.0) -const float weights[9] = float[]( - 0.0162, 0.0540, 0.1216, 0.1933, 0.2258, - 0.1933, 0.1216, 0.0540, 0.0162 -); - // Calculate signed distance from the focus line float focusDistance(vec2 uv) { // Rotate coordinate system around center @@ -57,6 +47,19 @@ float blurFactor(float dist) { return smoothstep(0.0, 1.0, normalizedDist) * uBlurAmount; } +// Get Gaussian weight for blur kernel (9-tap, sigma ~= 2.0) +float getWeight(int i) { + if (i == 0) return 0.0162; + if (i == 1) return 0.0540; + if (i == 2) return 0.1216; + if (i == 3) return 0.1933; + if (i == 4) return 0.2258; + if (i == 5) return 0.1933; + if (i == 6) return 0.1216; + if (i == 7) return 0.0540; + return 0.0162; // i == 8 +} + // Sample with Gaussian blur vec4 sampleBlurred(vec2 uv, float blur) { if (blur < 0.01) { @@ -73,10 +76,11 @@ vec4 sampleBlurred(vec2 uv, float blur) { // Scale blur radius by blur amount float radius = blur * 20.0; - for (int i = 0; i < KERNEL_SIZE; i++) { - float offset = (float(i) - KERNEL_HALF); + // 9-tap Gaussian blur + for (int i = 0; i < 9; i++) { + float offset = float(i) - 4.0; vec2 samplePos = uv + blurDir * texelSize * offset * radius; - color += texture2D(uTexture, samplePos) * weights[i]; + color += texture2D(uTexture, samplePos) * getWeight(i); } return color;