@cesium/engine 9.0.0 → 9.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Build/ThirdParty/Workers/z-worker-pako.js +6 -5
- package/Build/Workers/{chunk-ZNVSKMQ2.js → chunk-2CSEEWHN.js} +6 -6
- package/Build/Workers/{chunk-2ZBL3MVO.js → chunk-34DGOKCO.js} +10 -12
- package/Build/Workers/{chunk-QKBGRKKG.js → chunk-3RZK5NNV.js} +4 -4
- package/Build/Workers/{chunk-RV7ZOSS6.js → chunk-3S2MFY4B.js} +13 -13
- package/Build/Workers/{chunk-5TIV3L26.js → chunk-4AJGCQFX.js} +13 -13
- package/Build/Workers/{chunk-YV4H2Y7M.js → chunk-4KIUON73.js} +4 -4
- package/Build/Workers/{chunk-QCQUZGXI.js → chunk-4PHPQRSH.js} +4 -4
- package/Build/Workers/{chunk-HBQPB6IH.js → chunk-66E3H2KU.js} +12 -12
- package/Build/Workers/{chunk-TJBU6GML.js → chunk-6HCAQOVK.js} +6 -6
- package/Build/Workers/{chunk-VR5RBW52.js → chunk-7LPEGKOF.js} +7 -7
- package/Build/Workers/{chunk-MWV7IZK4.js → chunk-7VZNXIKG.js} +7 -7
- package/Build/Workers/{chunk-SE4PXOEA.js → chunk-A6NCZSL3.js} +19 -19
- package/Build/Workers/{chunk-Z7FQLK6N.js → chunk-AOFMPKUB.js} +4 -4
- package/Build/Workers/{chunk-73FKKY52.js → chunk-AOIKO5Y7.js} +5 -5
- package/Build/Workers/{chunk-YDVSBWEO.js → chunk-BDUJXBVF.js} +1 -1
- package/Build/Workers/{chunk-ADOVHYWO.js → chunk-C5CE4OG6.js} +469 -6
- package/Build/Workers/{chunk-LQJ5FFFR.js → chunk-CE6GTZ4I.js} +11 -13
- package/Build/Workers/{chunk-DGDUKCJJ.js → chunk-CYAJYEKW.js} +6 -6
- package/Build/Workers/{chunk-NP2GYYE5.js → chunk-FOZQIHZK.js} +6 -6
- package/Build/Workers/{chunk-L4BW3RUA.js → chunk-G7CJQKKD.js} +7 -7
- package/Build/Workers/{chunk-CO35JNNE.js → chunk-GIFJ77E4.js} +4 -4
- package/Build/Workers/{chunk-7COR472O.js → chunk-I5TDPPC4.js} +7197 -5096
- package/Build/Workers/{chunk-RMOEYCZW.js → chunk-IBXGK4WV.js} +2 -2
- package/Build/Workers/{chunk-GFA4SMXV.js → chunk-JI2445T5.js} +11 -11
- package/Build/Workers/{chunk-5R6VWLMH.js → chunk-KPY4F4BW.js} +6 -6
- package/Build/Workers/{chunk-C3XBUYBO.js → chunk-LVJCR7DH.js} +17 -17
- package/Build/Workers/{chunk-X2F6BEPY.js → chunk-LW7WGHEU.js} +16 -16
- package/Build/Workers/{chunk-BCU2LH5T.js → chunk-MWYZ64MH.js} +10 -10
- package/Build/Workers/chunk-NI2R52QD.js +961 -0
- package/Build/Workers/{chunk-I37B3MZ2.js → chunk-PEABJLCK.js} +1 -1
- package/Build/Workers/{chunk-P2YAAMT2.js → chunk-PK7TEP3J.js} +15 -15
- package/Build/Workers/{chunk-3NCVAGDA.js → chunk-POLFRINT.js} +14 -14
- package/Build/Workers/{chunk-E6WXPSJS.js → chunk-PS6AEMBR.js} +7 -7
- package/Build/Workers/{chunk-M2AYBTNH.js → chunk-PWF3YJJ5.js} +13 -13
- package/Build/Workers/{chunk-2632RVPI.js → chunk-QKF7XXEQ.js} +7 -7
- package/Build/Workers/{chunk-EOXYZ34O.js → chunk-RL73GOEF.js} +2 -2
- package/Build/Workers/{chunk-6WF3KIF5.js → chunk-RR7EOKGZ.js} +10 -10
- package/Build/Workers/{chunk-GXUXEOE2.js → chunk-S4XDCPKD.js} +1 -1
- package/Build/Workers/{chunk-NZWNZA6S.js → chunk-TMMOULW3.js} +5 -5
- package/Build/Workers/{chunk-SS4ESNE3.js → chunk-U4IMCOF5.js} +2 -2
- package/Build/Workers/{chunk-PXB7T27O.js → chunk-UAJEGIWA.js} +6 -6
- package/Build/Workers/{chunk-TZORKRNK.js → chunk-UCPPWV64.js} +1 -1
- package/Build/Workers/{chunk-EPKE7GE3.js → chunk-V7JB576Q.js} +5 -5
- package/Build/Workers/{chunk-DPUSFA7S.js → chunk-WEGCQ5DY.js} +6 -6
- package/Build/Workers/{chunk-N4KXMWQU.js → chunk-WFICTTOE.js} +2 -2
- package/Build/Workers/{chunk-P4XKB3QZ.js → chunk-WWP3I7R5.js} +5 -5
- package/Build/Workers/{chunk-WHUSTDIB.js → chunk-XHLDDE65.js} +10 -10
- package/Build/Workers/{chunk-24YTYWNB.js → chunk-XWML5Y7N.js} +11 -13
- package/Build/Workers/{chunk-C6OI26DR.js → chunk-YLZTCEBJ.js} +1 -1
- package/Build/Workers/{chunk-LAQP3SCC.js → chunk-ZC4AGBZK.js} +2 -2
- package/Build/Workers/{chunk-RSJXEO2A.js → chunk-ZDP32RQI.js} +2 -2
- package/Build/Workers/{chunk-ZYPTP7GS.js → chunk-ZWPIM77Q.js} +11 -11
- package/Build/Workers/combineGeometry.js +22 -24
- package/Build/Workers/createBoxGeometry.js +16 -18
- package/Build/Workers/createBoxOutlineGeometry.js +14 -16
- package/Build/Workers/createCircleGeometry.js +24 -26
- package/Build/Workers/createCircleOutlineGeometry.js +17 -19
- package/Build/Workers/createCoplanarPolygonGeometry.js +33 -34
- package/Build/Workers/createCoplanarPolygonOutlineGeometry.js +29 -31
- package/Build/Workers/createCorridorGeometry.js +27 -29
- package/Build/Workers/createCorridorOutlineGeometry.js +26 -28
- package/Build/Workers/createCylinderGeometry.js +18 -20
- package/Build/Workers/createCylinderOutlineGeometry.js +16 -18
- package/Build/Workers/createEllipseGeometry.js +24 -26
- package/Build/Workers/createEllipseOutlineGeometry.js +17 -19
- package/Build/Workers/createEllipsoidGeometry.js +17 -19
- package/Build/Workers/createEllipsoidOutlineGeometry.js +16 -18
- package/Build/Workers/createFrustumGeometry.js +16 -18
- package/Build/Workers/createFrustumOutlineGeometry.js +18 -19
- package/Build/Workers/createGeometry.js +22 -24
- package/Build/Workers/createGroundPolylineGeometry.js +23 -25
- package/Build/Workers/createPlaneGeometry.js +14 -16
- package/Build/Workers/createPlaneOutlineGeometry.js +13 -15
- package/Build/Workers/createPolygonGeometry.js +32 -34
- package/Build/Workers/createPolygonOutlineGeometry.js +28 -30
- package/Build/Workers/createPolylineGeometry.js +23 -25
- package/Build/Workers/createPolylineVolumeGeometry.js +29 -31
- package/Build/Workers/createPolylineVolumeOutlineGeometry.js +25 -27
- package/Build/Workers/createRectangleGeometry.js +27 -29
- package/Build/Workers/createRectangleOutlineGeometry.js +18 -20
- package/Build/Workers/createSimplePolylineGeometry.js +21 -23
- package/Build/Workers/createSphereGeometry.js +17 -19
- package/Build/Workers/createSphereOutlineGeometry.js +16 -18
- package/Build/Workers/createTaskProcessorWorker.js +3 -3
- package/Build/Workers/createVectorTileClampedPolylines.js +14 -16
- package/Build/Workers/createVectorTileGeometries.js +22 -24
- package/Build/Workers/createVectorTilePoints.js +12 -12
- package/Build/Workers/createVectorTilePolygons.js +20 -22
- package/Build/Workers/createVectorTilePolylines.js +14 -16
- package/Build/Workers/createVerticesFromGoogleEarthEnterpriseBuffer.js +23 -25
- package/Build/Workers/createVerticesFromHeightmap.js +23 -25
- package/Build/Workers/createVerticesFromQuantizedTerrainMesh.js +19 -22
- package/Build/Workers/createWallGeometry.js +22 -24
- package/Build/Workers/createWallOutlineGeometry.js +21 -23
- package/Build/Workers/decodeDraco.js +11 -11
- package/Build/Workers/decodeGoogleEarthEnterprisePacket.js +5 -5
- package/Build/Workers/decodeI3S.js +10 -11
- package/Build/Workers/transcodeKTX2.js +8 -8
- package/Build/Workers/transferTypedArrayTest.js +1 -1
- package/Build/Workers/upsampleQuantizedTerrainMesh.js +20 -22
- package/Source/Core/Ion.js +1 -1
- package/Source/Core/PixelFormat.js +1 -0
- package/Source/Core/Rectangle.js +89 -0
- package/Source/DataSources/DataSourceDisplay.js +5 -0
- package/Source/Renderer/ShaderBuilder.js +6 -3
- package/Source/Scene/ArcGisMapService.js +1 -1
- package/Source/Scene/Billboard.js +5 -3
- package/Source/Scene/Cesium3DTile.js +65 -0
- package/Source/Scene/Cesium3DTileset.js +48 -1
- package/Source/Scene/ClippingPolygon.js +212 -0
- package/Source/Scene/ClippingPolygonCollection.js +968 -0
- package/Source/Scene/Globe.js +14 -0
- package/Source/Scene/GlobeSurfaceShaderSet.js +81 -15
- package/Source/Scene/GlobeSurfaceTileProvider.js +81 -1
- package/Source/Scene/Model/Model.js +83 -0
- package/Source/Scene/Model/Model3DTileContent.js +21 -0
- package/Source/Scene/Model/ModelClippingPolygonsPipelineStage.js +92 -0
- package/Source/Scene/Model/ModelSceneGraph.js +5 -0
- package/Source/Scene/Terrain.js +2 -2
- package/Source/Shaders/Builtin/CzmBuiltins.js +4 -0
- package/Source/Shaders/Builtin/Functions/clipPolygons.glsl +37 -0
- package/Source/Shaders/Builtin/Functions/clipPolygons.js +39 -0
- package/Source/Shaders/Builtin/Functions/unpackClippingExtents.glsl +14 -0
- package/Source/Shaders/Builtin/Functions/unpackClippingExtents.js +15 -0
- package/Source/Shaders/GlobeFS.glsl +12 -0
- package/Source/Shaders/GlobeFS.js +12 -0
- package/Source/Shaders/GlobeVS.glsl +32 -0
- package/Source/Shaders/GlobeVS.js +32 -0
- package/Source/Shaders/Model/GeometryStageVS.glsl +1 -1
- package/Source/Shaders/Model/GeometryStageVS.js +1 -1
- package/Source/Shaders/Model/ModelClippingPolygonsStageFS.glsl +6 -0
- package/Source/Shaders/Model/ModelClippingPolygonsStageFS.js +8 -0
- package/Source/Shaders/Model/ModelClippingPolygonsStageVS.glsl +27 -0
- package/Source/Shaders/Model/ModelClippingPolygonsStageVS.js +29 -0
- package/Source/Shaders/Model/ModelFS.glsl +6 -0
- package/Source/Shaders/Model/ModelFS.js +7 -1
- package/Source/Shaders/Model/ModelVS.glsl +4 -0
- package/Source/Shaders/Model/ModelVS.js +4 -0
- package/Source/Shaders/PolygonSignedDistanceFS.glsl +100 -0
- package/Source/Shaders/PolygonSignedDistanceFS.js +101 -0
- package/Source/ThirdParty/Workers/z-worker-pako.js +1 -1
- package/index.d.ts +227 -1
- package/index.js +34 -26
- package/package.json +1 -1
- package/Build/Workers/chunk-2KACWKS4.js +0 -501
- package/Build/Workers/chunk-2XPLH3JY.js +0 -2977
- package/Build/Workers/chunk-X6XOMPWL.js +0 -73
|
@@ -64,6 +64,7 @@ import czm_cascadeColor from './Functions/cascadeColor.js'
|
|
|
64
64
|
import czm_cascadeDistance from './Functions/cascadeDistance.js'
|
|
65
65
|
import czm_cascadeMatrix from './Functions/cascadeMatrix.js'
|
|
66
66
|
import czm_cascadeWeights from './Functions/cascadeWeights.js'
|
|
67
|
+
import czm_clipPolygons from './Functions/clipPolygons.js'
|
|
67
68
|
import czm_columbusViewMorph from './Functions/columbusViewMorph.js'
|
|
68
69
|
import czm_computeAtmosphereColor from './Functions/computeAtmosphereColor.js'
|
|
69
70
|
import czm_computeGroundAtmosphereScattering from './Functions/computeGroundAtmosphereScattering.js'
|
|
@@ -127,6 +128,7 @@ import czm_transformPlane from './Functions/transformPlane.js'
|
|
|
127
128
|
import czm_translateRelativeToEye from './Functions/translateRelativeToEye.js'
|
|
128
129
|
import czm_translucentPhong from './Functions/translucentPhong.js'
|
|
129
130
|
import czm_transpose from './Functions/transpose.js'
|
|
131
|
+
import czm_unpackClippingExtents from './Functions/unpackClippingExtents.js'
|
|
130
132
|
import czm_unpackDepth from './Functions/unpackDepth.js'
|
|
131
133
|
import czm_unpackFloat from './Functions/unpackFloat.js'
|
|
132
134
|
import czm_unpackUint from './Functions/unpackUint.js'
|
|
@@ -203,6 +205,7 @@ export default {
|
|
|
203
205
|
czm_cascadeDistance : czm_cascadeDistance,
|
|
204
206
|
czm_cascadeMatrix : czm_cascadeMatrix,
|
|
205
207
|
czm_cascadeWeights : czm_cascadeWeights,
|
|
208
|
+
czm_clipPolygons : czm_clipPolygons,
|
|
206
209
|
czm_columbusViewMorph : czm_columbusViewMorph,
|
|
207
210
|
czm_computeAtmosphereColor : czm_computeAtmosphereColor,
|
|
208
211
|
czm_computeGroundAtmosphereScattering : czm_computeGroundAtmosphereScattering,
|
|
@@ -266,6 +269,7 @@ export default {
|
|
|
266
269
|
czm_translateRelativeToEye : czm_translateRelativeToEye,
|
|
267
270
|
czm_translucentPhong : czm_translucentPhong,
|
|
268
271
|
czm_transpose : czm_transpose,
|
|
272
|
+
czm_unpackClippingExtents : czm_unpackClippingExtents,
|
|
269
273
|
czm_unpackDepth : czm_unpackDepth,
|
|
270
274
|
czm_unpackFloat : czm_unpackFloat,
|
|
271
275
|
czm_unpackUint : czm_unpackUint,
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
float getSignedDistance(vec2 uv, highp sampler2D clippingDistance) {
|
|
2
|
+
float signedDistance = texture(clippingDistance, uv).r;
|
|
3
|
+
return (signedDistance - 0.5) * 2.0;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
void czm_clipPolygons(highp sampler2D clippingDistance, int extentsLength, vec2 clippingPosition, int regionIndex) {
|
|
7
|
+
// Position is completely outside of polygons bounds
|
|
8
|
+
vec2 rectUv = clippingPosition;
|
|
9
|
+
if (regionIndex < 0 || rectUv.x <= 0.0 || rectUv.y <= 0.0 || rectUv.x >= 1.0 || rectUv.y >= 1.0) {
|
|
10
|
+
#ifdef CLIPPING_INVERSE
|
|
11
|
+
discard;
|
|
12
|
+
#endif
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
vec2 clippingDistanceTextureDimensions = vec2(textureSize(clippingDistance, 0));
|
|
17
|
+
vec2 sampleOffset = max(1.0 / clippingDistanceTextureDimensions, vec2(0.005));
|
|
18
|
+
float dimension = float(extentsLength);
|
|
19
|
+
if (extentsLength > 2) {
|
|
20
|
+
dimension = ceil(log2(float(extentsLength)));
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
vec2 textureOffset = vec2(mod(float(regionIndex), dimension), floor(float(regionIndex) / dimension)) / dimension;
|
|
24
|
+
vec2 uv = textureOffset + rectUv / dimension;
|
|
25
|
+
|
|
26
|
+
float signedDistance = getSignedDistance(uv, clippingDistance);
|
|
27
|
+
|
|
28
|
+
#ifdef CLIPPING_INVERSE
|
|
29
|
+
if (signedDistance > 0.0) {
|
|
30
|
+
discard;
|
|
31
|
+
}
|
|
32
|
+
#else
|
|
33
|
+
if (signedDistance < 0.0) {
|
|
34
|
+
discard;
|
|
35
|
+
}
|
|
36
|
+
#endif
|
|
37
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
//This file is automatically rebuilt by the Cesium build process.
|
|
2
|
+
export default "float getSignedDistance(vec2 uv, highp sampler2D clippingDistance) {\n\
|
|
3
|
+
float signedDistance = texture(clippingDistance, uv).r;\n\
|
|
4
|
+
return (signedDistance - 0.5) * 2.0;\n\
|
|
5
|
+
}\n\
|
|
6
|
+
\n\
|
|
7
|
+
void czm_clipPolygons(highp sampler2D clippingDistance, int extentsLength, vec2 clippingPosition, int regionIndex) {\n\
|
|
8
|
+
// Position is completely outside of polygons bounds\n\
|
|
9
|
+
vec2 rectUv = clippingPosition;\n\
|
|
10
|
+
if (regionIndex < 0 || rectUv.x <= 0.0 || rectUv.y <= 0.0 || rectUv.x >= 1.0 || rectUv.y >= 1.0) {\n\
|
|
11
|
+
#ifdef CLIPPING_INVERSE \n\
|
|
12
|
+
discard;\n\
|
|
13
|
+
#endif\n\
|
|
14
|
+
return;\n\
|
|
15
|
+
}\n\
|
|
16
|
+
\n\
|
|
17
|
+
vec2 clippingDistanceTextureDimensions = vec2(textureSize(clippingDistance, 0));\n\
|
|
18
|
+
vec2 sampleOffset = max(1.0 / clippingDistanceTextureDimensions, vec2(0.005));\n\
|
|
19
|
+
float dimension = float(extentsLength);\n\
|
|
20
|
+
if (extentsLength > 2) {\n\
|
|
21
|
+
dimension = ceil(log2(float(extentsLength)));\n\
|
|
22
|
+
}\n\
|
|
23
|
+
\n\
|
|
24
|
+
vec2 textureOffset = vec2(mod(float(regionIndex), dimension), floor(float(regionIndex) / dimension)) / dimension;\n\
|
|
25
|
+
vec2 uv = textureOffset + rectUv / dimension;\n\
|
|
26
|
+
\n\
|
|
27
|
+
float signedDistance = getSignedDistance(uv, clippingDistance);\n\
|
|
28
|
+
\n\
|
|
29
|
+
#ifdef CLIPPING_INVERSE\n\
|
|
30
|
+
if (signedDistance > 0.0) {\n\
|
|
31
|
+
discard;\n\
|
|
32
|
+
}\n\
|
|
33
|
+
#else\n\
|
|
34
|
+
if (signedDistance < 0.0) {\n\
|
|
35
|
+
discard;\n\
|
|
36
|
+
}\n\
|
|
37
|
+
#endif\n\
|
|
38
|
+
}\n\
|
|
39
|
+
";
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
vec2 getLookupUv(vec2 dimensions, int i) {
|
|
2
|
+
int pixY = i / int(dimensions.x);
|
|
3
|
+
int pixX = i - (pixY * int(dimensions.x));
|
|
4
|
+
float pixelWidth = 1.0 / dimensions.x;
|
|
5
|
+
float pixelHeight = 1.0 / dimensions.y;
|
|
6
|
+
float u = (float(pixX) + 0.5) * pixelWidth; // sample from center of pixel
|
|
7
|
+
float v = (float(pixY) + 0.5) * pixelHeight;
|
|
8
|
+
return vec2(u, v);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
vec4 czm_unpackClippingExtents(highp sampler2D extentsTexture, int index) {
|
|
12
|
+
vec2 textureDimensions = vec2(textureSize(extentsTexture, 0));
|
|
13
|
+
return texture(extentsTexture, getLookupUv(textureDimensions, index));
|
|
14
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
//This file is automatically rebuilt by the Cesium build process.
|
|
2
|
+
export default "vec2 getLookupUv(vec2 dimensions, int i) {\n\
|
|
3
|
+
int pixY = i / int(dimensions.x);\n\
|
|
4
|
+
int pixX = i - (pixY * int(dimensions.x));\n\
|
|
5
|
+
float pixelWidth = 1.0 / dimensions.x;\n\
|
|
6
|
+
float pixelHeight = 1.0 / dimensions.y;\n\
|
|
7
|
+
float u = (float(pixX) + 0.5) * pixelWidth; // sample from center of pixel\n\
|
|
8
|
+
float v = (float(pixY) + 0.5) * pixelHeight;\n\
|
|
9
|
+
return vec2(u, v);\n\
|
|
10
|
+
}\n\
|
|
11
|
+
\n\
|
|
12
|
+
vec4 czm_unpackClippingExtents(highp sampler2D extentsTexture, int index) {\n\
|
|
13
|
+
vec2 textureDimensions = vec2(textureSize(extentsTexture, 0));\n\
|
|
14
|
+
return texture(extentsTexture, getLookupUv(textureDimensions, index));\n\
|
|
15
|
+
}";
|
|
@@ -77,6 +77,12 @@ uniform mat4 u_clippingPlanesMatrix;
|
|
|
77
77
|
uniform vec4 u_clippingPlanesEdgeStyle;
|
|
78
78
|
#endif
|
|
79
79
|
|
|
80
|
+
#ifdef ENABLE_CLIPPING_POLYGONS
|
|
81
|
+
uniform highp sampler2D u_clippingDistance;
|
|
82
|
+
in vec2 v_clippingPosition;
|
|
83
|
+
flat in int v_regionIndex;
|
|
84
|
+
#endif
|
|
85
|
+
|
|
80
86
|
#if defined(GROUND_ATMOSPHERE) || defined(FOG) && defined(DYNAMIC_ATMOSPHERE_LIGHTING) && (defined(ENABLE_VERTEX_LIGHTING) || defined(ENABLE_DAYNIGHT_SHADING))
|
|
81
87
|
uniform float u_minimumBrightness;
|
|
82
88
|
#endif
|
|
@@ -413,6 +419,12 @@ void main()
|
|
|
413
419
|
}
|
|
414
420
|
#endif
|
|
415
421
|
|
|
422
|
+
#ifdef ENABLE_CLIPPING_POLYGONS
|
|
423
|
+
vec2 clippingPosition = v_clippingPosition;
|
|
424
|
+
int regionIndex = v_regionIndex;
|
|
425
|
+
clipPolygons(u_clippingDistance, CLIPPING_POLYGON_REGIONS_LENGTH, clippingPosition, regionIndex);
|
|
426
|
+
#endif
|
|
427
|
+
|
|
416
428
|
#ifdef HIGHLIGHT_FILL_TILE
|
|
417
429
|
finalColor = vec4(mix(finalColor.rgb, u_fillHighlightColor.rgb, u_fillHighlightColor.a), finalColor.a);
|
|
418
430
|
#endif
|
|
@@ -78,6 +78,12 @@ uniform mat4 u_clippingPlanesMatrix;\n\
|
|
|
78
78
|
uniform vec4 u_clippingPlanesEdgeStyle;\n\
|
|
79
79
|
#endif\n\
|
|
80
80
|
\n\
|
|
81
|
+
#ifdef ENABLE_CLIPPING_POLYGONS\n\
|
|
82
|
+
uniform highp sampler2D u_clippingDistance;\n\
|
|
83
|
+
in vec2 v_clippingPosition;\n\
|
|
84
|
+
flat in int v_regionIndex;\n\
|
|
85
|
+
#endif\n\
|
|
86
|
+
\n\
|
|
81
87
|
#if defined(GROUND_ATMOSPHERE) || defined(FOG) && defined(DYNAMIC_ATMOSPHERE_LIGHTING) && (defined(ENABLE_VERTEX_LIGHTING) || defined(ENABLE_DAYNIGHT_SHADING))\n\
|
|
82
88
|
uniform float u_minimumBrightness;\n\
|
|
83
89
|
#endif\n\
|
|
@@ -414,6 +420,12 @@ void main()\n\
|
|
|
414
420
|
}\n\
|
|
415
421
|
#endif\n\
|
|
416
422
|
\n\
|
|
423
|
+
#ifdef ENABLE_CLIPPING_POLYGONS\n\
|
|
424
|
+
vec2 clippingPosition = v_clippingPosition;\n\
|
|
425
|
+
int regionIndex = v_regionIndex;\n\
|
|
426
|
+
clipPolygons(u_clippingDistance, CLIPPING_POLYGON_REGIONS_LENGTH, clippingPosition, regionIndex); \n\
|
|
427
|
+
#endif\n\
|
|
428
|
+
\n\
|
|
417
429
|
#ifdef HIGHLIGHT_FILL_TILE\n\
|
|
418
430
|
finalColor = vec4(mix(finalColor.rgb, u_fillHighlightColor.rgb, u_fillHighlightColor.a), finalColor.a);\n\
|
|
419
431
|
#endif\n\
|
|
@@ -46,6 +46,12 @@ out vec3 v_atmosphereMieColor;
|
|
|
46
46
|
out float v_atmosphereOpacity;
|
|
47
47
|
#endif
|
|
48
48
|
|
|
49
|
+
#ifdef ENABLE_CLIPPING_POLYGONS
|
|
50
|
+
uniform highp sampler2D u_clippingExtents;
|
|
51
|
+
out vec2 v_clippingPosition;
|
|
52
|
+
flat out int v_regionIndex;
|
|
53
|
+
#endif
|
|
54
|
+
|
|
49
55
|
// These functions are generated at runtime.
|
|
50
56
|
vec4 getPosition(vec3 position, float height, vec2 textureCoordinates);
|
|
51
57
|
float get2DYPositionFraction(vec2 textureCoordinates);
|
|
@@ -207,6 +213,32 @@ void main()
|
|
|
207
213
|
v_normalEC = czm_normal3D * v_normalMC;
|
|
208
214
|
#endif
|
|
209
215
|
|
|
216
|
+
#ifdef ENABLE_CLIPPING_POLYGONS
|
|
217
|
+
vec2 sphericalLatLong = czm_approximateSphericalCoordinates(position3DWC);
|
|
218
|
+
sphericalLatLong.y = czm_branchFreeTernary(sphericalLatLong.y < czm_pi, sphericalLatLong.y, sphericalLatLong.y - czm_twoPi);
|
|
219
|
+
|
|
220
|
+
vec2 minDistance = vec2(czm_infinity);
|
|
221
|
+
v_clippingPosition = vec2(czm_infinity);
|
|
222
|
+
v_regionIndex = -1;
|
|
223
|
+
|
|
224
|
+
for (int regionIndex = 0; regionIndex < CLIPPING_POLYGON_REGIONS_LENGTH; regionIndex++) {
|
|
225
|
+
vec4 extents = unpackClippingExtents(u_clippingExtents, regionIndex);
|
|
226
|
+
vec2 rectUv = (sphericalLatLong.yx - extents.yx) * extents.wz;
|
|
227
|
+
|
|
228
|
+
vec2 clamped = clamp(rectUv, vec2(0.0), vec2(1.0));
|
|
229
|
+
vec2 distance = abs(rectUv - clamped) * extents.wz;
|
|
230
|
+
|
|
231
|
+
float threshold = 0.01;
|
|
232
|
+
if (minDistance.x > distance.x || minDistance.y > distance.y) {
|
|
233
|
+
minDistance = distance;
|
|
234
|
+
v_clippingPosition = rectUv;
|
|
235
|
+
if (rectUv.x > threshold && rectUv.y > threshold && rectUv.x < 1.0 - threshold && rectUv.y < 1.0 - threshold) {
|
|
236
|
+
v_regionIndex = regionIndex;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
#endif
|
|
241
|
+
|
|
210
242
|
#if defined(FOG) || (defined(GROUND_ATMOSPHERE) && !defined(PER_FRAGMENT_GROUND_ATMOSPHERE))
|
|
211
243
|
|
|
212
244
|
bool dynamicLighting = false;
|
|
@@ -47,6 +47,12 @@ out vec3 v_atmosphereMieColor;\n\
|
|
|
47
47
|
out float v_atmosphereOpacity;\n\
|
|
48
48
|
#endif\n\
|
|
49
49
|
\n\
|
|
50
|
+
#ifdef ENABLE_CLIPPING_POLYGONS\n\
|
|
51
|
+
uniform highp sampler2D u_clippingExtents;\n\
|
|
52
|
+
out vec2 v_clippingPosition;\n\
|
|
53
|
+
flat out int v_regionIndex;\n\
|
|
54
|
+
#endif\n\
|
|
55
|
+
\n\
|
|
50
56
|
// These functions are generated at runtime.\n\
|
|
51
57
|
vec4 getPosition(vec3 position, float height, vec2 textureCoordinates);\n\
|
|
52
58
|
float get2DYPositionFraction(vec2 textureCoordinates);\n\
|
|
@@ -208,6 +214,32 @@ void main()\n\
|
|
|
208
214
|
v_normalEC = czm_normal3D * v_normalMC;\n\
|
|
209
215
|
#endif\n\
|
|
210
216
|
\n\
|
|
217
|
+
#ifdef ENABLE_CLIPPING_POLYGONS\n\
|
|
218
|
+
vec2 sphericalLatLong = czm_approximateSphericalCoordinates(position3DWC);\n\
|
|
219
|
+
sphericalLatLong.y = czm_branchFreeTernary(sphericalLatLong.y < czm_pi, sphericalLatLong.y, sphericalLatLong.y - czm_twoPi);\n\
|
|
220
|
+
\n\
|
|
221
|
+
vec2 minDistance = vec2(czm_infinity);\n\
|
|
222
|
+
v_clippingPosition = vec2(czm_infinity);\n\
|
|
223
|
+
v_regionIndex = -1;\n\
|
|
224
|
+
\n\
|
|
225
|
+
for (int regionIndex = 0; regionIndex < CLIPPING_POLYGON_REGIONS_LENGTH; regionIndex++) {\n\
|
|
226
|
+
vec4 extents = unpackClippingExtents(u_clippingExtents, regionIndex);\n\
|
|
227
|
+
vec2 rectUv = (sphericalLatLong.yx - extents.yx) * extents.wz;\n\
|
|
228
|
+
\n\
|
|
229
|
+
vec2 clamped = clamp(rectUv, vec2(0.0), vec2(1.0));\n\
|
|
230
|
+
vec2 distance = abs(rectUv - clamped) * extents.wz;\n\
|
|
231
|
+
\n\
|
|
232
|
+
float threshold = 0.01;\n\
|
|
233
|
+
if (minDistance.x > distance.x || minDistance.y > distance.y) {\n\
|
|
234
|
+
minDistance = distance;\n\
|
|
235
|
+
v_clippingPosition = rectUv;\n\
|
|
236
|
+
if (rectUv.x > threshold && rectUv.y > threshold && rectUv.x < 1.0 - threshold && rectUv.y < 1.0 - threshold) {\n\
|
|
237
|
+
v_regionIndex = regionIndex;\n\
|
|
238
|
+
}\n\
|
|
239
|
+
}\n\
|
|
240
|
+
}\n\
|
|
241
|
+
#endif\n\
|
|
242
|
+
\n\
|
|
211
243
|
#if defined(FOG) || (defined(GROUND_ATMOSPHERE) && !defined(PER_FRAGMENT_GROUND_ATMOSPHERE))\n\
|
|
212
244
|
\n\
|
|
213
245
|
bool dynamicLighting = false;\n\
|
|
@@ -16,7 +16,7 @@ vec4 geometryStage(inout ProcessedAttributes attributes, mat4 modelView, mat3 no
|
|
|
16
16
|
#endif
|
|
17
17
|
|
|
18
18
|
// Sometimes the custom shader and/or style needs this
|
|
19
|
-
#if defined(COMPUTE_POSITION_WC_CUSTOM_SHADER) || defined(COMPUTE_POSITION_WC_STYLE) || defined(COMPUTE_POSITION_WC_ATMOSPHERE)
|
|
19
|
+
#if defined(COMPUTE_POSITION_WC_CUSTOM_SHADER) || defined(COMPUTE_POSITION_WC_STYLE) || defined(COMPUTE_POSITION_WC_ATMOSPHERE) || defined(ENABLE_CLIPPING_POLYGONS)
|
|
20
20
|
// Note that this is a 32-bit position which may result in jitter on small
|
|
21
21
|
// scales.
|
|
22
22
|
v_positionWC = (czm_model * vec4(positionMC, 1.0)).xyz;
|
|
@@ -17,7 +17,7 @@ export default "vec4 geometryStage(inout ProcessedAttributes attributes, mat4 mo
|
|
|
17
17
|
#endif\n\
|
|
18
18
|
\n\
|
|
19
19
|
// Sometimes the custom shader and/or style needs this\n\
|
|
20
|
-
#if defined(COMPUTE_POSITION_WC_CUSTOM_SHADER) || defined(COMPUTE_POSITION_WC_STYLE) || defined(COMPUTE_POSITION_WC_ATMOSPHERE)\n\
|
|
20
|
+
#if defined(COMPUTE_POSITION_WC_CUSTOM_SHADER) || defined(COMPUTE_POSITION_WC_STYLE) || defined(COMPUTE_POSITION_WC_ATMOSPHERE) || defined(ENABLE_CLIPPING_POLYGONS)\n\
|
|
21
21
|
// Note that this is a 32-bit position which may result in jitter on small\n\
|
|
22
22
|
// scales.\n\
|
|
23
23
|
v_positionWC = (czm_model * vec4(positionMC, 1.0)).xyz;\n\
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
//This file is automatically rebuilt by the Cesium build process.
|
|
2
|
+
export default "void modelClippingPolygonsStage()\n\
|
|
3
|
+
{\n\
|
|
4
|
+
vec2 clippingPosition = v_clippingPosition;\n\
|
|
5
|
+
int regionIndex = v_regionIndex;\n\
|
|
6
|
+
czm_clipPolygons(model_clippingDistance, CLIPPING_POLYGON_REGIONS_LENGTH, clippingPosition, regionIndex);\n\
|
|
7
|
+
}\n\
|
|
8
|
+
";
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
void modelClippingPolygonsStage(ProcessedAttributes attributes)
|
|
2
|
+
{
|
|
3
|
+
vec2 sphericalLatLong = czm_approximateSphericalCoordinates(v_positionWC);
|
|
4
|
+
sphericalLatLong.y = czm_branchFreeTernary(sphericalLatLong.y < czm_pi, sphericalLatLong.y, sphericalLatLong.y - czm_twoPi);
|
|
5
|
+
|
|
6
|
+
vec2 minDistance = vec2(czm_infinity);
|
|
7
|
+
v_regionIndex = -1;
|
|
8
|
+
v_clippingPosition = vec2(czm_infinity);
|
|
9
|
+
|
|
10
|
+
for (int regionIndex = 0; regionIndex < CLIPPING_POLYGON_REGIONS_LENGTH; regionIndex++) {
|
|
11
|
+
vec4 extents = czm_unpackClippingExtents(model_clippingExtents, regionIndex);
|
|
12
|
+
vec2 rectUv = (sphericalLatLong.yx - extents.yx) * extents.wz;
|
|
13
|
+
|
|
14
|
+
vec2 clamped = clamp(rectUv, vec2(0.0), vec2(1.0));
|
|
15
|
+
vec2 distance = abs(rectUv - clamped) * extents.wz;
|
|
16
|
+
|
|
17
|
+
if (minDistance.x > distance.x || minDistance.y > distance.y) {
|
|
18
|
+
minDistance = distance;
|
|
19
|
+
v_clippingPosition = rectUv;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
float threshold = 0.01;
|
|
23
|
+
if (rectUv.x > threshold && rectUv.y > threshold && rectUv.x < 1.0 - threshold && rectUv.y < 1.0 - threshold) {
|
|
24
|
+
v_regionIndex = regionIndex;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
//This file is automatically rebuilt by the Cesium build process.
|
|
2
|
+
export default "void modelClippingPolygonsStage(ProcessedAttributes attributes)\n\
|
|
3
|
+
{\n\
|
|
4
|
+
vec2 sphericalLatLong = czm_approximateSphericalCoordinates(v_positionWC);\n\
|
|
5
|
+
sphericalLatLong.y = czm_branchFreeTernary(sphericalLatLong.y < czm_pi, sphericalLatLong.y, sphericalLatLong.y - czm_twoPi);\n\
|
|
6
|
+
\n\
|
|
7
|
+
vec2 minDistance = vec2(czm_infinity);\n\
|
|
8
|
+
v_regionIndex = -1;\n\
|
|
9
|
+
v_clippingPosition = vec2(czm_infinity);\n\
|
|
10
|
+
\n\
|
|
11
|
+
for (int regionIndex = 0; regionIndex < CLIPPING_POLYGON_REGIONS_LENGTH; regionIndex++) {\n\
|
|
12
|
+
vec4 extents = czm_unpackClippingExtents(model_clippingExtents, regionIndex);\n\
|
|
13
|
+
vec2 rectUv = (sphericalLatLong.yx - extents.yx) * extents.wz;\n\
|
|
14
|
+
\n\
|
|
15
|
+
vec2 clamped = clamp(rectUv, vec2(0.0), vec2(1.0));\n\
|
|
16
|
+
vec2 distance = abs(rectUv - clamped) * extents.wz;\n\
|
|
17
|
+
\n\
|
|
18
|
+
if (minDistance.x > distance.x || minDistance.y > distance.y) {\n\
|
|
19
|
+
minDistance = distance;\n\
|
|
20
|
+
v_clippingPosition = rectUv;\n\
|
|
21
|
+
}\n\
|
|
22
|
+
\n\
|
|
23
|
+
float threshold = 0.01;\n\
|
|
24
|
+
if (rectUv.x > threshold && rectUv.y > threshold && rectUv.x < 1.0 - threshold && rectUv.y < 1.0 - threshold) {\n\
|
|
25
|
+
v_regionIndex = regionIndex;\n\
|
|
26
|
+
}\n\
|
|
27
|
+
}\n\
|
|
28
|
+
}\n\
|
|
29
|
+
";
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
|
|
2
|
+
precision highp float;
|
|
1
3
|
czm_modelMaterial defaultModelMaterial()
|
|
2
4
|
{
|
|
3
5
|
czm_modelMaterial material;
|
|
@@ -75,6 +77,10 @@ void main()
|
|
|
75
77
|
modelClippingPlanesStage(color);
|
|
76
78
|
#endif
|
|
77
79
|
|
|
80
|
+
#ifdef ENABLE_CLIPPING_POLYGONS
|
|
81
|
+
modelClippingPolygonsStage();
|
|
82
|
+
#endif
|
|
83
|
+
|
|
78
84
|
#if defined(HAS_SILHOUETTE) && defined(HAS_NORMALS)
|
|
79
85
|
silhouetteStage(color);
|
|
80
86
|
#endif
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
//This file is automatically rebuilt by the Cesium build process.
|
|
2
|
-
export default "
|
|
2
|
+
export default "\n\
|
|
3
|
+
precision highp float;\n\
|
|
4
|
+
czm_modelMaterial defaultModelMaterial()\n\
|
|
3
5
|
{\n\
|
|
4
6
|
czm_modelMaterial material;\n\
|
|
5
7
|
material.diffuse = vec3(0.0);\n\
|
|
@@ -75,6 +77,10 @@ void main()\n\
|
|
|
75
77
|
#ifdef HAS_CLIPPING_PLANES\n\
|
|
76
78
|
modelClippingPlanesStage(color);\n\
|
|
77
79
|
#endif\n\
|
|
80
|
+
\n\
|
|
81
|
+
#ifdef ENABLE_CLIPPING_POLYGONS\n\
|
|
82
|
+
modelClippingPolygonsStage();\n\
|
|
83
|
+
#endif\n\
|
|
78
84
|
\n\
|
|
79
85
|
#if defined(HAS_SILHOUETTE) && defined(HAS_NORMALS)\n\
|
|
80
86
|
silhouetteStage(color);\n\
|
|
@@ -111,6 +111,10 @@ void main()\n\
|
|
|
111
111
|
#ifdef HAS_ATMOSPHERE\n\
|
|
112
112
|
atmosphereStage(attributes);\n\
|
|
113
113
|
#endif\n\
|
|
114
|
+
\n\
|
|
115
|
+
#ifdef ENABLE_CLIPPING_POLYGONS\n\
|
|
116
|
+
modelClippingPolygonsStage(attributes);\n\
|
|
117
|
+
#endif\n\
|
|
114
118
|
\n\
|
|
115
119
|
#ifdef HAS_SILHOUETTE\n\
|
|
116
120
|
silhouetteStage(attributes, positionClip);\n\
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
in vec2 v_textureCoordinates;
|
|
2
|
+
|
|
3
|
+
uniform int u_polygonsLength;
|
|
4
|
+
uniform int u_extentsLength;
|
|
5
|
+
uniform highp sampler2D u_polygonTexture;
|
|
6
|
+
uniform highp sampler2D u_extentsTexture;
|
|
7
|
+
|
|
8
|
+
int getPolygonIndex(float dimension, vec2 coord) {
|
|
9
|
+
vec2 uv = coord.xy * dimension;
|
|
10
|
+
return int(floor(uv.y) * dimension + floor(uv.x));
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
vec2 getLookupUv(ivec2 dimensions, int i) {
|
|
14
|
+
int pixY = i / dimensions.x;
|
|
15
|
+
int pixX = i - (pixY * dimensions.x);
|
|
16
|
+
float pixelWidth = 1.0 / float(dimensions.x);
|
|
17
|
+
float pixelHeight = 1.0 / float(dimensions.y);
|
|
18
|
+
float u = (float(pixX) + 0.5) * pixelWidth; // sample from center of pixel
|
|
19
|
+
float v = (float(pixY) + 0.5) * pixelHeight;
|
|
20
|
+
return vec2(u, v);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
vec4 getExtents(int i) {
|
|
24
|
+
return texture(u_extentsTexture, getLookupUv(textureSize(u_extentsTexture, 0), i));
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
ivec2 getPositionsLengthAndExtentsIndex(int i) {
|
|
28
|
+
vec2 uv = getLookupUv(textureSize(u_polygonTexture, 0), i);
|
|
29
|
+
vec4 value = texture(u_polygonTexture, uv);
|
|
30
|
+
return ivec2(int(value.x), int(value.y));
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
vec2 getPolygonPosition(int i) {
|
|
34
|
+
vec2 uv = getLookupUv(textureSize(u_polygonTexture, 0), i);
|
|
35
|
+
return texture(u_polygonTexture, uv).xy;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
vec2 getCoordinates(vec2 textureCoordinates, vec4 extents) {
|
|
39
|
+
float latitude = mix(extents.x, extents.x + 1.0 / extents.z, textureCoordinates.y);
|
|
40
|
+
float longitude = mix(extents.y, extents.y + 1.0 / extents.w, textureCoordinates.x);
|
|
41
|
+
return vec2(latitude, longitude);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
void main() {
|
|
45
|
+
int lastPolygonIndex = 0;
|
|
46
|
+
out_FragColor = vec4(1.0);
|
|
47
|
+
|
|
48
|
+
// Get the relevant region of the texture
|
|
49
|
+
float dimension = float(u_extentsLength);
|
|
50
|
+
if (u_extentsLength > 2) {
|
|
51
|
+
dimension = ceil(log2(float(u_extentsLength)));
|
|
52
|
+
}
|
|
53
|
+
int regionIndex = getPolygonIndex(dimension, v_textureCoordinates);
|
|
54
|
+
|
|
55
|
+
for (int polygonIndex = 0; polygonIndex < u_polygonsLength; polygonIndex++) {
|
|
56
|
+
ivec2 positionsLengthAndExtents = getPositionsLengthAndExtentsIndex(lastPolygonIndex);
|
|
57
|
+
int positionsLength = positionsLengthAndExtents.x;
|
|
58
|
+
int polygonExtentsIndex = positionsLengthAndExtents.y;
|
|
59
|
+
lastPolygonIndex += 1;
|
|
60
|
+
|
|
61
|
+
// Only compute signed distance for the relevant part of the atlas
|
|
62
|
+
if (polygonExtentsIndex == regionIndex) {
|
|
63
|
+
float clipAmount = czm_infinity;
|
|
64
|
+
vec4 extents = getExtents(polygonExtentsIndex);
|
|
65
|
+
vec2 textureOffset = vec2(mod(float(polygonExtentsIndex), dimension), floor(float(polygonExtentsIndex) / dimension)) / dimension;
|
|
66
|
+
vec2 p = getCoordinates((v_textureCoordinates - textureOffset) * dimension, extents);
|
|
67
|
+
float s = 1.0;
|
|
68
|
+
|
|
69
|
+
// Check each edge for absolute distance
|
|
70
|
+
for (int i = 0, j = positionsLength - 1; i < positionsLength; j = i, i++) {
|
|
71
|
+
vec2 a = getPolygonPosition(lastPolygonIndex + i);
|
|
72
|
+
vec2 b = getPolygonPosition(lastPolygonIndex + j);
|
|
73
|
+
|
|
74
|
+
vec2 ab = b - a;
|
|
75
|
+
vec2 pa = p - a;
|
|
76
|
+
float t = dot(pa, ab) / dot(ab, ab);
|
|
77
|
+
t = clamp(t, 0.0, 1.0);
|
|
78
|
+
|
|
79
|
+
vec2 pq = pa - t * ab;
|
|
80
|
+
float d = length(pq);
|
|
81
|
+
|
|
82
|
+
// Inside / outside computation to determine sign
|
|
83
|
+
bvec3 cond = bvec3(p.y >= a.y,
|
|
84
|
+
p.y < b.y,
|
|
85
|
+
ab.x * pa.y > ab.y * pa.x);
|
|
86
|
+
if (all(cond) || all(not(cond))) s = -s;
|
|
87
|
+
if (abs(d) < abs(clipAmount)) {
|
|
88
|
+
clipAmount = d;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// Normalize the range to [0,1]
|
|
93
|
+
vec4 result = (s * vec4(clipAmount * length(extents.zw))) / 2.0 + 0.5;
|
|
94
|
+
// In the case where we've iterated through multiple polygons, take the minimum
|
|
95
|
+
out_FragColor = min(out_FragColor, result);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
lastPolygonIndex += positionsLength;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
//This file is automatically rebuilt by the Cesium build process.
|
|
2
|
+
export default "in vec2 v_textureCoordinates;\n\
|
|
3
|
+
\n\
|
|
4
|
+
uniform int u_polygonsLength;\n\
|
|
5
|
+
uniform int u_extentsLength;\n\
|
|
6
|
+
uniform highp sampler2D u_polygonTexture;\n\
|
|
7
|
+
uniform highp sampler2D u_extentsTexture;\n\
|
|
8
|
+
\n\
|
|
9
|
+
int getPolygonIndex(float dimension, vec2 coord) {\n\
|
|
10
|
+
vec2 uv = coord.xy * dimension;\n\
|
|
11
|
+
return int(floor(uv.y) * dimension + floor(uv.x));\n\
|
|
12
|
+
}\n\
|
|
13
|
+
\n\
|
|
14
|
+
vec2 getLookupUv(ivec2 dimensions, int i) {\n\
|
|
15
|
+
int pixY = i / dimensions.x;\n\
|
|
16
|
+
int pixX = i - (pixY * dimensions.x);\n\
|
|
17
|
+
float pixelWidth = 1.0 / float(dimensions.x);\n\
|
|
18
|
+
float pixelHeight = 1.0 / float(dimensions.y);\n\
|
|
19
|
+
float u = (float(pixX) + 0.5) * pixelWidth; // sample from center of pixel\n\
|
|
20
|
+
float v = (float(pixY) + 0.5) * pixelHeight;\n\
|
|
21
|
+
return vec2(u, v);\n\
|
|
22
|
+
}\n\
|
|
23
|
+
\n\
|
|
24
|
+
vec4 getExtents(int i) {\n\
|
|
25
|
+
return texture(u_extentsTexture, getLookupUv(textureSize(u_extentsTexture, 0), i));\n\
|
|
26
|
+
}\n\
|
|
27
|
+
\n\
|
|
28
|
+
ivec2 getPositionsLengthAndExtentsIndex(int i) {\n\
|
|
29
|
+
vec2 uv = getLookupUv(textureSize(u_polygonTexture, 0), i);\n\
|
|
30
|
+
vec4 value = texture(u_polygonTexture, uv);\n\
|
|
31
|
+
return ivec2(int(value.x), int(value.y));\n\
|
|
32
|
+
}\n\
|
|
33
|
+
\n\
|
|
34
|
+
vec2 getPolygonPosition(int i) {\n\
|
|
35
|
+
vec2 uv = getLookupUv(textureSize(u_polygonTexture, 0), i);\n\
|
|
36
|
+
return texture(u_polygonTexture, uv).xy;\n\
|
|
37
|
+
}\n\
|
|
38
|
+
\n\
|
|
39
|
+
vec2 getCoordinates(vec2 textureCoordinates, vec4 extents) {\n\
|
|
40
|
+
float latitude = mix(extents.x, extents.x + 1.0 / extents.z, textureCoordinates.y);\n\
|
|
41
|
+
float longitude = mix(extents.y, extents.y + 1.0 / extents.w, textureCoordinates.x);\n\
|
|
42
|
+
return vec2(latitude, longitude);\n\
|
|
43
|
+
}\n\
|
|
44
|
+
\n\
|
|
45
|
+
void main() {\n\
|
|
46
|
+
int lastPolygonIndex = 0;\n\
|
|
47
|
+
out_FragColor = vec4(1.0);\n\
|
|
48
|
+
\n\
|
|
49
|
+
// Get the relevant region of the texture\n\
|
|
50
|
+
float dimension = float(u_extentsLength);\n\
|
|
51
|
+
if (u_extentsLength > 2) {\n\
|
|
52
|
+
dimension = ceil(log2(float(u_extentsLength)));\n\
|
|
53
|
+
}\n\
|
|
54
|
+
int regionIndex = getPolygonIndex(dimension, v_textureCoordinates);\n\
|
|
55
|
+
\n\
|
|
56
|
+
for (int polygonIndex = 0; polygonIndex < u_polygonsLength; polygonIndex++) {\n\
|
|
57
|
+
ivec2 positionsLengthAndExtents = getPositionsLengthAndExtentsIndex(lastPolygonIndex);\n\
|
|
58
|
+
int positionsLength = positionsLengthAndExtents.x;\n\
|
|
59
|
+
int polygonExtentsIndex = positionsLengthAndExtents.y;\n\
|
|
60
|
+
lastPolygonIndex += 1;\n\
|
|
61
|
+
\n\
|
|
62
|
+
// Only compute signed distance for the relevant part of the atlas\n\
|
|
63
|
+
if (polygonExtentsIndex == regionIndex) {\n\
|
|
64
|
+
float clipAmount = czm_infinity;\n\
|
|
65
|
+
vec4 extents = getExtents(polygonExtentsIndex);\n\
|
|
66
|
+
vec2 textureOffset = vec2(mod(float(polygonExtentsIndex), dimension), floor(float(polygonExtentsIndex) / dimension)) / dimension;\n\
|
|
67
|
+
vec2 p = getCoordinates((v_textureCoordinates - textureOffset) * dimension, extents);\n\
|
|
68
|
+
float s = 1.0;\n\
|
|
69
|
+
\n\
|
|
70
|
+
// Check each edge for absolute distance\n\
|
|
71
|
+
for (int i = 0, j = positionsLength - 1; i < positionsLength; j = i, i++) {\n\
|
|
72
|
+
vec2 a = getPolygonPosition(lastPolygonIndex + i);\n\
|
|
73
|
+
vec2 b = getPolygonPosition(lastPolygonIndex + j);\n\
|
|
74
|
+
\n\
|
|
75
|
+
vec2 ab = b - a;\n\
|
|
76
|
+
vec2 pa = p - a;\n\
|
|
77
|
+
float t = dot(pa, ab) / dot(ab, ab);\n\
|
|
78
|
+
t = clamp(t, 0.0, 1.0);\n\
|
|
79
|
+
\n\
|
|
80
|
+
vec2 pq = pa - t * ab;\n\
|
|
81
|
+
float d = length(pq);\n\
|
|
82
|
+
\n\
|
|
83
|
+
// Inside / outside computation to determine sign\n\
|
|
84
|
+
bvec3 cond = bvec3(p.y >= a.y, \n\
|
|
85
|
+
p.y < b.y, \n\
|
|
86
|
+
ab.x * pa.y > ab.y * pa.x);\n\
|
|
87
|
+
if (all(cond) || all(not(cond))) s = -s;\n\
|
|
88
|
+
if (abs(d) < abs(clipAmount)) {\n\
|
|
89
|
+
clipAmount = d;\n\
|
|
90
|
+
}\n\
|
|
91
|
+
}\n\
|
|
92
|
+
\n\
|
|
93
|
+
// Normalize the range to [0,1]\n\
|
|
94
|
+
vec4 result = (s * vec4(clipAmount * length(extents.zw))) / 2.0 + 0.5;\n\
|
|
95
|
+
// In the case where we've iterated through multiple polygons, take the minimum\n\
|
|
96
|
+
out_FragColor = min(out_FragColor, result);\n\
|
|
97
|
+
}\n\
|
|
98
|
+
\n\
|
|
99
|
+
lastPolygonIndex += positionsLength;\n\
|
|
100
|
+
}\n\
|
|
101
|
+
}";
|