CompositeOITFS.glsl 806 B

1234567891011121314151617181920212223242526
  1. /**
  2. * Compositing for Weighted Blended Order-Independent Transparency. See:
  3. * - http://jcgt.org/published/0002/02/09/
  4. * - http://casual-effects.blogspot.com/2014/03/weighted-blended-order-independent.html
  5. */
  6. uniform sampler2D u_opaque;
  7. uniform sampler2D u_accumulation;
  8. uniform sampler2D u_revealage;
  9. varying vec2 v_textureCoordinates;
  10. void main()
  11. {
  12. vec4 opaque = texture2D(u_opaque, v_textureCoordinates);
  13. vec4 accum = texture2D(u_accumulation, v_textureCoordinates);
  14. float r = texture2D(u_revealage, v_textureCoordinates).r;
  15. #ifdef MRT
  16. vec4 transparent = vec4(accum.rgb / clamp(r, 1e-4, 5e4), accum.a);
  17. #else
  18. vec4 transparent = vec4(accum.rgb / clamp(accum.a, 1e-4, 5e4), r);
  19. #endif
  20. gl_FragColor = (1.0 - transparent.a) * transparent + transparent.a * opaque;
  21. }