DOFMipMapShader.js 972 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. ( function () {
  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. const DOFMipMapShader = {
  8. uniforms: {
  9. 'tColor': {
  10. value: null
  11. },
  12. 'tDepth': {
  13. value: null
  14. },
  15. 'focus': {
  16. value: 1.0
  17. },
  18. 'maxblur': {
  19. value: 1.0
  20. }
  21. },
  22. vertexShader:
  23. /* glsl */
  24. `
  25. varying vec2 vUv;
  26. void main() {
  27. vUv = uv;
  28. gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
  29. }`,
  30. fragmentShader:
  31. /* glsl */
  32. `
  33. uniform float focus;
  34. uniform float maxblur;
  35. uniform sampler2D tColor;
  36. uniform sampler2D tDepth;
  37. varying vec2 vUv;
  38. void main() {
  39. vec4 depth = texture2D( tDepth, vUv );
  40. float factor = depth.x - focus;
  41. vec4 col = texture2D( tColor, vUv, 2.0 * maxblur * abs( focus - depth.x ) );
  42. gl_FragColor = col;
  43. gl_FragColor.a = 1.0;
  44. }`
  45. };
  46. THREE.DOFMipMapShader = DOFMipMapShader;
  47. } )();