assign-material-color.glsl.ts 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. export const assign_material_color = `
  2. #if defined(dRenderVariant_color)
  3. #if defined(dColorType_uniform)
  4. vec4 material = vec4(uColor, uAlpha);
  5. #elif defined(dColorType_varying)
  6. vec4 material = vec4(vColor.rgb, uAlpha);
  7. #endif
  8. // mix material with overpaint
  9. #if defined(dOverpaint)
  10. material.rgb = mix(material.rgb, vOverpaint.rgb, vOverpaint.a);
  11. #endif
  12. #elif defined(dRenderVariant_pick)
  13. vec4 material = vColor;
  14. #elif defined(dRenderVariant_depth)
  15. #ifdef enabledFragDepth
  16. vec4 material = packDepthToRGBA(gl_FragDepthEXT);
  17. #else
  18. vec4 material = packDepthToRGBA(gl_FragCoord.z);
  19. #endif
  20. #endif
  21. // apply screendoor transparency
  22. #if defined(dTransparency)
  23. float ta = 1.0 - vTransparency;
  24. #if defined(dRenderVariant_pick)
  25. if (ta < uPickingAlphaThreshold)
  26. discard; // ignore so the element below can be picked
  27. #else
  28. #if defined(dRenderVariant_colorBlended)
  29. float at = 0.0;
  30. // shift by view-offset during multi-sample rendering to allow for blending
  31. vec2 coord = gl_FragCoord.xy + uViewOffset * 0.25;
  32. const mat4 thresholdMatrix = mat4(
  33. 1.0 / 17.0, 9.0 / 17.0, 3.0 / 17.0, 11.0 / 17.0,
  34. 13.0 / 17.0, 5.0 / 17.0, 15.0 / 17.0, 7.0 / 17.0,
  35. 4.0 / 17.0, 12.0 / 17.0, 2.0 / 17.0, 10.0 / 17.0,
  36. 16.0 / 17.0, 8.0 / 17.0, 14.0 / 17.0, 6.0 / 17.0
  37. );
  38. int ci = int(intMod(coord.x, 4.0));
  39. int ri = int(intMod(coord.y, 4.0));
  40. #if __VERSION__ == 100
  41. vec4 i = vec4(float(ci * 4 + ri));
  42. vec4 v = thresholdMatrix[0] * vec4(equal(i, vec4(0.0, 1.0, 2.0, 3.0))) +
  43. thresholdMatrix[1] * vec4(equal(i, vec4(4.0, 5.0, 6.0, 7.0))) +
  44. thresholdMatrix[2] * vec4(equal(i, vec4(8.0, 9.0, 10.0, 11.0))) +
  45. thresholdMatrix[3] * vec4(equal(i, vec4(12.0, 13.0, 14.0, 15.0)));
  46. at = v.x + v.y + v.z + v.w;
  47. #else
  48. at = thresholdMatrix[ci][ri];
  49. #endif
  50. if (ta < 0.99 && (ta < 0.01 || ta < at)) {
  51. discard;
  52. }
  53. #elif defined(dRenderVariant_colorWboit)
  54. material.a *= ta;
  55. #endif
  56. #endif
  57. #endif
  58. `;