summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorDanny Lin <danny@kdrag0n.dev>2021-10-16 05:28:30 -0700
committeralk3pInjection <webmaster@raspii.tech>2022-05-05 00:39:05 +0800
commit2924fb0e9462b8768f90eace669884eb70a68e7a (patch)
tree022501cc5e559ea156d965a402aa258c363a8ca4 /core
parent4c0bd9813c378e9a167258962c2daba225834916 (diff)
display: Render screen-off fade animation in linear sRGB space
The sRGB transfer function is a piecewise function with linear and gamma 2.4 parts, not involving cosine or other magic constants. Fade colors in linear sRGB instead of non-linear sRGB + magic gamma to minimize color distortion as the animation progresses. Change-Id: I57db834f938cc63b7298af1c9dfe8c284dc6abe2
Diffstat (limited to 'core')
-rw-r--r--core/res/res/raw/color_fade_frag.frag34
1 files changed, 28 insertions, 6 deletions
diff --git a/core/res/res/raw/color_fade_frag.frag b/core/res/res/raw/color_fade_frag.frag
index 29975d5f7b5e..db0f63f2ee24 100644
--- a/core/res/res/raw/color_fade_frag.frag
+++ b/core/res/res/raw/color_fade_frag.frag
@@ -3,12 +3,34 @@
precision mediump float;
uniform samplerExternalOES texUnit;
uniform float opacity;
-uniform float gamma;
varying vec2 UV;
-void main()
-{
- vec4 color = texture2D(texUnit, UV);
- vec3 rgb = pow(color.rgb * opacity, vec3(gamma));
- gl_FragColor = vec4(rgb, 1.0);
+vec3 mixBvec3(vec3 a, vec3 b, bvec3 sel) {
+ return vec3(
+ sel.x ? b.x : a.x,
+ sel.y ? b.y : a.y,
+ sel.z ? b.z : a.z
+ );
+}
+
+vec3 srgbTransfer(vec3 c) {
+ vec3 gamma = 1.055 * pow(c, vec3(1.0/2.4)) - 0.055;
+ vec3 linear = 12.92 * c;
+ bvec3 selectParts = lessThan(c, vec3(0.0031308));
+ return mixBvec3(gamma, linear, selectParts);
+}
+
+vec3 srgbTransferInv(vec3 c) {
+ vec3 gamma = pow((c + 0.055)/1.055, vec3(2.4));
+ vec3 linear = c / 12.92;
+ bvec3 selectParts = lessThan(c, vec3(0.04045));
+ return mixBvec3(gamma, linear, selectParts);
+}
+
+void main() {
+ vec3 inRgb = srgbTransferInv(texture2D(texUnit, UV).rgb);
+ vec3 fade = inRgb * opacity * opacity;
+ vec3 outRgb = srgbTransfer(fade);
+
+ gl_FragColor = vec4(outRgb, 1.0);
}