PointPrimitiveCollectionFS.glsl 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. in vec4 v_color;
  2. in vec4 v_outlineColor;
  3. in float v_innerPercent;
  4. in float v_pixelDistance;
  5. in vec4 v_pickColor;
  6. void main()
  7. {
  8. // The distance in UV space from this fragment to the center of the point, at most 0.5.
  9. float distanceToCenter = length(gl_PointCoord - vec2(0.5));
  10. // The max distance stops one pixel shy of the edge to leave space for anti-aliasing.
  11. float maxDistance = max(0.0, 0.5 - v_pixelDistance);
  12. float wholeAlpha = 1.0 - smoothstep(maxDistance, 0.5, distanceToCenter);
  13. float innerAlpha = 1.0 - smoothstep(maxDistance * v_innerPercent, 0.5 * v_innerPercent, distanceToCenter);
  14. vec4 color = mix(v_outlineColor, v_color, innerAlpha);
  15. color.a *= wholeAlpha;
  16. // Fully transparent parts of the billboard are not pickable.
  17. #if !defined(OPAQUE) && !defined(TRANSLUCENT)
  18. if (color.a < 0.005) // matches 0/255 and 1/255
  19. {
  20. discard;
  21. }
  22. #else
  23. // The billboard is rendered twice. The opaque pass discards translucent fragments
  24. // and the translucent pass discards opaque fragments.
  25. #ifdef OPAQUE
  26. if (color.a < 0.995) // matches < 254/255
  27. {
  28. discard;
  29. }
  30. #else
  31. if (color.a >= 0.995) // matches 254/255 and 255/255
  32. {
  33. discard;
  34. }
  35. #endif
  36. #endif
  37. out_FragColor = czm_gammaCorrect(color);
  38. czm_writeLogDepth();
  39. }