Upload blueprints/.glsl/Image_Blur_1.frag with huggingface_hub
Browse files
blueprints/.glsl/Image_Blur_1.frag
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#version 300 es
|
| 2 |
+
#pragma passes 2
|
| 3 |
+
precision highp float;
|
| 4 |
+
|
| 5 |
+
// Blur type constants
|
| 6 |
+
const int BLUR_GAUSSIAN = 0;
|
| 7 |
+
const int BLUR_BOX = 1;
|
| 8 |
+
const int BLUR_RADIAL = 2;
|
| 9 |
+
|
| 10 |
+
// Radial blur config
|
| 11 |
+
const int RADIAL_SAMPLES = 12;
|
| 12 |
+
const float RADIAL_STRENGTH = 0.0003;
|
| 13 |
+
|
| 14 |
+
uniform sampler2D u_image0;
|
| 15 |
+
uniform int u_int0; // Blur type (BLUR_GAUSSIAN, BLUR_BOX, BLUR_RADIAL)
|
| 16 |
+
uniform float u_float0; // Blur radius/amount
|
| 17 |
+
uniform int u_pass; // Pass index (0 = horizontal, 1 = vertical)
|
| 18 |
+
|
| 19 |
+
in vec2 v_texCoord;
|
| 20 |
+
layout(location = 0) out vec4 fragColor0;
|
| 21 |
+
|
| 22 |
+
float gaussian(float x, float sigma) {
|
| 23 |
+
return exp(-(x * x) / (2.0 * sigma * sigma));
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
void main() {
|
| 27 |
+
vec2 texelSize = 1.0 / vec2(textureSize(u_image0, 0));
|
| 28 |
+
float radius = max(u_float0, 0.0);
|
| 29 |
+
|
| 30 |
+
// Radial (angular) blur - single pass, doesn't use separable
|
| 31 |
+
if (u_int0 == BLUR_RADIAL) {
|
| 32 |
+
// Only execute on first pass
|
| 33 |
+
if (u_pass > 0) {
|
| 34 |
+
fragColor0 = texture(u_image0, v_texCoord);
|
| 35 |
+
return;
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
vec2 center = vec2(0.5);
|
| 39 |
+
vec2 dir = v_texCoord - center;
|
| 40 |
+
float dist = length(dir);
|
| 41 |
+
|
| 42 |
+
if (dist < 1e-4) {
|
| 43 |
+
fragColor0 = texture(u_image0, v_texCoord);
|
| 44 |
+
return;
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
vec4 sum = vec4(0.0);
|
| 48 |
+
float totalWeight = 0.0;
|
| 49 |
+
float angleStep = radius * RADIAL_STRENGTH;
|
| 50 |
+
|
| 51 |
+
dir /= dist;
|
| 52 |
+
|
| 53 |
+
float cosStep = cos(angleStep);
|
| 54 |
+
float sinStep = sin(angleStep);
|
| 55 |
+
|
| 56 |
+
float negAngle = -float(RADIAL_SAMPLES) * angleStep;
|
| 57 |
+
vec2 rotDir = vec2(
|
| 58 |
+
dir.x * cos(negAngle) - dir.y * sin(negAngle),
|
| 59 |
+
dir.x * sin(negAngle) + dir.y * cos(negAngle)
|
| 60 |
+
);
|
| 61 |
+
|
| 62 |
+
for (int i = -RADIAL_SAMPLES; i <= RADIAL_SAMPLES; i++) {
|
| 63 |
+
vec2 uv = center + rotDir * dist;
|
| 64 |
+
float w = 1.0 - abs(float(i)) / float(RADIAL_SAMPLES);
|
| 65 |
+
sum += texture(u_image0, uv) * w;
|
| 66 |
+
totalWeight += w;
|
| 67 |
+
|
| 68 |
+
rotDir = vec2(
|
| 69 |
+
rotDir.x * cosStep - rotDir.y * sinStep,
|
| 70 |
+
rotDir.x * sinStep + rotDir.y * cosStep
|
| 71 |
+
);
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
fragColor0 = sum / max(totalWeight, 0.001);
|
| 75 |
+
return;
|
| 76 |
+
}
|
| 77 |
+
|
| 78 |
+
// Separable Gaussian / Box blur
|
| 79 |
+
int samples = int(ceil(radius));
|
| 80 |
+
|
| 81 |
+
if (samples == 0) {
|
| 82 |
+
fragColor0 = texture(u_image0, v_texCoord);
|
| 83 |
+
return;
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
// Direction: pass 0 = horizontal, pass 1 = vertical
|
| 87 |
+
vec2 dir = (u_pass == 0) ? vec2(1.0, 0.0) : vec2(0.0, 1.0);
|
| 88 |
+
|
| 89 |
+
vec4 color = vec4(0.0);
|
| 90 |
+
float totalWeight = 0.0;
|
| 91 |
+
float sigma = radius / 2.0;
|
| 92 |
+
|
| 93 |
+
for (int i = -samples; i <= samples; i++) {
|
| 94 |
+
vec2 offset = dir * float(i) * texelSize;
|
| 95 |
+
vec4 sample_color = texture(u_image0, v_texCoord + offset);
|
| 96 |
+
|
| 97 |
+
float weight;
|
| 98 |
+
if (u_int0 == BLUR_GAUSSIAN) {
|
| 99 |
+
weight = gaussian(float(i), sigma);
|
| 100 |
+
} else {
|
| 101 |
+
// BLUR_BOX
|
| 102 |
+
weight = 1.0;
|
| 103 |
+
}
|
| 104 |
+
|
| 105 |
+
color += sample_color * weight;
|
| 106 |
+
totalWeight += weight;
|
| 107 |
+
}
|
| 108 |
+
|
| 109 |
+
fragColor0 = color / totalWeight;
|
| 110 |
+
}
|