DOFMipMapShader.js 963 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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: /* glsl */`
  23. varying vec2 vUv;
  24. void main() {
  25. vUv = uv;
  26. gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
  27. }`,
  28. fragmentShader: /* glsl */`
  29. uniform float focus;
  30. uniform float maxblur;
  31. uniform sampler2D tColor;
  32. uniform sampler2D tDepth;
  33. varying vec2 vUv;
  34. void main() {
  35. vec4 depth = texture2D( tDepth, vUv );
  36. float factor = depth.x - focus;
  37. vec4 col = texture2D( tColor, vUv, 2.0 * maxblur * abs( focus - depth.x ) );
  38. gl_FragColor = col;
  39. gl_FragColor.a = 1.0;
  40. }`
  41. };
  42. THREE.DOFMipMapShader = DOFMipMapShader;
  43. } )();