Krolyxon
Commit 096f55e

Branches

Refs →

aurora.confighyprshaders11_invert.glsl

30 lines · 812 B · GLSL

1#version 300 es
2// Invert Colors Shader - OPTIMIZED
3// Added: Optional luminance-preserving mode
4
5precision highp float;
6
7in vec2 v_texcoord;
8uniform sampler2D tex;
9out vec4 fragColor;
10
11// Set true for "smart invert" that preserves relative brightness
12const bool PRESERVE_LUMINANCE = false;
13const vec3 LUMA = vec3(0.2126, 0.7152, 0.0722);
14
15void main() {
16 vec4 color = texture(tex, v_texcoord);
17 vec3 inverted = 1.0 - color.rgb;
18
19 if (PRESERVE_LUMINANCE) {
20 // Adjust inverted colors to match original luminance
21 float origLuma = dot(color.rgb, LUMA);
22 float invLuma = dot(inverted, LUMA);
23 if (invLuma > 0.001) {
24 inverted *= origLuma / invLuma;
25 inverted = clamp(inverted, 0.0, 1.0);
26 }
27 }
28
29 fragColor = vec4(inverted, color.a);
30}