DOFMipMapShader.js 982 B

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