diff --git a/egui_glium/src/shader/fragment_100es.glsl b/egui_glium/src/shader/fragment_100es.glsl index bd3f6519..29878191 100644 --- a/egui_glium/src/shader/fragment_100es.glsl +++ b/egui_glium/src/shader/fragment_100es.glsl @@ -7,39 +7,39 @@ varying vec2 v_tc; // 0-255 sRGB from 0-1 linear vec3 srgb_from_linear(vec3 rgb) { - bvec3 cutoff = lessThan(rgb, vec3(0.0031308)); - vec3 lower = rgb * vec3(3294.6); - vec3 higher = vec3(269.025) * pow(rgb, vec3(1.0 / 2.4)) - vec3(14.025); - return mix(higher, lower, vec3(cutoff)); + bvec3 cutoff = lessThan(rgb, vec3(0.0031308)); + vec3 lower = rgb * vec3(3294.6); + vec3 higher = vec3(269.025) * pow(rgb, vec3(1.0 / 2.4)) - vec3(14.025); + return mix(higher, lower, vec3(cutoff)); } vec4 srgba_from_linear(vec4 rgba) { - return vec4(srgb_from_linear(rgba.rgb), 255.0 * rgba.a); + return vec4(srgb_from_linear(rgba.rgb), 255.0 * rgba.a); } // 0-1 linear from 0-255 sRGB vec3 linear_from_srgb(vec3 srgb) { - bvec3 cutoff = lessThan(srgb, vec3(10.31475)); - vec3 lower = srgb / vec3(3294.6); - vec3 higher = pow((srgb + vec3(14.025)) / vec3(269.025), vec3(2.4)); - return mix(higher, lower, vec3(cutoff)); + bvec3 cutoff = lessThan(srgb, vec3(10.31475)); + vec3 lower = srgb / vec3(3294.6); + vec3 higher = pow((srgb + vec3(14.025)) / vec3(269.025), vec3(2.4)); + return mix(higher, lower, vec3(cutoff)); } vec4 linear_from_srgba(vec4 srgba) { - return vec4(linear_from_srgb(srgba.rgb), srgba.a / 255.0); + return vec4(linear_from_srgb(srgba.rgb), srgba.a / 255.0); } void main() { - // We must decode the colors, since WebGL doesn't come with sRGBA textures: - vec4 texture_rgba = linear_from_srgba(texture2D(u_sampler, v_tc) * 255.0); + // We must decode the colors, since WebGL doesn't come with sRGBA textures: + vec4 texture_rgba = linear_from_srgba(texture2D(u_sampler, v_tc) * 255.0); - /// Multiply vertex color with texture color (in linear space). - gl_FragColor = v_rgba * texture_rgba; + /// Multiply vertex color with texture color (in linear space). + gl_FragColor = v_rgba * texture_rgba; - // We must gamma-encode again since WebGL doesn't support linear blending in the framebuffer. - gl_FragColor = srgba_from_linear(v_rgba * texture_rgba) / 255.0; + // We must gamma-encode again since WebGL doesn't support linear blending in the framebuffer. + gl_FragColor = srgba_from_linear(v_rgba * texture_rgba) / 255.0; - // WebGL doesn't support linear blending in the framebuffer, - // so we apply this hack to at least get a bit closer to the desired blending: - gl_FragColor.a = pow(gl_FragColor.a, 1.6); // Empiric nonsense + // WebGL doesn't support linear blending in the framebuffer, + // so we apply this hack to at least get a bit closer to the desired blending: + gl_FragColor.a = pow(gl_FragColor.a, 1.6); // Empiric nonsense } diff --git a/egui_glium/src/shader/fragment_120.glsl b/egui_glium/src/shader/fragment_120.glsl index f7e8e3dc..6cd250df 100644 --- a/egui_glium/src/shader/fragment_120.glsl +++ b/egui_glium/src/shader/fragment_120.glsl @@ -5,7 +5,7 @@ varying vec4 v_rgba; varying vec2 v_tc; void main() { - // The texture sampler is sRGB aware, and glium already expects linear rgba output - // so no need for any sRGB conversions here: - gl_FragColor = v_rgba * texture2D(u_sampler, v_tc); + // The texture sampler is sRGB aware, and glium already expects linear rgba output + // so no need for any sRGB conversions here: + gl_FragColor = v_rgba * texture2D(u_sampler, v_tc); } diff --git a/egui_glium/src/shader/fragment_140.glsl b/egui_glium/src/shader/fragment_140.glsl index cad0bac1..f2e38ccd 100644 --- a/egui_glium/src/shader/fragment_140.glsl +++ b/egui_glium/src/shader/fragment_140.glsl @@ -6,7 +6,7 @@ in vec2 v_tc; out vec4 f_color; void main() { - // The texture sampler is sRGB aware, and glium already expects linear rgba output - // so no need for any sRGB conversions here: - f_color = v_rgba * texture(u_sampler, v_tc); + // The texture sampler is sRGB aware, and glium already expects linear rgba output + // so no need for any sRGB conversions here: + f_color = v_rgba * texture(u_sampler, v_tc); } diff --git a/egui_glium/src/shader/fragment_300es.glsl b/egui_glium/src/shader/fragment_300es.glsl index 65b37c9b..509c0a12 100644 --- a/egui_glium/src/shader/fragment_300es.glsl +++ b/egui_glium/src/shader/fragment_300es.glsl @@ -7,27 +7,27 @@ varying vec2 v_tc; // 0-255 sRGB from 0-1 linear vec3 srgb_from_linear(vec3 rgb) { - bvec3 cutoff = lessThan(rgb, vec3(0.0031308)); - vec3 lower = rgb * vec3(3294.6); - vec3 higher = vec3(269.025) * pow(rgb, vec3(1.0 / 2.4)) - vec3(14.025); - return mix(higher, lower, vec3(cutoff)); + bvec3 cutoff = lessThan(rgb, vec3(0.0031308)); + vec3 lower = rgb * vec3(3294.6); + vec3 higher = vec3(269.025) * pow(rgb, vec3(1.0 / 2.4)) - vec3(14.025); + return mix(higher, lower, vec3(cutoff)); } vec4 srgba_from_linear(vec4 rgba) { - return vec4(srgb_from_linear(rgba.rgb), 255.0 * rgba.a); + return vec4(srgb_from_linear(rgba.rgb), 255.0 * rgba.a); } void main() { - // The texture is set up with `SRGB8_ALPHA8`, so no need to decode here! - vec4 texture_rgba = texture2D(u_sampler, v_tc); + // The texture is set up with `SRGB8_ALPHA8`, so no need to decode here! + vec4 texture_rgba = texture2D(u_sampler, v_tc); - /// Multiply vertex color with texture color (in linear space). - gl_FragColor = v_rgba * texture_rgba; + /// Multiply vertex color with texture color (in linear space). + gl_FragColor = v_rgba * texture_rgba; - // We must gamma-encode again since WebGL doesn't support linear blending in the framebuffer. - gl_FragColor = srgba_from_linear(v_rgba * texture_rgba) / 255.0; + // We must gamma-encode again since WebGL doesn't support linear blending in the framebuffer. + gl_FragColor = srgba_from_linear(v_rgba * texture_rgba) / 255.0; - // WebGL doesn't support linear blending in the framebuffer, - // so we apply this hack to at least get a bit closer to the desired blending: - gl_FragColor.a = pow(gl_FragColor.a, 1.6); // Empiric nonsense + // WebGL doesn't support linear blending in the framebuffer, + // so we apply this hack to at least get a bit closer to the desired blending: + gl_FragColor.a = pow(gl_FragColor.a, 1.6); // Empiric nonsense } diff --git a/egui_glium/src/shader/vertex_100es.glsl b/egui_glium/src/shader/vertex_100es.glsl index d1581d9f..a0332888 100644 --- a/egui_glium/src/shader/vertex_100es.glsl +++ b/egui_glium/src/shader/vertex_100es.glsl @@ -10,23 +10,23 @@ varying vec2 v_tc; // 0-1 linear from 0-255 sRGB vec3 linear_from_srgb(vec3 srgb) { - bvec3 cutoff = lessThan(srgb, vec3(10.31475)); - vec3 lower = srgb / vec3(3294.6); - vec3 higher = pow((srgb + vec3(14.025)) / vec3(269.025), vec3(2.4)); - return mix(higher, lower, vec3(cutoff)); + bvec3 cutoff = lessThan(srgb, vec3(10.31475)); + vec3 lower = srgb / vec3(3294.6); + vec3 higher = pow((srgb + vec3(14.025)) / vec3(269.025), vec3(2.4)); + return mix(higher, lower, vec3(cutoff)); } vec4 linear_from_srgba(vec4 srgba) { - return vec4(linear_from_srgb(srgba.rgb), srgba.a / 255.0); + return vec4(linear_from_srgb(srgba.rgb), srgba.a / 255.0); } void main() { - gl_Position = vec4( - 2.0 * a_pos.x / u_screen_size.x - 1.0, - 1.0 - 2.0 * a_pos.y / u_screen_size.y, - 0.0, - 1.0); - // egui encodes vertex colors in gamma spaces, so we must decode the colors here: - v_rgba = linear_from_srgba(a_srgba); - v_tc = a_tc; + gl_Position = vec4( + 2.0 * a_pos.x / u_screen_size.x - 1.0, + 1.0 - 2.0 * a_pos.y / u_screen_size.y, + 0.0, + 1.0); + // egui encodes vertex colors in gamma spaces, so we must decode the colors here: + v_rgba = linear_from_srgba(a_srgba); + v_tc = a_tc; } diff --git a/egui_glium/src/shader/vertex_120.glsl b/egui_glium/src/shader/vertex_120.glsl index 8f419314..ef04ef76 100644 --- a/egui_glium/src/shader/vertex_120.glsl +++ b/egui_glium/src/shader/vertex_120.glsl @@ -9,23 +9,23 @@ varying vec2 v_tc; // 0-1 linear from 0-255 sRGB vec3 linear_from_srgb(vec3 srgb) { - bvec3 cutoff = lessThan(srgb, vec3(10.31475)); - vec3 lower = srgb / vec3(3294.6); - vec3 higher = pow((srgb + vec3(14.025)) / vec3(269.025), vec3(2.4)); - return mix(higher, lower, vec3(cutoff)); + bvec3 cutoff = lessThan(srgb, vec3(10.31475)); + vec3 lower = srgb / vec3(3294.6); + vec3 higher = pow((srgb + vec3(14.025)) / vec3(269.025), vec3(2.4)); + return mix(higher, lower, vec3(cutoff)); } vec4 linear_from_srgba(vec4 srgba) { - return vec4(linear_from_srgb(srgba.rgb), srgba.a / 255.0); + return vec4(linear_from_srgb(srgba.rgb), srgba.a / 255.0); } void main() { - gl_Position = vec4( - 2.0 * a_pos.x / u_screen_size.x - 1.0, - 1.0 - 2.0 * a_pos.y / u_screen_size.y, - 0.0, - 1.0); - // egui encodes vertex colors in gamma spaces, so we must decode the colors here: - v_rgba = linear_from_srgba(a_srgba); - v_tc = a_tc; + gl_Position = vec4( + 2.0 * a_pos.x / u_screen_size.x - 1.0, + 1.0 - 2.0 * a_pos.y / u_screen_size.y, + 0.0, + 1.0); + // egui encodes vertex colors in gamma spaces, so we must decode the colors here: + v_rgba = linear_from_srgba(a_srgba); + v_tc = a_tc; } diff --git a/egui_glium/src/shader/vertex_140.glsl b/egui_glium/src/shader/vertex_140.glsl index c1b9054e..c3a5b798 100644 --- a/egui_glium/src/shader/vertex_140.glsl +++ b/egui_glium/src/shader/vertex_140.glsl @@ -9,23 +9,23 @@ out vec2 v_tc; // 0-1 linear from 0-255 sRGB vec3 linear_from_srgb(vec3 srgb) { - bvec3 cutoff = lessThan(srgb, vec3(10.31475)); - vec3 lower = srgb / vec3(3294.6); - vec3 higher = pow((srgb + vec3(14.025)) / vec3(269.025), vec3(2.4)); - return mix(higher, lower, cutoff); + bvec3 cutoff = lessThan(srgb, vec3(10.31475)); + vec3 lower = srgb / vec3(3294.6); + vec3 higher = pow((srgb + vec3(14.025)) / vec3(269.025), vec3(2.4)); + return mix(higher, lower, cutoff); } vec4 linear_from_srgba(vec4 srgba) { - return vec4(linear_from_srgb(srgba.rgb), srgba.a / 255.0); + return vec4(linear_from_srgb(srgba.rgb), srgba.a / 255.0); } void main() { - gl_Position = vec4( - 2.0 * a_pos.x / u_screen_size.x - 1.0, - 1.0 - 2.0 * a_pos.y / u_screen_size.y, - 0.0, - 1.0); - // egui encodes vertex colors in gamma spaces, so we must decode the colors here: - v_rgba = linear_from_srgba(a_srgba); - v_tc = a_tc; + gl_Position = vec4( + 2.0 * a_pos.x / u_screen_size.x - 1.0, + 1.0 - 2.0 * a_pos.y / u_screen_size.y, + 0.0, + 1.0); + // egui encodes vertex colors in gamma spaces, so we must decode the colors here: + v_rgba = linear_from_srgba(a_srgba); + v_tc = a_tc; } diff --git a/egui_glium/src/shader/vertex_300es.glsl b/egui_glium/src/shader/vertex_300es.glsl index f587b2e3..0cf5dc11 100644 --- a/egui_glium/src/shader/vertex_300es.glsl +++ b/egui_glium/src/shader/vertex_300es.glsl @@ -10,23 +10,23 @@ varying vec2 v_tc; // 0-1 linear from 0-255 sRGB vec3 linear_from_srgb(vec3 srgb) { - bvec3 cutoff = lessThan(srgb, vec3(10.31475)); - vec3 lower = srgb / vec3(3294.6); - vec3 higher = pow((srgb + vec3(14.025)) / vec3(269.025), vec3(2.4)); - return mix(higher, lower, vec3(cutoff)); + bvec3 cutoff = lessThan(srgb, vec3(10.31475)); + vec3 lower = srgb / vec3(3294.6); + vec3 higher = pow((srgb + vec3(14.025)) / vec3(269.025), vec3(2.4)); + return mix(higher, lower, vec3(cutoff)); } vec4 linear_from_srgba(vec4 srgba) { - return vec4(linear_from_srgb(srgba.rgb), srgba.a / 255.0); + return vec4(linear_from_srgb(srgba.rgb), srgba.a / 255.0); } void main() { - gl_Position = vec4( - 2.0 * a_pos.x / u_screen_size.x - 1.0, - 1.0 - 2.0 * a_pos.y / u_screen_size.y, - 0.0, - 1.0); - // egui encodes vertex colors in gamma spaces, so we must decode the colors here: - v_rgba = linear_from_srgba(a_srgba); - v_tc = a_tc; + gl_Position = vec4( + 2.0 * a_pos.x / u_screen_size.x - 1.0, + 1.0 - 2.0 * a_pos.y / u_screen_size.y, + 0.0, + 1.0); + // egui encodes vertex colors in gamma spaces, so we must decode the colors here: + v_rgba = linear_from_srgba(a_srgba); + v_tc = a_tc; } diff --git a/egui_glow/src/shader/fragment.glsl b/egui_glow/src/shader/fragment.glsl index 288cdf0c..9760c4ef 100644 --- a/egui_glow/src/shader/fragment.glsl +++ b/egui_glow/src/shader/fragment.glsl @@ -1,77 +1,76 @@ #ifdef GL_ES -precision mediump float; + precision mediump float; #endif uniform sampler2D u_sampler; #ifdef NEW_SHADER_INTERFACE -in vec4 v_rgba; -in vec2 v_tc; -out vec4 f_color; -// a dirty hack applied to support webGL2 -#define gl_FragColor f_color -#define texture2D texture + in vec4 v_rgba; + in vec2 v_tc; + out vec4 f_color; + // a dirty hack applied to support webGL2 + #define gl_FragColor f_color + #define texture2D texture #else -varying vec4 v_rgba; -varying vec2 v_tc; + varying vec4 v_rgba; + varying vec2 v_tc; #endif -#ifndef SRGB_SUPPORTED -// 0-255 sRGB from 0-1 linear -vec3 srgb_from_linear(vec3 rgb) { - bvec3 cutoff = lessThan(rgb, vec3(0.0031308)); - vec3 lower = rgb * vec3(3294.6); - vec3 higher = vec3(269.025) * pow(rgb, vec3(1.0 / 2.4)) - vec3(14.025); - return mix(higher, lower, vec3(cutoff)); -} - -vec4 srgba_from_linear(vec4 rgba) { - return vec4(srgb_from_linear(rgba.rgb), 255.0 * rgba.a); -} -// 0-1 linear from 0-255 sRGB -vec3 linear_from_srgb(vec3 srgb) { - bvec3 cutoff = lessThan(srgb, vec3(10.31475)); - vec3 lower = srgb / vec3(3294.6); - vec3 higher = pow((srgb + vec3(14.025)) / vec3(269.025), vec3(2.4)); - return mix(higher, lower, vec3(cutoff)); -} - -vec4 linear_from_srgba(vec4 srgba) { - return vec4(linear_from_srgb(srgba.rgb), srgba.a / 255.0); -} - -void main() { - // We must decode the colors, since WebGL doesn't come with sRGBA textures: - vec4 texture_rgba = linear_from_srgba(texture2D(u_sampler, v_tc) * 255.0); - /// Multiply vertex color with texture color (in linear space). - gl_FragColor = v_rgba * texture_rgba; - - // WebGL doesn't support linear blending in the framebuffer, - // so we do a hack here where we change the premultiplied alpha - // to do the multiplication in gamma space instead: - - // Unmultiply alpha: - if (gl_FragColor.a > 0.0) { - gl_FragColor.rgb /= gl_FragColor.a; +#ifdef SRGB_SUPPORTED + void main() { + // The texture sampler is sRGB aware, and OpenGL already expects linear rgba output + // so no need for any sRGB conversions here: + gl_FragColor = v_rgba * texture2D(u_sampler, v_tc); } +#else + // 0-255 sRGB from 0-1 linear + vec3 srgb_from_linear(vec3 rgb) { + bvec3 cutoff = lessThan(rgb, vec3(0.0031308)); + vec3 lower = rgb * vec3(3294.6); + vec3 higher = vec3(269.025) * pow(rgb, vec3(1.0 / 2.4)) - vec3(14.025); + return mix(higher, lower, vec3(cutoff)); + } + + vec4 srgba_from_linear(vec4 rgba) { + return vec4(srgb_from_linear(rgba.rgb), 255.0 * rgba.a); + } + + // 0-1 linear from 0-255 sRGB + vec3 linear_from_srgb(vec3 srgb) { + bvec3 cutoff = lessThan(srgb, vec3(10.31475)); + vec3 lower = srgb / vec3(3294.6); + vec3 higher = pow((srgb + vec3(14.025)) / vec3(269.025), vec3(2.4)); + return mix(higher, lower, vec3(cutoff)); + } + + vec4 linear_from_srgba(vec4 srgba) { + return vec4(linear_from_srgb(srgba.rgb), srgba.a / 255.0); + } + + void main() { + // We must decode the colors, since WebGL1 doesn't come with sRGBA textures: + vec4 texture_rgba = linear_from_srgba(texture2D(u_sampler, v_tc) * 255.0); + /// Multiply vertex color with texture color (in linear space). + gl_FragColor = v_rgba * texture_rgba; + + // WebGL1 doesn't support linear blending in the framebuffer, + // so we do a hack here where we change the premultiplied alpha + // to do the multiplication in gamma space instead: + + // Unmultiply alpha: + if (gl_FragColor.a > 0.0) { + gl_FragColor.rgb /= gl_FragColor.a; + } // Empiric tweak to make e.g. shadows look more like they should: gl_FragColor.a *= sqrt(gl_FragColor.a); - // To gamma: - gl_FragColor = srgba_from_linear(gl_FragColor) / 255.0; + // To gamma: + gl_FragColor = srgba_from_linear(gl_FragColor) / 255.0; - // Premultiply alpha, this time in gamma space: - if (gl_FragColor.a > 0.0) { - gl_FragColor.rgb *= gl_FragColor.a; + // Premultiply alpha, this time in gamma space: + if (gl_FragColor.a > 0.0) { + gl_FragColor.rgb *= gl_FragColor.a; + } } -} - #else -void main() { - // The texture sampler is sRGB aware, and OpenGL already expects linear rgba output - // so no need for any sRGB conversions here: - - gl_FragColor = v_rgba * texture2D(u_sampler, v_tc); - -} - #endif +#endif diff --git a/egui_glow/src/shader/vertex.glsl b/egui_glow/src/shader/vertex.glsl index 15ea4c26..43a3b6b3 100644 --- a/egui_glow/src/shader/vertex.glsl +++ b/egui_glow/src/shader/vertex.glsl @@ -1,16 +1,17 @@ #ifdef NEW_SHADER_INTERFACE -#define I in -#define O out -#define V(x) x + #define I in + #define O out + #define V(x) x #else -#define I attribute -#define O varying -#define V(x) vec3(x) + #define I attribute + #define O varying + #define V(x) vec3(x) #endif #ifdef GL_ES -precision mediump float; + precision mediump float; #endif + uniform vec2 u_screen_size; I vec2 a_pos; I vec4 a_srgba; // 0-255 sRGB @@ -20,23 +21,23 @@ O vec2 v_tc; // 0-1 linear from 0-255 sRGB vec3 linear_from_srgb(vec3 srgb) { - bvec3 cutoff = lessThan(srgb, vec3(10.31475)); - vec3 lower = srgb / vec3(3294.6); - vec3 higher = pow((srgb + vec3(14.025)) / vec3(269.025), vec3(2.4)); - return mix(higher, lower, V(cutoff)); + bvec3 cutoff = lessThan(srgb, vec3(10.31475)); + vec3 lower = srgb / vec3(3294.6); + vec3 higher = pow((srgb + vec3(14.025)) / vec3(269.025), vec3(2.4)); + return mix(higher, lower, V(cutoff)); } vec4 linear_from_srgba(vec4 srgba) { - return vec4(linear_from_srgb(srgba.rgb), srgba.a / 255.0); + return vec4(linear_from_srgb(srgba.rgb), srgba.a / 255.0); } void main() { - gl_Position = vec4( - 2.0 * a_pos.x / u_screen_size.x - 1.0, - 1.0 - 2.0 * a_pos.y / u_screen_size.y, - 0.0, - 1.0); - // egui encodes vertex colors in gamma spaces, so we must decode the colors here: - v_rgba = linear_from_srgba(a_srgba); - v_tc = a_tc; + gl_Position = vec4( + 2.0 * a_pos.x / u_screen_size.x - 1.0, + 1.0 - 2.0 * a_pos.y / u_screen_size.y, + 0.0, + 1.0); + // egui encodes vertex colors in gamma space, so we must decode the colors here: + v_rgba = linear_from_srgba(a_srgba); + v_tc = a_tc; } diff --git a/egui_web/src/shader/fragment_100es.glsl b/egui_web/src/shader/fragment_100es.glsl index 5b45edf2..ef6a2870 100644 --- a/egui_web/src/shader/fragment_100es.glsl +++ b/egui_web/src/shader/fragment_100es.glsl @@ -5,54 +5,54 @@ varying vec2 v_tc; // 0-255 sRGB from 0-1 linear vec3 srgb_from_linear(vec3 rgb) { - bvec3 cutoff = lessThan(rgb, vec3(0.0031308)); - vec3 lower = rgb * vec3(3294.6); - vec3 higher = vec3(269.025) * pow(rgb, vec3(1.0 / 2.4)) - vec3(14.025); - return mix(higher, lower, vec3(cutoff)); + bvec3 cutoff = lessThan(rgb, vec3(0.0031308)); + vec3 lower = rgb * vec3(3294.6); + vec3 higher = vec3(269.025) * pow(rgb, vec3(1.0 / 2.4)) - vec3(14.025); + return mix(higher, lower, vec3(cutoff)); } // 0-255 sRGB from 0-1 linear vec4 srgba_from_linear(vec4 rgba) { - return vec4(srgb_from_linear(rgba.rgb), 255.0 * rgba.a); + return vec4(srgb_from_linear(rgba.rgb), 255.0 * rgba.a); } // 0-1 linear from 0-255 sRGB vec3 linear_from_srgb(vec3 srgb) { - bvec3 cutoff = lessThan(srgb, vec3(10.31475)); - vec3 lower = srgb / vec3(3294.6); - vec3 higher = pow((srgb + vec3(14.025)) / vec3(269.025), vec3(2.4)); - return mix(higher, lower, vec3(cutoff)); + bvec3 cutoff = lessThan(srgb, vec3(10.31475)); + vec3 lower = srgb / vec3(3294.6); + vec3 higher = pow((srgb + vec3(14.025)) / vec3(269.025), vec3(2.4)); + return mix(higher, lower, vec3(cutoff)); } // 0-1 linear from 0-255 sRGBA vec4 linear_from_srgba(vec4 srgba) { - return vec4(linear_from_srgb(srgba.rgb), srgba.a / 255.0); + return vec4(linear_from_srgb(srgba.rgb), srgba.a / 255.0); } void main() { - // We must decode the colors, since WebGL1 doesn't come with sRGBA textures: - vec4 texture_rgba = linear_from_srgba(texture2D(u_sampler, v_tc) * 255.0); + // We must decode the colors, since WebGL1 doesn't come with sRGBA textures: + vec4 texture_rgba = linear_from_srgba(texture2D(u_sampler, v_tc) * 255.0); - /// Multiply vertex color with texture color (in linear space). - gl_FragColor = v_rgba * texture_rgba; + /// Multiply vertex color with texture color (in linear space). + gl_FragColor = v_rgba * texture_rgba; - // WebGL doesn't support linear blending in the framebuffer, - // so we do a hack here where we change the premultiplied alpha - // to do the multiplication in gamma space instead: + // WebGL doesn't support linear blending in the framebuffer, + // so we do a hack here where we change the premultiplied alpha + // to do the multiplication in gamma space instead: - // Unmultiply alpha: - if (gl_FragColor.a > 0.0) { - gl_FragColor.rgb /= gl_FragColor.a; - } + // Unmultiply alpha: + if (gl_FragColor.a > 0.0) { + gl_FragColor.rgb /= gl_FragColor.a; + } - // Empiric tweak to make e.g. shadows look more like they should: - gl_FragColor.a *= sqrt(gl_FragColor.a); + // Empiric tweak to make e.g. shadows look more like they should: + gl_FragColor.a *= sqrt(gl_FragColor.a); - // To gamma: - gl_FragColor = srgba_from_linear(gl_FragColor) / 255.0; + // To gamma: + gl_FragColor = srgba_from_linear(gl_FragColor) / 255.0; - // Premultiply alpha, this time in gamma space: - if (gl_FragColor.a > 0.0) { - gl_FragColor.rgb *= gl_FragColor.a; - } + // Premultiply alpha, this time in gamma space: + if (gl_FragColor.a > 0.0) { + gl_FragColor.rgb *= gl_FragColor.a; + } } diff --git a/egui_web/src/shader/main_fragment_100es.glsl b/egui_web/src/shader/main_fragment_100es.glsl index 4dc0eb63..d1c45dcf 100644 --- a/egui_web/src/shader/main_fragment_100es.glsl +++ b/egui_web/src/shader/main_fragment_100es.glsl @@ -4,10 +4,10 @@ varying vec4 v_rgba; varying vec2 v_tc; void main() { - // The texture is set up with `SRGB8_ALPHA8`, so no need to decode here! - vec4 texture_rgba = texture2D(u_sampler, v_tc); + // The texture is set up with `SRGB8_ALPHA8`, so no need to decode here! + vec4 texture_rgba = texture2D(u_sampler, v_tc); - // Multiply vertex color with texture color (in linear space). - // Linear color is written and blended in Framebuffer and converted to sRGB later - gl_FragColor = v_rgba * texture_rgba; + // Multiply vertex color with texture color (in linear space). + // Linear color is written and blended in Framebuffer and converted to sRGB later + gl_FragColor = v_rgba * texture_rgba; } diff --git a/egui_web/src/shader/main_vertex_100es.glsl b/egui_web/src/shader/main_vertex_100es.glsl index c45c628d..002c06da 100644 --- a/egui_web/src/shader/main_vertex_100es.glsl +++ b/egui_web/src/shader/main_vertex_100es.glsl @@ -8,24 +8,24 @@ varying vec2 v_tc; // 0-1 linear from 0-255 sRGB vec3 linear_from_srgb(vec3 srgb) { - bvec3 cutoff = lessThan(srgb, vec3(10.31475)); - vec3 lower = srgb / vec3(3294.6); - vec3 higher = pow((srgb + vec3(14.025)) / vec3(269.025), vec3(2.4)); - return mix(higher, lower, vec3(cutoff)); + bvec3 cutoff = lessThan(srgb, vec3(10.31475)); + vec3 lower = srgb / vec3(3294.6); + vec3 higher = pow((srgb + vec3(14.025)) / vec3(269.025), vec3(2.4)); + return mix(higher, lower, vec3(cutoff)); } // 0-1 linear from 0-255 sRGBA vec4 linear_from_srgba(vec4 srgba) { - return vec4(linear_from_srgb(srgba.rgb), srgba.a / 255.0); + return vec4(linear_from_srgb(srgba.rgb), srgba.a / 255.0); } void main() { - gl_Position = vec4( - 2.0 * a_pos.x / u_screen_size.x - 1.0, - 1.0 - 2.0 * a_pos.y / u_screen_size.y, - 0.0, - 1.0); - // egui encodes vertex colors in gamma spaces, so we must decode the colors here: - v_rgba = linear_from_srgba(a_srgba); - v_tc = a_tc; + gl_Position = vec4( + 2.0 * a_pos.x / u_screen_size.x - 1.0, + 1.0 - 2.0 * a_pos.y / u_screen_size.y, + 0.0, + 1.0); + // egui encodes vertex colors in gamma spaces, so we must decode the colors here: + v_rgba = linear_from_srgba(a_srgba); + v_tc = a_tc; }