DOFMipMapShader.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. console.warn( "THREE.DOFMipMapShader: 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. * Depth-of-field shader using mipmaps
  6. * - from Matt Handley @applmak
  7. * - requires power-of-2 sized render target with enabled mipmaps
  8. */
  9. THREE.DOFMipMapShader = {
  10. uniforms: {
  11. "tColor": { value: null },
  12. "tDepth": { value: null },
  13. "focus": { value: 1.0 },
  14. "maxblur": { value: 1.0 }
  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 float focus;",
  25. "uniform float maxblur;",
  26. "uniform sampler2D tColor;",
  27. "uniform sampler2D tDepth;",
  28. "varying vec2 vUv;",
  29. "void main() {",
  30. " vec4 depth = texture2D( tDepth, vUv );",
  31. " float factor = depth.x - focus;",
  32. " vec4 col = texture2D( tColor, vUv, 2.0 * maxblur * abs( focus - depth.x ) );",
  33. " gl_FragColor = col;",
  34. " gl_FragColor.a = 1.0;",
  35. "}"
  36. ].join( "\n" )
  37. };