DOFMipMapShader.js 934 B

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