Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 | //This file is automatically rebuilt by the Cesium build process.
export default "uniform sampler2D u_atlas;\n\
uniform float u_coarseDepthTestDistance;\n\
uniform float u_threePointDepthTestDistance;\n\
\n\
#ifdef VECTOR_TILE\n\
uniform vec4 u_highlightColor;\n\
#endif\n\
\n\
in vec2 v_textureCoordinates;\n\
in vec4 v_pickColor;\n\
in vec4 v_color;\n\
in float v_splitDirection;\n\
\n\
#ifdef SDF\n\
in vec4 v_outlineColor;\n\
in float v_outlineWidth;\n\
#endif\n\
\n\
in vec4 v_compressed; // x: eyeDepth, y: applyTranslate & enableDepthCheck, z: dimensions, w: imageSize\n\
const float SHIFT_LEFT1 = 2.0;\n\
const float SHIFT_RIGHT1 = 1.0 / 2.0;\n\
\n\
#ifdef FS_THREE_POINT_DEPTH_CHECK\n\
in vec4 v_textureCoordinateBounds; // the min and max x and y values for the texture coordinates\n\
in vec4 v_originTextureCoordinateAndTranslate; // texture coordinate at the origin, billboard translate (used for label glyphs)\n\
in mat2 v_rotationMatrix;\n\
\n\
const float SHIFT_LEFT12 = 4096.0;\n\
\n\
const float SHIFT_RIGHT12 = 1.0 / 4096.0;\n\
#endif\n\
\n\
float getGlobeDepthAtCoords(vec2 st)\n\
{\n\
float logDepthOrDepth = czm_unpackDepth(texture(czm_globeDepthTexture, st));\n\
if (logDepthOrDepth == 0.0)\n\
{\n\
return 0.0; // not on the globe\n\
}\n\
\n\
vec4 eyeCoordinate = czm_windowToEyeCoordinates(gl_FragCoord.xy, logDepthOrDepth);\n\
return eyeCoordinate.z / eyeCoordinate.w;\n\
}\n\
\n\
#ifdef FS_THREE_POINT_DEPTH_CHECK\n\
float getGlobeDepth(vec2 adjustedST, vec2 depthLookupST, bool applyTranslate, vec2 dimensions, vec2 imageSize)\n\
{\n\
vec2 lookupVector = imageSize * (depthLookupST - adjustedST);\n\
lookupVector = v_rotationMatrix * lookupVector;\n\
vec2 labelOffset = (dimensions - imageSize) * (depthLookupST - vec2(0.0, v_originTextureCoordinateAndTranslate.y)); // aligns label glyph with bounding rectangle. Will be zero for billboards because dimensions and imageSize will be equal\n\
\n\
vec2 translation = v_originTextureCoordinateAndTranslate.zw;\n\
\n\
if (applyTranslate)\n\
{\n\
// this is only needed for labels where the horizontal origin is not LEFT\n\
// it moves the label back to where the \"origin\" should be since all label glyphs are set to HorizontalOrigin.LEFT\n\
translation += (dimensions * v_originTextureCoordinateAndTranslate.xy * vec2(1.0, 0.0));\n\
}\n\
\n\
vec2 st = ((lookupVector - translation + labelOffset) + gl_FragCoord.xy) / czm_viewport.zw;\n\
return getGlobeDepthAtCoords(st);\n\
}\n\
#endif\n\
\n\
#ifdef SDF\n\
\n\
// Get the distance from the edge of a glyph at a given position sampling an SDF texture.\n\
float getDistance(vec2 position)\n\
{\n\
return texture(u_atlas, position).r;\n\
}\n\
\n\
// Samples the sdf texture at the given position and produces a color based on the fill color and the outline.\n\
vec4 getSDFColor(vec2 position, float outlineWidth, vec4 outlineColor, float smoothing)\n\
{\n\
float distance = getDistance(position);\n\
\n\
if (outlineWidth > 0.0)\n\
{\n\
// Don't get the outline edge exceed the SDF_EDGE\n\
float outlineEdge = clamp(SDF_EDGE - outlineWidth, 0.0, SDF_EDGE);\n\
float outlineFactor = smoothstep(SDF_EDGE - smoothing, SDF_EDGE + smoothing, distance);\n\
vec4 sdfColor = mix(outlineColor, v_color, outlineFactor);\n\
float alpha = smoothstep(outlineEdge - smoothing, outlineEdge + smoothing, distance);\n\
return vec4(sdfColor.rgb, sdfColor.a * alpha);\n\
}\n\
else\n\
{\n\
float alpha = smoothstep(SDF_EDGE - smoothing, SDF_EDGE + smoothing, distance);\n\
return vec4(v_color.rgb, v_color.a * alpha);\n\
}\n\
}\n\
#endif\n\
\n\
#ifdef FS_THREE_POINT_DEPTH_CHECK\n\
void doThreePointDepthTest(float eyeDepth, bool applyTranslate) {\n\
\n\
if (eyeDepth < -u_threePointDepthTestDistance) return;\n\
float temp = v_compressed.z;\n\
temp = temp * SHIFT_RIGHT12;\n\
\n\
vec2 dimensions;\n\
dimensions.y = (temp - floor(temp)) * SHIFT_LEFT12;\n\
dimensions.x = floor(temp);\n\
\n\
temp = v_compressed.w;\n\
temp = temp * SHIFT_RIGHT12;\n\
\n\
vec2 imageSize;\n\
imageSize.y = (temp - floor(temp)) * SHIFT_LEFT12;\n\
imageSize.x = floor(temp);\n\
\n\
vec2 adjustedST = v_textureCoordinates - v_textureCoordinateBounds.xy;\n\
adjustedST = adjustedST / vec2(v_textureCoordinateBounds.z - v_textureCoordinateBounds.x, v_textureCoordinateBounds.w - v_textureCoordinateBounds.y);\n\
\n\
float epsilonEyeDepth = v_compressed.x + czm_epsilon1;\n\
float globeDepth1 = getGlobeDepth(adjustedST, v_originTextureCoordinateAndTranslate.xy, applyTranslate, dimensions, imageSize);\n\
\n\
// negative values go into the screen\n\
if (globeDepth1 == 0.0 || globeDepth1 < epsilonEyeDepth) return;\n\
\n\
float globeDepth2 = getGlobeDepth(adjustedST, vec2(0.0, 1.0), applyTranslate, dimensions, imageSize); // top left corner\n\
if (globeDepth2 == 0.0 || globeDepth2 < epsilonEyeDepth) return;\n\
\n\
float globeDepth3 = getGlobeDepth(adjustedST, vec2(1.0, 1.0), applyTranslate, dimensions, imageSize); // top right corner\n\
if (globeDepth3 == 0.0 || globeDepth3 < epsilonEyeDepth) return;\n\
\n\
// All three key points are occluded, discard the fragment (and by extension the entire billboard) \n\
discard;\n\
}\n\
#endif\n\
\n\
// Extra manual depth testing is done to allow more control over how a billboard is occluded \n\
// by the globe when near and far from the camera.\n\
void doDepthTest(float globeDepth) {\n\
float temp = v_compressed.y;\n\
temp = temp * SHIFT_RIGHT1;\n\
float temp2 = (temp - floor(temp)) * SHIFT_LEFT1;\n\
bool enableDepthCheck = temp2 != 0.0;\n\
if (!enableDepthCheck) return;\n\
\n\
float eyeDepth = v_compressed.x;\n\
\n\
#ifdef FS_THREE_POINT_DEPTH_CHECK\n\
// If the billboard is clamped to the ground and within a given distance, we do a 3-point depth test. This test is performed in the vertex shader, unless\n\
// vertex texture sampling is not supported, in which case we do it here.\n\
bool applyTranslate = floor(temp) != 0.0;\n\
doThreePointDepthTest(eyeDepth, applyTranslate);\n\
\n\
#elif defined(VS_THREE_POINT_DEPTH_CHECK)\n\
// Since discarding vertices is not possible, the vertex shader sets eyeDepth to 0 to indicate the depth test failed. Apply the discard here.\n\
if (eyeDepth > -u_threePointDepthTestDistance) {\n\
if (eyeDepth == 0.0) {\n\
discard;\n\
}\n\
return;\n\
}\n\
#endif\n\
\n\
// If we're far away, we just compare against a flat, camera-facing depth-plane at the ellipsoid's center.\n\
// If we're close, we compare against the globe depth texture (which includes depth from the 3D tile pass).\n\
\n\
if (globeDepth == 0.0) return; // Not on globe \n\
float distanceToEllipsoidCenter = -length(czm_viewerPositionWC); // depth is negative by convention\n\
float testDistance = (eyeDepth > -u_coarseDepthTestDistance) ? globeDepth : distanceToEllipsoidCenter;\n\
if (eyeDepth < testDistance) {\n\
discard;\n\
}\n\
}\n\
\n\
void main()\n\
{\n\
if (v_splitDirection < 0.0 && gl_FragCoord.x > czm_splitPosition) discard;\n\
if (v_splitDirection > 0.0 && gl_FragCoord.x < czm_splitPosition) discard;\n\
\n\
vec2 fragSt = gl_FragCoord.xy / czm_viewport.zw;\n\
float globeDepth = getGlobeDepthAtCoords(fragSt);\n\
doDepthTest(globeDepth);\n\
\n\
vec4 color = texture(u_atlas, v_textureCoordinates);\n\
\n\
#ifdef SDF\n\
float outlineWidth = v_outlineWidth;\n\
vec4 outlineColor = v_outlineColor;\n\
\n\
// Get the current distance\n\
float distance = getDistance(v_textureCoordinates);\n\
\n\
#if (__VERSION__ == 300 || defined(GL_OES_standard_derivatives))\n\
float smoothing = fwidth(distance);\n\
// Get an offset that is approximately half the distance to the neighbor pixels\n\
// 0.354 is approximately half of 1/sqrt(2)\n\
vec2 sampleOffset = 0.354 * vec2(dFdx(v_textureCoordinates) + dFdy(v_textureCoordinates));\n\
\n\
// Sample the center point\n\
vec4 center = getSDFColor(v_textureCoordinates, outlineWidth, outlineColor, smoothing);\n\
\n\
// Sample the 4 neighbors\n\
vec4 color1 = getSDFColor(v_textureCoordinates + vec2(sampleOffset.x, sampleOffset.y), outlineWidth, outlineColor, smoothing);\n\
vec4 color2 = getSDFColor(v_textureCoordinates + vec2(-sampleOffset.x, sampleOffset.y), outlineWidth, outlineColor, smoothing);\n\
vec4 color3 = getSDFColor(v_textureCoordinates + vec2(-sampleOffset.x, -sampleOffset.y), outlineWidth, outlineColor, smoothing);\n\
vec4 color4 = getSDFColor(v_textureCoordinates + vec2(sampleOffset.x, -sampleOffset.y), outlineWidth, outlineColor, smoothing);\n\
\n\
// Equally weight the center sample and the 4 neighboring samples\n\
color = (center + color1 + color2 + color3 + color4)/5.0;\n\
#else\n\
// If no derivatives available (IE 10?), just do a single sample\n\
float smoothing = 1.0/32.0;\n\
color = getSDFColor(v_textureCoordinates, outlineWidth, outlineColor, smoothing);\n\
#endif\n\
\n\
color = czm_gammaCorrect(color);\n\
#else\n\
color = czm_gammaCorrect(color);\n\
color *= czm_gammaCorrect(v_color);\n\
#endif\n\
\n\
// Fully transparent parts of the billboard are not pickable.\n\
#if !defined(OPAQUE) && !defined(TRANSLUCENT)\n\
if (color.a < 0.005) // matches 0/255 and 1/255\n\
{\n\
discard;\n\
}\n\
#else\n\
// The billboard is rendered twice. The opaque pass discards translucent fragments\n\
// and the translucent pass discards opaque fragments.\n\
#ifdef OPAQUE\n\
if (color.a < 0.995) // matches < 254/255\n\
{\n\
discard;\n\
}\n\
#else\n\
if (color.a >= 0.995) // matches 254/255 and 255/255\n\
{\n\
discard;\n\
}\n\
#endif\n\
#endif\n\
\n\
#ifdef VECTOR_TILE\n\
color *= u_highlightColor;\n\
#endif\n\
out_FragColor = color;\n\
\n\
#ifdef LOG_DEPTH\n\
// If we've made it here, we passed our manual depth test, above. But the automatic depth test will\n\
// still run, and some fragments of the billboard may clip against the globe. To prevent that,\n\
// ensure the depth value we write out is in front of the globe depth.\n\
float depthArg = v_depthFromNearPlusOne;\n\
\n\
if (globeDepth != 0.0) { // On the globe\n\
float globeDepthFromNearPlusOne = (-globeDepth - czm_currentFrustum.x) + 1.0;\n\
float nudge = max(globeDepthFromNearPlusOne * 5e-6, czm_epsilon7);\n\
float globeOnTop = max(1.0, globeDepthFromNearPlusOne - nudge);\n\
depthArg = min(depthArg, globeOnTop);\n\
}\n\
\n\
czm_writeLogDepth(depthArg);\n\
#endif\n\
}";
|