Fix GLSL shader for OpenGL ES 2.0 compatibility
- Move #extension directive to first line (required by GLSL) - Replace array initializer syntax with getWeight() function (float[]() constructor not supported in GLSL ES 1.00) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
07e10ac9c3
commit
cc367bc713
1 changed files with 19 additions and 15 deletions
|
|
@ -1,8 +1,8 @@
|
||||||
|
#extension GL_OES_EGL_image_external : require
|
||||||
|
|
||||||
// Fragment shader for tilt-shift effect
|
// Fragment shader for tilt-shift effect
|
||||||
// Applies gradient blur based on distance from focus line
|
// Applies gradient blur based on distance from focus line
|
||||||
|
|
||||||
#extension GL_OES_EGL_image_external : require
|
|
||||||
|
|
||||||
precision mediump float;
|
precision mediump float;
|
||||||
|
|
||||||
// Camera texture (external texture for camera preview)
|
// Camera texture (external texture for camera preview)
|
||||||
|
|
@ -17,16 +17,6 @@ uniform vec2 uResolution; // Texture resolution for proper sampling
|
||||||
|
|
||||||
varying vec2 vTexCoord;
|
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
|
// Calculate signed distance from the focus line
|
||||||
float focusDistance(vec2 uv) {
|
float focusDistance(vec2 uv) {
|
||||||
// Rotate coordinate system around center
|
// Rotate coordinate system around center
|
||||||
|
|
@ -57,6 +47,19 @@ float blurFactor(float dist) {
|
||||||
return smoothstep(0.0, 1.0, normalizedDist) * uBlurAmount;
|
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
|
// Sample with Gaussian blur
|
||||||
vec4 sampleBlurred(vec2 uv, float blur) {
|
vec4 sampleBlurred(vec2 uv, float blur) {
|
||||||
if (blur < 0.01) {
|
if (blur < 0.01) {
|
||||||
|
|
@ -73,10 +76,11 @@ vec4 sampleBlurred(vec2 uv, float blur) {
|
||||||
// Scale blur radius by blur amount
|
// Scale blur radius by blur amount
|
||||||
float radius = blur * 20.0;
|
float radius = blur * 20.0;
|
||||||
|
|
||||||
for (int i = 0; i < KERNEL_SIZE; i++) {
|
// 9-tap Gaussian blur
|
||||||
float offset = (float(i) - KERNEL_HALF);
|
for (int i = 0; i < 9; i++) {
|
||||||
|
float offset = float(i) - 4.0;
|
||||||
vec2 samplePos = uv + blurDir * texelSize * offset * radius;
|
vec2 samplePos = uv + blurDir * texelSize * offset * radius;
|
||||||
color += texture2D(uTexture, samplePos) * weights[i];
|
color += texture2D(uTexture, samplePos) * getWeight(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
return color;
|
return color;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue