blob: 11d73a93ad04cfb1901435ffd24eaa997117a662 [file] [log] [blame]
Ahan Wu9a8e2602019-01-14 20:38:14 +08001precision mediump float;
2
3uniform sampler2D uTexture;
4uniform float uCenterReveal;
5uniform float uReveal;
6uniform float uAod2Opacity;
7uniform int uAodMode;
8varying vec2 vTextureCoordinates;
9
10vec3 luminosity(vec3 color) {
11 float lum = 0.2126 * color.r + 0.7152 * color.g + 0.0722 * color.b;
12 return vec3(lum);
13}
14
15vec4 transform(vec3 diffuse) {
16 // TODO: Add well comments here, tracking on b/123615467.
17 vec3 lum = luminosity(diffuse);
18 diffuse = mix(diffuse, lum, smoothstep(0., uCenterReveal, uReveal));
19 float val = mix(uReveal, uCenterReveal, step(uCenterReveal, uReveal));
20 diffuse = smoothstep(val, 1.0, diffuse);
21 diffuse *= uAod2Opacity * (1. - smoothstep(uCenterReveal, 1., uReveal));
22 return vec4(diffuse.r, diffuse.g, diffuse.b, 1.);
23}
24
25void main() {
26 vec4 fragColor = texture2D(uTexture, vTextureCoordinates);
27 // TODO: Remove the branch logic here, tracking on b/123615467.
28 if (uAodMode != 0) {
29 gl_FragColor = transform(fragColor.rgb);
30 } else {
31 gl_FragColor = fragColor;
32 }
33}