VerticalTiltShiftShader.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. console.warn( "THREE.VerticalTiltShiftShader: As part of the transition to ES6 Modules, the files in 'examples/js' were deprecated in May 2020 (r117) and will be deleted in December 2020 (r124). You can find more information about developing using ES6 Modules in https://threejs.org/docs/index.html#manual/en/introduction/Import-via-modules." );
  2. /**
  3. * @author alteredq / http://alteredqualia.com/
  4. *
  5. * Simple fake tilt-shift effect, modulating two pass Gaussian blur (see above) by vertical position
  6. *
  7. * - 9 samples per pass
  8. * - standard deviation 2.7
  9. * - "h" and "v" parameters should be set to "1 / width" and "1 / height"
  10. * - "r" parameter control where "focused" horizontal line lies
  11. */
  12. THREE.VerticalTiltShiftShader = {
  13. uniforms: {
  14. "tDiffuse": { value: null },
  15. "v": { value: 1.0 / 512.0 },
  16. "r": { value: 0.35 }
  17. },
  18. vertexShader: [
  19. "varying vec2 vUv;",
  20. "void main() {",
  21. " vUv = uv;",
  22. " gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
  23. "}"
  24. ].join( "\n" ),
  25. fragmentShader: [
  26. "uniform sampler2D tDiffuse;",
  27. "uniform float v;",
  28. "uniform float r;",
  29. "varying vec2 vUv;",
  30. "void main() {",
  31. " vec4 sum = vec4( 0.0 );",
  32. " float vv = v * abs( r - vUv.y );",
  33. " sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y - 4.0 * vv ) ) * 0.051;",
  34. " sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y - 3.0 * vv ) ) * 0.0918;",
  35. " sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y - 2.0 * vv ) ) * 0.12245;",
  36. " sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y - 1.0 * vv ) ) * 0.1531;",
  37. " sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y ) ) * 0.1633;",
  38. " sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y + 1.0 * vv ) ) * 0.1531;",
  39. " sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y + 2.0 * vv ) ) * 0.12245;",
  40. " sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y + 3.0 * vv ) ) * 0.0918;",
  41. " sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y + 4.0 * vv ) ) * 0.051;",
  42. " gl_FragColor = sum;",
  43. "}"
  44. ].join( "\n" )
  45. };