assign-material-color.glsl.ts 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. export default `
  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. // apply screendoor transparency
  13. #if defined(dTransparency)
  14. float ta = 1.0 - vTransparency;
  15. float at = 0.0;
  16. // shift by view-offset during multi-sample rendering to allow for blending
  17. vec2 coord = gl_FragCoord.xy + uViewOffset * 0.25;
  18. #if defined(dTransparencyVariant_single)
  19. const mat4 thresholdMatrix = mat4(
  20. 1.0 / 17.0, 9.0 / 17.0, 3.0 / 17.0, 11.0 / 17.0,
  21. 13.0 / 17.0, 5.0 / 17.0, 15.0 / 17.0, 7.0 / 17.0,
  22. 4.0 / 17.0, 12.0 / 17.0, 2.0 / 17.0, 10.0 / 17.0,
  23. 16.0 / 17.0, 8.0 / 17.0, 14.0 / 17.0, 6.0 / 17.0
  24. );
  25. at = thresholdMatrix[int(intMod(coord.x, 4.0))][int(intMod(coord.y, 4.0))];
  26. #elif defined(dTransparencyVariant_multi)
  27. at = fract(dot(vec3(coord, vGroup + 0.5), vec3(2.0, 7.0, 23.0) / 17.0f));
  28. #endif
  29. if (ta < 0.99 && (ta < 0.01 || ta < at)) discard;
  30. #endif
  31. #elif defined(dRenderVariant_pick)
  32. vec4 material = vColor;
  33. #elif defined(dRenderVariant_depth)
  34. #ifdef enabledFragDepth
  35. vec4 material = packDepthToRGBA(gl_FragDepthEXT);
  36. #else
  37. vec4 material = packDepthToRGBA(gl_FragCoord.z);
  38. #endif
  39. #endif
  40. `;