wboit-write.glsl.ts 1.2 KB

12345678910111213141516171819202122232425262728293031
  1. /**
  2. * Copyright (c) 2019-2022 mol* contributors, licensed under MIT, See LICENSE file for more info.
  3. *
  4. * @author Alexander Rose <alexander.rose@weirdbyte.de>
  5. * @author Áron Samuel Kovács <aron.kovacs@mail.muni.cz>
  6. */
  7. export const wboit_write = `
  8. #if defined(dRenderVariant_colorWboit)
  9. if (!uRenderWboit) {
  10. if (preFogAlpha < 1.0) {
  11. discard;
  12. }
  13. } else if (uRenderWboit) {
  14. // the 'fragmentDepth > 0.99' check is to handle precision issues with packed depth
  15. if (preFogAlpha != 1.0 && (!interior || uDoubleSided) && (fragmentDepth < getDepth(gl_FragCoord.xy / uDrawingBufferSize) || fragmentDepth > 0.99)) {
  16. float alpha = gl_FragColor.a;
  17. float wboitWeight = alpha * clamp(pow(1.0 - fragmentDepth, 2.0), 0.01, 1.0);
  18. gl_FragColor = vec4(gl_FragColor.rgb * alpha * wboitWeight, alpha);
  19. // extra alpha is to handle pre-multiplied alpha
  20. #ifndef dGeometryType_directVolume
  21. gl_FragData[1] = vec4((uTransparentBackground ? alpha : 1.0) * alpha * wboitWeight);
  22. #else
  23. gl_FragData[1] = vec4(alpha * alpha * wboitWeight);
  24. #endif
  25. } else {
  26. discard;
  27. }
  28. }
  29. #endif
  30. `;