CompositeOITFS.glsl 870 B

12345678910111213141516171819202122232425262728293031
  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. in vec2 v_textureCoordinates;
  10. void main()
  11. {
  12. vec4 opaque = texture(u_opaque, v_textureCoordinates);
  13. vec4 accum = texture(u_accumulation, v_textureCoordinates);
  14. float r = texture(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. out_FragColor = (1.0 - transparent.a) * transparent + transparent.a * opaque;
  21. if (opaque != czm_backgroundColor)
  22. {
  23. out_FragColor.a = 1.0;
  24. }
  25. }