1 precision mediump float; 2 3 // The actual wallpaper texture. 4 uniform sampler2D uTexture; 5 6 // The 85th percenile for the luminance histogram of the image (a value between 0 and 1). 7 // This value represents the point in histogram that includes 85% of the pixels of the image. 8 uniform float uPer85; 9 10 // Reveal is the animation value that goes from 1 (the image is hidden) to 0 (the image is visible). 11 uniform float uReveal; 12 13 // The opacity of locked screen (constant value). 14 uniform float uAod2Opacity; 15 varying vec2 vTextureCoordinates; 16 17 /* 18 * Calculates the relative luminance of the pixel. 19 */ 20 vec3 luminosity(vec3 color) { 21 float lum = 0.2126 * color.r + 0.7152 * color.g + 0.0722 * color.b; 22 return vec3(lum); 23 } 24 25 vec4 transform(vec3 diffuse) { 26 // Getting the luminance for this pixel 27 vec3 lum = luminosity(diffuse); 28 29 /* 30 * while the reveal > per85, it shows the luminance image (B&W image) 31 * then when moving passed that value, the image gets colored. 32 */ 33 float trans = smoothstep(0., uPer85, uReveal); 34 diffuse = mix(diffuse, lum, trans); 35 36 // 'lower' value represents the capped 'reveal' value to the range [0, per85] 37 float selector = step(uPer85, uReveal); 38 float lower = mix(uReveal, uPer85, selector); 39 40 /* 41 * Remaps image: 42 * - from reveal=1 to reveal=per85 => lower=per85, diffuse=luminance 43 * That means that remaps black and white image pixel 44 * from a possible values of [0,1] to [per85, 1] (if the pixel is darker than per85, 45 * it's gonna be black, if it's between per85 and 1, it's gonna be gray 46 * and if it's 1 it's gonna be white). 47 * - from reveal=per85 to reveal=0 => lower=reveal, 'diffuse' changes from luminance to color 48 * That means that remaps each image pixel color (rgb) 49 * from a possible values of [0,1] to [lower, 1] (if the pixel color is darker than 'lower', 50 * it's gonna be 0, if it's between 'lower' and 1, it's gonna be remap to a value 51 * between 0 and 1 and if it's 1 it's gonna be 1). 52 * - if reveal=0 => lower=0, diffuse=color image 53 * The image is shown as it is, colored. 54 */ 55 vec3 remaps = smoothstep(lower, 1., diffuse); 56 57 // Interpolate between diffuse and remaps using reveal to avoid over saturation. 58 diffuse = mix(diffuse, remaps, uReveal); 59 60 /* 61 * Fades in the pixel value: 62 * - if reveal=1 => fadeInOpacity=0 63 * - from reveal=1 to reveal=per85 => 0<=fadeInOpacity<=1 64 * - if reveal>per85 => fadeInOpacity=1 65 */ 66 float fadeInOpacity = 1. - smoothstep(uPer85, 1., uReveal); 67 diffuse *= uAod2Opacity * fadeInOpacity; 68 69 return vec4(diffuse.r, diffuse.g, diffuse.b, 1.); 70 } 71 72 void main() { 73 // gets the pixel value of the wallpaper for this uv coordinates on screen. 74 vec4 fragColor = texture2D(uTexture, vTextureCoordinates); 75 gl_FragColor = transform(fragColor.rgb); 76 }