| 1 | #version 300 es |
| 2 | // Sepia Tone Shader - OPTIMIZED |
| 3 | // Fixes: Clamping to prevent overflow on bright pixels |
| 4 | |
| 5 | precision highp float; |
| 6 | |
| 7 | in vec2 v_texcoord; |
| 8 | uniform sampler2D tex; |
| 9 | out vec4 fragColor; |
| 10 | |
| 11 | // W3C standard Sepia Matrix (column-major for GLSL) |
| 12 | const mat3 SEPIA_MATRIX = mat3( |
| 13 | 0.393, 0.769, 0.189, // Red output weights |
| 14 | 0.349, 0.686, 0.168, // Green output weights |
| 15 | 0.272, 0.534, 0.131 // Blue output weights |
| 16 | ); |
| 17 | |
| 18 | // Sepia intensity (0.0 = no effect, 1.0 = full sepia) |
| 19 | const float INTENSITY = 1.0; |
| 20 | |
| 21 | void main() { |
| 22 | vec4 color = texture(tex, v_texcoord); |
| 23 | |
| 24 | vec3 sepia = color.rgb * SEPIA_MATRIX; |
| 25 | |
| 26 | // FIXED: Clamp to prevent overflow artifacts on bright pixels |
| 27 | sepia = clamp(sepia, 0.0, 1.0); |
| 28 | |
| 29 | // Optional: blend with original for partial effect |
| 30 | vec3 final = mix(color.rgb, sepia, INTENSITY); |
| 31 | |
| 32 | fragColor = vec4(final, color.a); |
| 33 | } |