Ahan Wu | 9a8e260 | 2019-01-14 20:38:14 +0800 | [diff] [blame] | 1 | precision mediump float; |
| 2 | |
| 3 | uniform sampler2D uTexture; |
| 4 | uniform float uCenterReveal; |
| 5 | uniform float uReveal; |
| 6 | uniform float uAod2Opacity; |
| 7 | uniform int uAodMode; |
| 8 | varying vec2 vTextureCoordinates; |
| 9 | |
| 10 | vec3 luminosity(vec3 color) { |
| 11 | float lum = 0.2126 * color.r + 0.7152 * color.g + 0.0722 * color.b; |
| 12 | return vec3(lum); |
| 13 | } |
| 14 | |
| 15 | vec4 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 | |
| 25 | void 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 | } |