DOFMipMapShader.js 970 B

1234567891011121314151617181920212223242526272829
  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. var 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;', 'void main() {', ' vUv = uv;', ' gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );', '}' ].join( '\n' ),
  23. fragmentShader: [ 'uniform float focus;', 'uniform float maxblur;', 'uniform sampler2D tColor;', 'uniform sampler2D tDepth;', 'varying vec2 vUv;', 'void main() {', ' vec4 depth = texture2D( tDepth, vUv );', ' float factor = depth.x - focus;', ' vec4 col = texture2D( tColor, vUv, 2.0 * maxblur * abs( focus - depth.x ) );', ' gl_FragColor = col;', ' gl_FragColor.a = 1.0;', '}' ].join( '\n' )
  24. };
  25. THREE.DOFMipMapShader = DOFMipMapShader;
  26. } )();