HorizontalTiltShiftShader.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /**
  2. * @author alteredq / http://alteredqualia.com/
  3. *
  4. * Simple fake tilt-shift effect, modulating two pass Gaussian blur (see above) by vertical position
  5. *
  6. * - 9 samples per pass
  7. * - standard deviation 2.7
  8. * - "h" and "v" parameters should be set to "1 / width" and "1 / height"
  9. * - "r" parameter control where "focused" horizontal line lies
  10. */
  11. THREE.HorizontalTiltShiftShader = {
  12. uniforms: {
  13. "tDiffuse": { value: null },
  14. "h": { value: 1.0 / 512.0 },
  15. "r": { value: 0.35 }
  16. },
  17. vertexShader: [
  18. "varying vec2 vUv;",
  19. "void main() {",
  20. "vUv = uv;",
  21. "gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
  22. "}"
  23. ].join( "\n" ),
  24. fragmentShader: [
  25. "uniform sampler2D tDiffuse;",
  26. "uniform float h;",
  27. "uniform float r;",
  28. "varying vec2 vUv;",
  29. "void main() {",
  30. "vec4 sum = vec4( 0.0 );",
  31. "float hh = h * abs( r - vUv.y );",
  32. "sum += texture2D( tDiffuse, vec2( vUv.x - 4.0 * hh, vUv.y ) ) * 0.051;",
  33. "sum += texture2D( tDiffuse, vec2( vUv.x - 3.0 * hh, vUv.y ) ) * 0.0918;",
  34. "sum += texture2D( tDiffuse, vec2( vUv.x - 2.0 * hh, vUv.y ) ) * 0.12245;",
  35. "sum += texture2D( tDiffuse, vec2( vUv.x - 1.0 * hh, vUv.y ) ) * 0.1531;",
  36. "sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y ) ) * 0.1633;",
  37. "sum += texture2D( tDiffuse, vec2( vUv.x + 1.0 * hh, vUv.y ) ) * 0.1531;",
  38. "sum += texture2D( tDiffuse, vec2( vUv.x + 2.0 * hh, vUv.y ) ) * 0.12245;",
  39. "sum += texture2D( tDiffuse, vec2( vUv.x + 3.0 * hh, vUv.y ) ) * 0.0918;",
  40. "sum += texture2D( tDiffuse, vec2( vUv.x + 4.0 * hh, vUv.y ) ) * 0.051;",
  41. "gl_FragColor = sum;",
  42. "}"
  43. ].join( "\n" )
  44. };