| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154 |
- uniform float u_maxTotalPointSize;
-
- in vec4 positionHighAndSize;
- in vec4 positionLowAndOutline;
- in vec4 compressedAttribute0; // color, outlineColor, pick color
- in vec4 compressedAttribute1; // show, translucency by distance, some free space
- in vec4 scaleByDistance; // near, nearScale, far, farScale
- in vec4 distanceDisplayConditionAndDisableDepthAndSplitDirection; // near, far, disableDepthTestDistance, splitDirection
-
- out vec4 v_color;
- out vec4 v_outlineColor;
- out float v_innerPercent;
- out float v_pixelDistance;
- out vec4 v_pickColor;
- out float v_splitDirection;
-
- const float SHIFT_LEFT8 = 256.0;
- const float SHIFT_RIGHT8 = 1.0 / 256.0;
-
- void main()
- {
- // Modifying this shader may also require modifications to PointPrimitive._computeScreenSpacePosition
-
- // unpack attributes
- vec3 positionHigh = positionHighAndSize.xyz;
- vec3 positionLow = positionLowAndOutline.xyz;
- float outlineWidthBothSides = 2.0 * positionLowAndOutline.w;
- float totalSize = positionHighAndSize.w + outlineWidthBothSides;
- float outlinePercent = outlineWidthBothSides / totalSize;
- // Scale in response to browser-zoom.
- totalSize *= czm_pixelRatio;
-
- float temp = compressedAttribute1.x * SHIFT_RIGHT8;
- float show = floor(temp);
-
- #ifdef EYE_DISTANCE_TRANSLUCENCY
- vec4 translucencyByDistance;
- translucencyByDistance.x = compressedAttribute1.z;
- translucencyByDistance.z = compressedAttribute1.w;
-
- translucencyByDistance.y = ((temp - floor(temp)) * SHIFT_LEFT8) / 255.0;
-
- temp = compressedAttribute1.y * SHIFT_RIGHT8;
- translucencyByDistance.w = ((temp - floor(temp)) * SHIFT_LEFT8) / 255.0;
- #endif
-
- ///////////////////////////////////////////////////////////////////////////
-
- vec4 color = czm_decodeRGB8(compressedAttribute0.x);
- vec4 outlineColor = czm_decodeRGB8(compressedAttribute0.y);
- vec4 pickColor = czm_decodeRGB8(compressedAttribute0.z);
- vec4 alphaPacked = czm_decodeRGB8(compressedAttribute0.w);
-
- color.a = alphaPacked.x;
- outlineColor.a = alphaPacked.y;
- pickColor.a = alphaPacked.z;
-
- ///////////////////////////////////////////////////////////////////////////
-
- vec4 p = czm_translateRelativeToEye(positionHigh, positionLow);
- vec4 positionEC = czm_modelViewRelativeToEye * p;
-
- ///////////////////////////////////////////////////////////////////////////
-
- #if defined(EYE_DISTANCE_SCALING) || defined(EYE_DISTANCE_TRANSLUCENCY) || defined(DISTANCE_DISPLAY_CONDITION) || defined(DISABLE_DEPTH_DISTANCE)
- float lengthSq;
- if (czm_sceneMode == czm_sceneMode2D)
- {
- // 2D camera distance is a special case
- // treat all billboards as flattened to the z=0.0 plane
- lengthSq = czm_eyeHeight2D.y;
- }
- else
- {
- lengthSq = dot(positionEC.xyz, positionEC.xyz);
- }
- #endif
-
- #ifdef EYE_DISTANCE_SCALING
- totalSize *= czm_nearFarScalar(scaleByDistance, lengthSq);
- #endif
- if (totalSize > 0.0) {
- // Add padding for anti-aliasing on both sides.
- totalSize += 3.0;
- }
-
- // Clamp to max point size.
- totalSize = min(totalSize, u_maxTotalPointSize);
- // If size is too small, push vertex behind near plane for clipping.
- // Note that context.minimumAliasedPointSize "will be at most 1.0".
- if (totalSize < 1.0)
- {
- positionEC.xyz = vec3(0.0);
- totalSize = 1.0;
- }
-
- float translucency = 1.0;
- #ifdef EYE_DISTANCE_TRANSLUCENCY
- translucency = czm_nearFarScalar(translucencyByDistance, lengthSq);
- // push vertex behind near plane for clipping
- if (translucency < 0.004)
- {
- positionEC.xyz = vec3(0.0);
- }
- #endif
-
- #ifdef DISTANCE_DISPLAY_CONDITION
- float nearSq = distanceDisplayConditionAndDisableDepthAndSplitDirection.x;
- float farSq = distanceDisplayConditionAndDisableDepthAndSplitDirection.y;
- if (lengthSq < nearSq || lengthSq > farSq) {
- // push vertex behind camera to force it to be clipped
- positionEC.xyz = vec3(0.0, 0.0, 1.0);
- }
- #endif
-
- gl_Position = czm_projection * positionEC;
- czm_vertexLogDepth();
-
- #ifdef DISABLE_DEPTH_DISTANCE
- float disableDepthTestDistance = distanceDisplayConditionAndDisableDepthAndSplitDirection.z;
- if (disableDepthTestDistance == 0.0 && czm_minimumDisableDepthTestDistance != 0.0)
- {
- disableDepthTestDistance = czm_minimumDisableDepthTestDistance;
- }
-
- if (disableDepthTestDistance != 0.0)
- {
- // Don't try to "multiply both sides" by w. Greater/less-than comparisons won't work for negative values of w.
- float zclip = gl_Position.z / gl_Position.w;
- bool clipped = (zclip < -1.0 || zclip > 1.0);
- if (!clipped && (disableDepthTestDistance < 0.0 || (lengthSq > 0.0 && lengthSq < disableDepthTestDistance)))
- {
- // Position z on the near plane.
- gl_Position.z = -gl_Position.w;
- #ifdef LOG_DEPTH
- czm_vertexLogDepth(vec4(czm_currentFrustum.x));
- #endif
- }
- }
- #endif
-
- v_color = color;
- v_color.a *= translucency * show;
- v_outlineColor = outlineColor;
- v_outlineColor.a *= translucency * show;
-
- v_innerPercent = 1.0 - outlinePercent;
- v_pixelDistance = 2.0 / totalSize;
- gl_PointSize = totalSize * show;
- gl_Position *= show;
-
- v_pickColor = pickColor;
- v_splitDirection = distanceDisplayConditionAndDisableDepthAndSplitDirection.w;
- }
|