DOFMipMapShader.js 981 B

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