UnpackDepthRGBAShader.js 998 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /**
  2. * @author alteredq / http://alteredqualia.com/
  3. *
  4. * Unpack RGBA depth shader
  5. * - show RGBA encoded depth as monochrome color
  6. */
  7. THREE.UnpackDepthRGBAShader = {
  8. uniforms: {
  9. "tDiffuse": { type: "t", value: null },
  10. "opacity": { type: "f", value: 1.0 }
  11. },
  12. vertexShader: [
  13. "varying vec2 vUv;",
  14. "void main() {",
  15. "vUv = uv;",
  16. "gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
  17. "}"
  18. ].join("\n"),
  19. fragmentShader: [
  20. "uniform float opacity;",
  21. "uniform sampler2D tDiffuse;",
  22. "varying vec2 vUv;",
  23. // RGBA depth
  24. "float unpackDepth( const in vec4 rgba_depth ) {",
  25. "const vec4 bit_shift = vec4( 1.0 / ( 256.0 * 256.0 * 256.0 ), 1.0 / ( 256.0 * 256.0 ), 1.0 / 256.0, 1.0 );",
  26. "float depth = dot( rgba_depth, bit_shift );",
  27. "return depth;",
  28. "}",
  29. "void main() {",
  30. "float depth = 1.0 - unpackDepth( texture2D( tDiffuse, vUv ) );",
  31. "gl_FragColor = opacity * vec4( vec3( depth ), 1.0 );",
  32. "}"
  33. ].join("\n")
  34. };