merlemcdurrrmott commited on
Commit
18c0c8a
·
verified ·
1 Parent(s): a0c7347

Upload blueprints/.glsl/Unsharp_Mask_26.frag with huggingface_hub

Browse files
blueprints/.glsl/Unsharp_Mask_26.frag ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #version 300 es
2
+ precision highp float;
3
+
4
+ uniform sampler2D u_image0;
5
+ uniform float u_float0; // amount [0.0 - 3.0] typical: 0.5-1.5
6
+ uniform float u_float1; // radius [0.5 - 10.0] blur radius in pixels
7
+ uniform float u_float2; // threshold [0.0 - 0.1] min difference to sharpen
8
+
9
+ in vec2 v_texCoord;
10
+ layout(location = 0) out vec4 fragColor0;
11
+
12
+ float gaussian(float x, float sigma) {
13
+ return exp(-(x * x) / (2.0 * sigma * sigma));
14
+ }
15
+
16
+ float getLuminance(vec3 color) {
17
+ return dot(color, vec3(0.2126, 0.7152, 0.0722));
18
+ }
19
+
20
+ void main() {
21
+ vec2 texel = 1.0 / vec2(textureSize(u_image0, 0));
22
+ float radius = max(u_float1, 0.5);
23
+ float amount = u_float0;
24
+ float threshold = u_float2;
25
+
26
+ vec4 original = texture(u_image0, v_texCoord);
27
+
28
+ // Gaussian blur for the "unsharp" mask
29
+ int samples = int(ceil(radius));
30
+ float sigma = radius / 2.0;
31
+
32
+ vec4 blurred = vec4(0.0);
33
+ float totalWeight = 0.0;
34
+
35
+ for (int x = -samples; x <= samples; x++) {
36
+ for (int y = -samples; y <= samples; y++) {
37
+ vec2 offset = vec2(float(x), float(y)) * texel;
38
+ vec4 sample_color = texture(u_image0, v_texCoord + offset);
39
+
40
+ float dist = length(vec2(float(x), float(y)));
41
+ float weight = gaussian(dist, sigma);
42
+ blurred += sample_color * weight;
43
+ totalWeight += weight;
44
+ }
45
+ }
46
+ blurred /= totalWeight;
47
+
48
+ // Unsharp mask = original - blurred
49
+ vec3 mask = original.rgb - blurred.rgb;
50
+
51
+ // Luminance-based threshold with smooth falloff
52
+ float lumaDelta = abs(getLuminance(original.rgb) - getLuminance(blurred.rgb));
53
+ float thresholdScale = smoothstep(0.0, threshold, lumaDelta);
54
+ mask *= thresholdScale;
55
+
56
+ // Sharpen: original + mask * amount
57
+ vec3 sharpened = original.rgb + mask * amount;
58
+
59
+ fragColor0 = vec4(clamp(sharpened, 0.0, 1.0), original.a);
60
+ }