tile-flip.fs 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*
  2. * Copyright (c) 2012 Adobe Systems Incorporated. All rights reserved.
  3. * Copyright (c) 2012 Branislav Ulicny
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. precision mediump float;
  18. // Uniform values from CSS
  19. uniform float amount;
  20. uniform float tileOutline;
  21. // Built-in uniforms
  22. uniform vec2 u_meshSize;
  23. uniform vec2 u_textureSize;
  24. // Varyings passed in from vertex shader
  25. varying float v_depth;
  26. varying vec2 v_uv;
  27. // Main
  28. void main()
  29. {
  30. // FIXME: Must swap x and y as a workaround for:
  31. // https://bugs.webkit.org/show_bug.cgi?id=96285
  32. vec2 u_meshSize = u_meshSize.yx;
  33. vec4 c = vec4(1.0);
  34. // Fade out.
  35. c.a = 1.0 - v_depth;
  36. // Show grid outline.
  37. if (tileOutline >= 0.5) {
  38. float cell_width = u_textureSize.x / u_meshSize.y;
  39. float cell_height = u_textureSize.y / u_meshSize.x;
  40. float dd = 1.0;
  41. if (mod(v_uv.x * u_textureSize.x + dd, cell_width) < 2.0
  42. || mod(v_uv.y * u_textureSize.y + dd, cell_height) < 2.0) {
  43. if (amount > 0.0)
  44. c.rgb = vec3(1.0 - sqrt(amount));
  45. }
  46. }
  47. css_ColorMatrix = mat4(c.r, 0.0, 0.0, 0.0,
  48. 0.0, c.g, 0.0, 0.0,
  49. 0.0, 0.0, c.b, 0.0,
  50. 0.0, 0.0, 0.0, c.a);
  51. }