2
0

DOFMipMapShader.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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/#manual/en/introduction/Installation." );
  2. /**
  3. * Depth-of-field shader using mipmaps
  4. * - from Matt Handley @applmak
  5. * - requires power-of-2 sized render target with enabled mipmaps
  6. */
  7. THREE.DOFMipMapShader = {
  8. uniforms: {
  9. "tColor": { value: null },
  10. "tDepth": { value: null },
  11. "focus": { value: 1.0 },
  12. "maxblur": { value: 1.0 }
  13. },
  14. vertexShader: [
  15. "varying vec2 vUv;",
  16. "void main() {",
  17. " vUv = uv;",
  18. " gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
  19. "}"
  20. ].join( "\n" ),
  21. fragmentShader: [
  22. "uniform float focus;",
  23. "uniform float maxblur;",
  24. "uniform sampler2D tColor;",
  25. "uniform sampler2D tDepth;",
  26. "varying vec2 vUv;",
  27. "void main() {",
  28. " vec4 depth = texture2D( tDepth, vUv );",
  29. " float factor = depth.x - focus;",
  30. " vec4 col = texture2D( tColor, vUv, 2.0 * maxblur * abs( focus - depth.x ) );",
  31. " gl_FragColor = col;",
  32. " gl_FragColor.a = 1.0;",
  33. "}"
  34. ].join( "\n" )
  35. };