DOFMipMapShader.js 918 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /**
  2. * Depth-of-field shader using mipmaps
  3. * - from Matt Handley @applmak
  4. * - requires power-of-2 sized render target with enabled mipmaps
  5. */
  6. const DOFMipMapShader = {
  7. name: 'DOFMipMapShader',
  8. uniforms: {
  9. 'tColor': { value: null },
  10. 'tDepth': { value: null },
  11. 'focus': { value: 1.0 },
  12. 'maxblur': { value: 1.0 }
  13. },
  14. vertexShader: /* glsl */`
  15. varying vec2 vUv;
  16. void main() {
  17. vUv = uv;
  18. gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
  19. }`,
  20. fragmentShader: /* glsl */`
  21. uniform float focus;
  22. uniform float maxblur;
  23. uniform sampler2D tColor;
  24. uniform sampler2D tDepth;
  25. varying vec2 vUv;
  26. void main() {
  27. vec4 depth = texture2D( tDepth, vUv );
  28. float factor = depth.x - focus;
  29. vec4 col = texture2D( tColor, vUv, 2.0 * maxblur * abs( focus - depth.x ) );
  30. gl_FragColor = col;
  31. gl_FragColor.a = 1.0;
  32. }`
  33. };
  34. export { DOFMipMapShader };