BillboardCollectionFS.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. //This file is automatically rebuilt by the Cesium build process.
  2. export default "#ifdef GL_OES_standard_derivatives\n\
  3. #extension GL_OES_standard_derivatives : enable\n\
  4. #endif\n\
  5. uniform sampler2D u_atlas;\n\
  6. #ifdef VECTOR_TILE\n\
  7. uniform vec4 u_highlightColor;\n\
  8. #endif\n\
  9. varying vec2 v_textureCoordinates;\n\
  10. varying vec4 v_pickColor;\n\
  11. varying vec4 v_color;\n\
  12. #ifdef SDF\n\
  13. varying vec4 v_outlineColor;\n\
  14. varying float v_outlineWidth;\n\
  15. #endif\n\
  16. #ifdef FRAGMENT_DEPTH_CHECK\n\
  17. varying vec4 v_textureCoordinateBounds;\n\
  18. varying vec4 v_originTextureCoordinateAndTranslate;\n\
  19. varying vec4 v_compressed;\n\
  20. varying mat2 v_rotationMatrix;\n\
  21. const float SHIFT_LEFT12 = 4096.0;\n\
  22. const float SHIFT_LEFT1 = 2.0;\n\
  23. const float SHIFT_RIGHT12 = 1.0 / 4096.0;\n\
  24. const float SHIFT_RIGHT1 = 1.0 / 2.0;\n\
  25. float getGlobeDepth(vec2 adjustedST, vec2 depthLookupST, bool applyTranslate, vec2 dimensions, vec2 imageSize)\n\
  26. {\n\
  27. vec2 lookupVector = imageSize * (depthLookupST - adjustedST);\n\
  28. lookupVector = v_rotationMatrix * lookupVector;\n\
  29. vec2 labelOffset = (dimensions - imageSize) * (depthLookupST - vec2(0.0, v_originTextureCoordinateAndTranslate.y));\n\
  30. vec2 translation = v_originTextureCoordinateAndTranslate.zw;\n\
  31. if (applyTranslate)\n\
  32. {\n\
  33. translation += (dimensions * v_originTextureCoordinateAndTranslate.xy * vec2(1.0, 0.0));\n\
  34. }\n\
  35. vec2 st = ((lookupVector - translation + labelOffset) + gl_FragCoord.xy) / czm_viewport.zw;\n\
  36. float logDepthOrDepth = czm_unpackDepth(texture2D(czm_globeDepthTexture, st));\n\
  37. if (logDepthOrDepth == 0.0)\n\
  38. {\n\
  39. return 0.0;\n\
  40. }\n\
  41. vec4 eyeCoordinate = czm_windowToEyeCoordinates(gl_FragCoord.xy, logDepthOrDepth);\n\
  42. return eyeCoordinate.z / eyeCoordinate.w;\n\
  43. }\n\
  44. #endif\n\
  45. #ifdef SDF\n\
  46. float getDistance(vec2 position)\n\
  47. {\n\
  48. return texture2D(u_atlas, position).r;\n\
  49. }\n\
  50. vec4 getSDFColor(vec2 position, float outlineWidth, vec4 outlineColor, float smoothing)\n\
  51. {\n\
  52. float distance = getDistance(position);\n\
  53. if (outlineWidth > 0.0)\n\
  54. {\n\
  55. float outlineEdge = clamp(SDF_EDGE - outlineWidth, 0.0, SDF_EDGE);\n\
  56. float outlineFactor = smoothstep(SDF_EDGE - smoothing, SDF_EDGE + smoothing, distance);\n\
  57. vec4 sdfColor = mix(outlineColor, v_color, outlineFactor);\n\
  58. float alpha = smoothstep(outlineEdge - smoothing, outlineEdge + smoothing, distance);\n\
  59. return vec4(sdfColor.rgb, sdfColor.a * alpha);\n\
  60. }\n\
  61. else\n\
  62. {\n\
  63. float alpha = smoothstep(SDF_EDGE - smoothing, SDF_EDGE + smoothing, distance);\n\
  64. return vec4(v_color.rgb, v_color.a * alpha);\n\
  65. }\n\
  66. }\n\
  67. #endif\n\
  68. void main()\n\
  69. {\n\
  70. vec4 color = texture2D(u_atlas, v_textureCoordinates);\n\
  71. #ifdef SDF\n\
  72. float outlineWidth = v_outlineWidth;\n\
  73. vec4 outlineColor = v_outlineColor;\n\
  74. float distance = getDistance(v_textureCoordinates);\n\
  75. #ifdef GL_OES_standard_derivatives\n\
  76. float smoothing = fwidth(distance);\n\
  77. vec2 sampleOffset = 0.354 * vec2(dFdx(v_textureCoordinates) + dFdy(v_textureCoordinates));\n\
  78. vec4 center = getSDFColor(v_textureCoordinates, outlineWidth, outlineColor, smoothing);\n\
  79. vec4 color1 = getSDFColor(v_textureCoordinates + vec2(sampleOffset.x, sampleOffset.y), outlineWidth, outlineColor, smoothing);\n\
  80. vec4 color2 = getSDFColor(v_textureCoordinates + vec2(-sampleOffset.x, sampleOffset.y), outlineWidth, outlineColor, smoothing);\n\
  81. vec4 color3 = getSDFColor(v_textureCoordinates + vec2(-sampleOffset.x, -sampleOffset.y), outlineWidth, outlineColor, smoothing);\n\
  82. vec4 color4 = getSDFColor(v_textureCoordinates + vec2(sampleOffset.x, -sampleOffset.y), outlineWidth, outlineColor, smoothing);\n\
  83. color = (center + color1 + color2 + color3 + color4)/5.0;\n\
  84. #else\n\
  85. float smoothing = 1.0/32.0;\n\
  86. color = getSDFColor(v_textureCoordinates, outlineWidth, outlineColor, smoothing);\n\
  87. #endif\n\
  88. color = czm_gammaCorrect(color);\n\
  89. #else\n\
  90. color = czm_gammaCorrect(color);\n\
  91. color *= czm_gammaCorrect(v_color);\n\
  92. #endif\n\
  93. #if !defined(OPAQUE) && !defined(TRANSLUCENT)\n\
  94. if (color.a < 0.005)\n\
  95. {\n\
  96. discard;\n\
  97. }\n\
  98. #else\n\
  99. #ifdef OPAQUE\n\
  100. if (color.a < 0.995)\n\
  101. {\n\
  102. discard;\n\
  103. }\n\
  104. #else\n\
  105. if (color.a >= 0.995)\n\
  106. {\n\
  107. discard;\n\
  108. }\n\
  109. #endif\n\
  110. #endif\n\
  111. #ifdef VECTOR_TILE\n\
  112. color *= u_highlightColor;\n\
  113. #endif\n\
  114. gl_FragColor = color;\n\
  115. czm_writeLogDepth();\n\
  116. #ifdef FRAGMENT_DEPTH_CHECK\n\
  117. float temp = v_compressed.y;\n\
  118. temp = temp * SHIFT_RIGHT1;\n\
  119. float temp2 = (temp - floor(temp)) * SHIFT_LEFT1;\n\
  120. bool enableDepthTest = temp2 != 0.0;\n\
  121. bool applyTranslate = floor(temp) != 0.0;\n\
  122. if (enableDepthTest) {\n\
  123. temp = v_compressed.z;\n\
  124. temp = temp * SHIFT_RIGHT12;\n\
  125. vec2 dimensions;\n\
  126. dimensions.y = (temp - floor(temp)) * SHIFT_LEFT12;\n\
  127. dimensions.x = floor(temp);\n\
  128. temp = v_compressed.w;\n\
  129. temp = temp * SHIFT_RIGHT12;\n\
  130. vec2 imageSize;\n\
  131. imageSize.y = (temp - floor(temp)) * SHIFT_LEFT12;\n\
  132. imageSize.x = floor(temp);\n\
  133. vec2 adjustedST = v_textureCoordinates - v_textureCoordinateBounds.xy;\n\
  134. adjustedST = adjustedST / vec2(v_textureCoordinateBounds.z - v_textureCoordinateBounds.x, v_textureCoordinateBounds.w - v_textureCoordinateBounds.y);\n\
  135. float epsilonEyeDepth = v_compressed.x + czm_epsilon1;\n\
  136. float globeDepth1 = getGlobeDepth(adjustedST, v_originTextureCoordinateAndTranslate.xy, applyTranslate, dimensions, imageSize);\n\
  137. if (globeDepth1 != 0.0 && globeDepth1 > epsilonEyeDepth)\n\
  138. {\n\
  139. float globeDepth2 = getGlobeDepth(adjustedST, vec2(0.0, 1.0), applyTranslate, dimensions, imageSize);\n\
  140. if (globeDepth2 != 0.0 && globeDepth2 > epsilonEyeDepth)\n\
  141. {\n\
  142. float globeDepth3 = getGlobeDepth(adjustedST, vec2(1.0, 1.0), applyTranslate, dimensions, imageSize);\n\
  143. if (globeDepth3 != 0.0 && globeDepth3 > epsilonEyeDepth)\n\
  144. {\n\
  145. discard;\n\
  146. }\n\
  147. }\n\
  148. }\n\
  149. }\n\
  150. #endif\n\
  151. }\n\
  152. ";