tedit/shaders/contrast.frag
2025-04-07 20:08:16 -04:00

25 lines
778 B
GLSL

#version 330 core
out vec4 FragColor;
in vec2 TexCoord;
uniform sampler2D InputTexture;
uniform float contrastValue; // Expecting value e.g., -100 to 100
// Perceptually accurate contrast adjustment
vec3 applyContrast(vec3 color, float contrast) {
float factor = pow(2.0, contrast / 50.0); // Exponential scaling for more natural feel
// Use 0.18 as middle gray (photographic standard)
const vec3 midPoint = vec3(0.18);
// Apply contrast with proper pivot point
return midPoint + factor * (color - midPoint);
}
void main() {
vec4 color = texture(InputTexture, TexCoord);
color.rgb = applyContrast(color.rgb, contrastValue);
// Clamp results to valid range
FragColor = vec4(clamp(color.rgb, vec3(0.0), vec3(1.0)), color.a);
}