DOFMipMapShader.js 923 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. THREE.DOFMipMapShader = {
  7. uniforms: {
  8. "tColor": { value: null },
  9. "tDepth": { value: null },
  10. "focus": { value: 1.0 },
  11. "maxblur": { value: 1.0 }
  12. },
  13. vertexShader: [
  14. "varying vec2 vUv;",
  15. "void main() {",
  16. " vUv = uv;",
  17. " gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
  18. "}"
  19. ].join( "\n" ),
  20. fragmentShader: [
  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. ].join( "\n" )
  34. };