HorizontalTiltShiftShader.js 1.9 KB

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