Fix colors in glium (srgb issue)

This commit is contained in:
Emil Ernerfeldt 2020-04-16 23:10:42 +02:00
parent 49cbd3fe07
commit 74eeaf27ce

View file

@ -41,8 +41,18 @@ impl Painter {
in vec4 v_color;
in vec2 v_tc;
out vec4 f_color;
// glium expects linear output.
vec3 linear_from_srgb(vec3 srgb) {
bvec3 cutoff = lessThan(srgb, vec3(0.04045));
vec3 higher = pow((srgb + vec3(0.055)) / vec3(1.055), vec3(2.4));
vec3 lower = srgb / vec3(12.92);
return mix(higher, lower, cutoff);
}
void main() {
f_color = v_color;
f_color.rgb = linear_from_srgb(f_color.rgb);
f_color.a *= texture(u_sampler, v_tc).r;
}
"
@ -74,8 +84,18 @@ impl Painter {
uniform sampler2D u_sampler;
varying vec4 v_color;
varying vec2 v_tc;
// glium expects linear output.
vec3 linear_from_srgb(vec3 srgb) {
bvec3 cutoff = lessThan(srgb, vec3(0.04045));
vec3 higher = pow((srgb + vec3(0.055)) / vec3(1.055), vec3(2.4));
vec3 lower = srgb / vec3(12.92);
return mix(higher, lower, cutoff);
}
void main() {
gl_FragColor = v_color;
gl_FragColor.rgb = linear_from_srgb(gl_FragColor.rgb);
gl_FragColor.a *= texture2D(u_sampler, v_tc).r;
}
",
@ -107,8 +127,18 @@ impl Painter {
uniform sampler2D u_sampler;
varying mediump vec4 v_color;
varying mediump vec2 v_tc;
// glium expects linear output.
vec3 linear_from_srgb(vec3 srgb) {
bvec3 cutoff = lessThan(srgb, vec3(0.04045));
vec3 higher = pow((srgb + vec3(0.055)) / vec3(1.055), vec3(2.4));
vec3 lower = srgb / vec3(12.92);
return mix(higher, lower, cutoff);
}
void main() {
gl_FragColor = v_color;
gl_FragColor.rgb = linear_from_srgb(gl_FragColor.rgb);
gl_FragColor.a *= texture2D(u_sampler, v_tc).r;
}
",