| 1 | #version 300 es |
| 2 | // Vignette Shader - OPTIMIZED |
| 3 | // Fixes: Aspect ratio correction for circular vignette, safe smoothstep bounds |
| 4 | |
| 5 | precision highp float; |
| 6 | |
| 7 | in vec2 v_texcoord; |
| 8 | uniform sampler2D tex; |
| 9 | out vec4 fragColor; |
| 10 | |
| 11 | // --- CONFIGURATION --- |
| 12 | const float RADIUS = 0.65; |
| 13 | const float SOFTNESS = 0.45; |
| 14 | const float STRENGTH = 0.5; |
| 15 | // Set to your monitor's aspect ratio for circular vignette |
| 16 | const float ASPECT_RATIO = 16.0 / 9.0; |
| 17 | |
| 18 | void main() { |
| 19 | vec4 color = texture(tex, v_texcoord); |
| 20 | |
| 21 | // FIXED: Aspect-corrected distance for circular (not elliptical) vignette |
| 22 | vec2 centered = v_texcoord - 0.5; |
| 23 | centered.x *= ASPECT_RATIO; |
| 24 | float dist = length(centered); |
| 25 | // Normalize so corner distance is ~1.0 regardless of aspect ratio |
| 26 | dist /= length(vec2(ASPECT_RATIO * 0.5, 0.5)); |
| 27 | |
| 28 | // FIXED: Ensure smoothstep has valid bounds (edge1 > edge0) |
| 29 | float innerEdge = RADIUS; |
| 30 | float outerEdge = RADIUS + SOFTNESS; |
| 31 | float vignette = 1.0 - smoothstep(innerEdge, outerEdge, dist); |
| 32 | |
| 33 | // Apply with strength control |
| 34 | color.rgb = mix(color.rgb, color.rgb * vignette, STRENGTH); |
| 35 | |
| 36 | fragColor = color; |
| 37 | } |