@cesium/engine 0.1.0 → 1.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.
Files changed (217) hide show
  1. package/Build/Workers/{AttributeCompression-4589338a.js → AttributeCompression-b646d393.js} +1 -1
  2. package/Build/Workers/{AxisAlignedBoundingBox-bfb1234f.js → AxisAlignedBoundingBox-a4321399.js} +1 -1
  3. package/Build/Workers/{BoundingRectangle-7ffc2153.js → BoundingRectangle-80d8801f.js} +1 -1
  4. package/Build/Workers/{BoxGeometry-93f344a3.js → BoxGeometry-33c10a4f.js} +1 -1
  5. package/Build/Workers/{Color-0c5aaf47.js → Color-1bf9a6e0.js} +1 -1
  6. package/Build/Workers/{CoplanarPolygonGeometryLibrary-6597982a.js → CoplanarPolygonGeometryLibrary-5c5b981b.js} +1 -1
  7. package/Build/Workers/{CorridorGeometryLibrary-2119580e.js → CorridorGeometryLibrary-7cbae7a0.js} +1 -1
  8. package/Build/Workers/{CylinderGeometry-f9503c6d.js → CylinderGeometry-42740df0.js} +1 -1
  9. package/Build/Workers/{EllipseGeometry-fedf72d5.js → EllipseGeometry-49a3ac21.js} +1 -1
  10. package/Build/Workers/{EllipseGeometryLibrary-4ea68687.js → EllipseGeometryLibrary-b891b2f8.js} +1 -1
  11. package/Build/Workers/{EllipseOutlineGeometry-e2ae6a35.js → EllipseOutlineGeometry-fbd72e07.js} +1 -1
  12. package/Build/Workers/{EllipsoidGeodesic-16de63ea.js → EllipsoidGeodesic-98c62a56.js} +1 -1
  13. package/Build/Workers/{EllipsoidGeometry-95c0330e.js → EllipsoidGeometry-a351dba8.js} +1 -1
  14. package/Build/Workers/{EllipsoidOutlineGeometry-d6d2ceec.js → EllipsoidOutlineGeometry-3e8779bf.js} +1 -1
  15. package/Build/Workers/{EllipsoidRhumbLine-ae5e65e0.js → EllipsoidRhumbLine-19756602.js} +1 -1
  16. package/Build/Workers/{EllipsoidTangentPlane-bfc674bf.js → EllipsoidTangentPlane-cfb50678.js} +1 -1
  17. package/Build/Workers/{EncodedCartesian3-f473ea18.js → EncodedCartesian3-81f70735.js} +1 -1
  18. package/Build/Workers/{FrustumGeometry-3bf2e4eb.js → FrustumGeometry-c5754412.js} +1 -1
  19. package/Build/Workers/{GeometryAttribute-df5f473e.js → GeometryAttribute-0bfd05e8.js} +1 -1
  20. package/Build/Workers/{GeometryInstance-aa75b4cf.js → GeometryInstance-451dc1cd.js} +1 -1
  21. package/Build/Workers/{GeometryPipeline-f0e46c42.js → GeometryPipeline-0166905d.js} +1 -1
  22. package/Build/Workers/{IntersectionTests-9de29d51.js → IntersectionTests-a93d3de9.js} +1 -1
  23. package/Build/Workers/{Matrix2-ce637455.js → Matrix2-13178034.js} +4 -2
  24. package/Build/Workers/{Matrix3-4f4df527.js → Matrix3-315394f6.js} +2 -1
  25. package/Build/Workers/{OrientedBoundingBox-d3ff3d4d.js → OrientedBoundingBox-b450cb61.js} +5 -5
  26. package/Build/Workers/{Plane-b81241c2.js → Plane-900aa728.js} +1 -1
  27. package/Build/Workers/{PolygonGeometryLibrary-6f4937bb.js → PolygonGeometryLibrary-f918ac26.js} +1 -1
  28. package/Build/Workers/PolygonPipeline-f59a8f0a.js +1345 -0
  29. package/Build/Workers/{PolylinePipeline-2e2b015c.js → PolylinePipeline-d8e6bd9b.js} +1 -1
  30. package/Build/Workers/{PolylineVolumeGeometryLibrary-7ee1d449.js → PolylineVolumeGeometryLibrary-125d2edf.js} +1 -1
  31. package/Build/Workers/{PrimitivePipeline-a9b7aae0.js → PrimitivePipeline-0d7b5ed4.js} +1 -1
  32. package/Build/Workers/{RectangleGeometryLibrary-9aa6c8f6.js → RectangleGeometryLibrary-0768db63.js} +1 -1
  33. package/Build/Workers/{TerrainEncoding-b52dcfc5.js → TerrainEncoding-06470d7f.js} +1 -1
  34. package/Build/Workers/{Transforms-2f755df8.js → Transforms-26539bce.js} +97 -83
  35. package/Build/Workers/{WallGeometryLibrary-ab19a93d.js → WallGeometryLibrary-6167b0fc.js} +1 -1
  36. package/Build/Workers/{WebMercatorProjection-9f25de49.js → WebMercatorProjection-13a90d41.js} +1 -1
  37. package/Build/Workers/cesiumWorkerBootstrapper.js +25 -1
  38. package/Build/Workers/combineGeometry.js +1 -1
  39. package/Build/Workers/createBoxGeometry.js +1 -1
  40. package/Build/Workers/createBoxOutlineGeometry.js +1 -1
  41. package/Build/Workers/createCircleGeometry.js +1 -1
  42. package/Build/Workers/createCircleOutlineGeometry.js +1 -1
  43. package/Build/Workers/createCoplanarPolygonGeometry.js +1 -1
  44. package/Build/Workers/createCoplanarPolygonOutlineGeometry.js +1 -1
  45. package/Build/Workers/createCorridorGeometry.js +1 -1
  46. package/Build/Workers/createCorridorOutlineGeometry.js +1 -1
  47. package/Build/Workers/createCylinderGeometry.js +1 -1
  48. package/Build/Workers/createCylinderOutlineGeometry.js +1 -1
  49. package/Build/Workers/createEllipseGeometry.js +1 -1
  50. package/Build/Workers/createEllipseOutlineGeometry.js +1 -1
  51. package/Build/Workers/createEllipsoidGeometry.js +1 -1
  52. package/Build/Workers/createEllipsoidOutlineGeometry.js +1 -1
  53. package/Build/Workers/createFrustumGeometry.js +1 -1
  54. package/Build/Workers/createFrustumOutlineGeometry.js +1 -1
  55. package/Build/Workers/createGeometry.js +1 -1
  56. package/Build/Workers/createGroundPolylineGeometry.js +1 -1
  57. package/Build/Workers/createPlaneGeometry.js +1 -1
  58. package/Build/Workers/createPlaneOutlineGeometry.js +1 -1
  59. package/Build/Workers/createPolygonGeometry.js +1 -1
  60. package/Build/Workers/createPolygonOutlineGeometry.js +1 -1
  61. package/Build/Workers/createPolylineGeometry.js +1 -1
  62. package/Build/Workers/createPolylineVolumeGeometry.js +1 -1
  63. package/Build/Workers/createPolylineVolumeOutlineGeometry.js +1 -1
  64. package/Build/Workers/createRectangleGeometry.js +1 -1
  65. package/Build/Workers/createRectangleOutlineGeometry.js +1 -1
  66. package/Build/Workers/createSimplePolylineGeometry.js +1 -1
  67. package/Build/Workers/createSphereGeometry.js +1 -1
  68. package/Build/Workers/createSphereOutlineGeometry.js +1 -1
  69. package/Build/Workers/createVectorTileClampedPolylines.js +1 -1
  70. package/Build/Workers/createVectorTileGeometries.js +1 -1
  71. package/Build/Workers/createVectorTilePoints.js +1 -1
  72. package/Build/Workers/createVectorTilePolygons.js +1 -1
  73. package/Build/Workers/createVectorTilePolylines.js +1 -1
  74. package/Build/Workers/createVerticesFromGoogleEarthEnterpriseBuffer.js +1 -1
  75. package/Build/Workers/createVerticesFromHeightmap.js +7 -3
  76. package/Build/Workers/createVerticesFromQuantizedTerrainMesh.js +1 -1
  77. package/Build/Workers/createWallGeometry.js +1 -1
  78. package/Build/Workers/createWallOutlineGeometry.js +1 -1
  79. package/Build/Workers/decodeGoogleEarthEnterprisePacket.js +95 -76
  80. package/Build/Workers/decodeI3S.js +1 -1
  81. package/Build/Workers/package.js +25 -1
  82. package/Build/Workers/transferTypedArrayTest.js +25 -1
  83. package/Build/Workers/upsampleQuantizedTerrainMesh.js +1 -1
  84. package/README.md +9 -9
  85. package/Source/Core/EarthOrientationParameters.js +67 -63
  86. package/Source/Core/Ion.js +1 -1
  87. package/Source/Core/Matrix2.js +2 -1
  88. package/Source/Core/Matrix3.js +2 -1
  89. package/Source/Core/Matrix4.js +1 -0
  90. package/Source/Core/OrientedBoundingBox.js +4 -4
  91. package/Source/Core/S2Cell.js +3 -3
  92. package/Source/Core/Transforms.js +3 -7
  93. package/Source/DataSources/GpxDataSource.js +4 -6
  94. package/Source/DataSources/KmlDataSource.js +3 -5
  95. package/Source/Renderer/Context.js +230 -177
  96. package/Source/Renderer/Pass.js +3 -2
  97. package/Source/Scene/Cesium3DTileContentType.js +19 -0
  98. package/Source/Scene/Cesium3DTilesVoxelProvider.js +482 -0
  99. package/Source/Scene/Cesium3DTilesetMetadata.js +2 -2
  100. package/Source/Scene/ContentMetadata.js +2 -2
  101. package/Source/Scene/DerivedCommand.js +7 -0
  102. package/Source/Scene/Expression.js +1 -1
  103. package/Source/Scene/Globe.js +10 -0
  104. package/Source/Scene/GlobeSurfaceTileProvider.js +7 -0
  105. package/Source/Scene/GltfImageLoader.js +1 -1
  106. package/Source/Scene/GltfVertexBufferLoader.js +10 -2
  107. package/Source/Scene/GroupMetadata.js +2 -2
  108. package/Source/Scene/I3SDataProvider.js +2 -1
  109. package/Source/Scene/I3SFeature.js +1 -1
  110. package/Source/Scene/I3SLayer.js +64 -2
  111. package/Source/Scene/I3SNode.js +50 -6
  112. package/Source/Scene/ImplicitMetadataView.js +2 -2
  113. package/Source/Scene/ImplicitSubtreeCache.js +127 -0
  114. package/Source/Scene/ImplicitSubtreeMetadata.js +2 -2
  115. package/Source/Scene/ImplicitTileset.js +3 -2
  116. package/Source/Scene/KeyframeNode.js +47 -0
  117. package/Source/Scene/Megatexture.js +490 -0
  118. package/Source/Scene/MetadataClass.js +60 -25
  119. package/Source/Scene/MetadataClassProperty.js +132 -68
  120. package/Source/Scene/MetadataComponentType.js +78 -57
  121. package/Source/Scene/MetadataEnum.js +59 -23
  122. package/Source/Scene/MetadataEnumValue.js +49 -15
  123. package/Source/Scene/MetadataSchema.js +53 -24
  124. package/Source/Scene/MetadataSchemaLoader.js +2 -2
  125. package/Source/Scene/MetadataTableProperty.js +2 -2
  126. package/Source/Scene/MetadataType.js +6 -14
  127. package/Source/Scene/Model/GeoJsonLoader.js +1 -1
  128. package/Source/Scene/Model/Model.js +38 -6
  129. package/Source/Scene/Model/buildDrawCommand.js +19 -11
  130. package/Source/Scene/PointCloud.js +1 -1
  131. package/Source/Scene/PropertyAttribute.js +2 -2
  132. package/Source/Scene/PropertyAttributeProperty.js +2 -2
  133. package/Source/Scene/PropertyTable.js +2 -2
  134. package/Source/Scene/PropertyTexture.js +2 -2
  135. package/Source/Scene/PropertyTextureProperty.js +2 -2
  136. package/Source/Scene/ResourceCache.js +9 -1
  137. package/Source/Scene/ResourceCacheKey.js +9 -1
  138. package/Source/Scene/Scene.js +20 -50
  139. package/Source/Scene/SpatialNode.js +375 -0
  140. package/Source/Scene/StructuralMetadata.js +2 -2
  141. package/Source/Scene/TileMetadata.js +2 -2
  142. package/Source/Scene/TilesetMetadata.js +2 -2
  143. package/Source/Scene/VoxelBoxShape.js +527 -0
  144. package/Source/Scene/VoxelContent.js +169 -0
  145. package/Source/Scene/VoxelCylinderShape.js +937 -0
  146. package/Source/Scene/VoxelEllipsoidShape.js +937 -0
  147. package/Source/Scene/VoxelPrimitive.js +1919 -0
  148. package/Source/Scene/VoxelProvider.js +255 -0
  149. package/Source/Scene/VoxelRenderResources.js +224 -0
  150. package/Source/Scene/VoxelShape.js +152 -0
  151. package/Source/Scene/VoxelShapeType.js +105 -0
  152. package/Source/Scene/VoxelTraversal.js +1144 -0
  153. package/Source/Scene/buildVoxelDrawCommands.js +116 -0
  154. package/Source/Scene/parseBatchTable.js +18 -2
  155. package/Source/Scene/preprocess3DTileContent.js +8 -0
  156. package/Source/Scene/processVoxelProperties.js +455 -0
  157. package/Source/Shaders/BillboardCollectionVS.glsl +1 -1
  158. package/Source/Shaders/BillboardCollectionVS.js +1 -1
  159. package/Source/Shaders/Builtin/Constants/passOverlay.glsl +1 -1
  160. package/Source/Shaders/Builtin/Constants/passOverlay.js +1 -1
  161. package/Source/Shaders/Builtin/Constants/passVoxels.glsl +9 -0
  162. package/Source/Shaders/Builtin/Constants/passVoxels.js +11 -0
  163. package/Source/Shaders/Builtin/CzmBuiltins.js +2 -0
  164. package/Source/Shaders/Builtin/Functions/windowToEyeCoordinates.glsl +55 -43
  165. package/Source/Shaders/Builtin/Functions/windowToEyeCoordinates.js +55 -43
  166. package/Source/Shaders/GlobeFS.glsl +2 -1
  167. package/Source/Shaders/GlobeFS.js +2 -1
  168. package/Source/Shaders/PointPrimitiveCollectionVS.glsl +5 -2
  169. package/Source/Shaders/PointPrimitiveCollectionVS.js +5 -2
  170. package/Source/Shaders/Voxels/IntersectBox.glsl +79 -0
  171. package/Source/Shaders/Voxels/IntersectBox.js +81 -0
  172. package/Source/Shaders/Voxels/IntersectClippingPlanes.glsl +70 -0
  173. package/Source/Shaders/Voxels/IntersectClippingPlanes.js +72 -0
  174. package/Source/Shaders/Voxels/IntersectCylinder.glsl +273 -0
  175. package/Source/Shaders/Voxels/IntersectCylinder.js +275 -0
  176. package/Source/Shaders/Voxels/IntersectDepth.glsl +23 -0
  177. package/Source/Shaders/Voxels/IntersectDepth.js +25 -0
  178. package/Source/Shaders/Voxels/IntersectEllipsoid.glsl +337 -0
  179. package/Source/Shaders/Voxels/IntersectEllipsoid.js +339 -0
  180. package/Source/Shaders/Voxels/Intersection.glsl +54 -0
  181. package/Source/Shaders/Voxels/Intersection.js +56 -0
  182. package/Source/Shaders/Voxels/IntersectionUtils.glsl +151 -0
  183. package/Source/Shaders/Voxels/IntersectionUtils.js +153 -0
  184. package/Source/Shaders/Voxels/Megatexture.glsl +136 -0
  185. package/Source/Shaders/Voxels/Megatexture.js +138 -0
  186. package/Source/Shaders/Voxels/Octree.glsl +221 -0
  187. package/Source/Shaders/Voxels/Octree.js +223 -0
  188. package/Source/Shaders/Voxels/VoxelFS.glsl +150 -0
  189. package/Source/Shaders/Voxels/VoxelFS.js +152 -0
  190. package/Source/Shaders/Voxels/VoxelVS.glsl +11 -0
  191. package/Source/Shaders/Voxels/VoxelVS.js +13 -0
  192. package/Source/Shaders/Voxels/convertUvToBox.glsl +16 -0
  193. package/Source/Shaders/Voxels/convertUvToBox.js +18 -0
  194. package/Source/Shaders/Voxels/convertUvToCylinder.glsl +79 -0
  195. package/Source/Shaders/Voxels/convertUvToCylinder.js +81 -0
  196. package/Source/Shaders/Voxels/convertUvToEllipsoid.glsl +133 -0
  197. package/Source/Shaders/Voxels/convertUvToEllipsoid.js +135 -0
  198. package/Source/ThirdParty/Workers/draco_decoder_nodejs.js +100 -101
  199. package/Source/ThirdParty/Workers/pako_deflate.min.js +2 -2
  200. package/Source/ThirdParty/Workers/pako_inflate.min.js +2 -2
  201. package/Source/ThirdParty/draco_decoder.wasm +0 -0
  202. package/Source/Widget/CesiumWidget.js +1 -1
  203. package/index.d.ts +961 -56
  204. package/index.js +92 -60
  205. package/package.json +6 -4
  206. package/Build/ThirdParty/Workers/basis_transcoder.js +0 -2233
  207. package/Build/ThirdParty/Workers/draco_decoder_nodejs.js +0 -1872
  208. package/Build/ThirdParty/Workers/package.json +0 -1
  209. package/Build/ThirdParty/Workers/pako_deflate.min.js +0 -589
  210. package/Build/ThirdParty/Workers/pako_inflate.min.js +0 -798
  211. package/Build/ThirdParty/Workers/z-worker-pako.js +0 -503
  212. package/Build/ThirdParty/basis_transcoder.wasm +0 -0
  213. package/Build/ThirdParty/draco_decoder.wasm +0 -0
  214. package/Build/ThirdParty/google-earth-dbroot-parser.js +0 -8019
  215. package/Build/Widget/CesiumWidget.css +0 -120
  216. package/Build/Widget/lighter.css +0 -13
  217. package/Build/Workers/PolygonPipeline-774a8aaf.js +0 -1341
@@ -22,6 +22,7 @@ import czm_passOpaque from './Constants/passOpaque.js'
22
22
  import czm_passOverlay from './Constants/passOverlay.js'
23
23
  import czm_passTerrainClassification from './Constants/passTerrainClassification.js'
24
24
  import czm_passTranslucent from './Constants/passTranslucent.js'
25
+ import czm_passVoxels from './Constants/passVoxels.js'
25
26
  import czm_pi from './Constants/pi.js'
26
27
  import czm_piOverFour from './Constants/piOverFour.js'
27
28
  import czm_piOverSix from './Constants/piOverSix.js'
@@ -153,6 +154,7 @@ export default {
153
154
  czm_passOverlay : czm_passOverlay,
154
155
  czm_passTerrainClassification : czm_passTerrainClassification,
155
156
  czm_passTranslucent : czm_passTranslucent,
157
+ czm_passVoxels : czm_passVoxels,
156
158
  czm_pi : czm_pi,
157
159
  czm_piOverFour : czm_piOverFour,
158
160
  czm_piOverSix : czm_piOverSix,
@@ -1,38 +1,13 @@
1
- /**
2
- * Transforms a position from window to eye coordinates.
3
- * The transform from window to normalized device coordinates is done using components
4
- * of (@link czm_viewport} and {@link czm_viewportTransformation} instead of calculating
5
- * the inverse of <code>czm_viewportTransformation</code>. The transformation from
6
- * normalized device coordinates to clip coordinates is done using <code>fragmentCoordinate.w</code>,
7
- * which is expected to be the scalar used in the perspective divide. The transformation
8
- * from clip to eye coordinates is done using {@link czm_inverseProjection}.
9
- *
10
- * @name czm_windowToEyeCoordinates
11
- * @glslFunction
12
- *
13
- * @param {vec4} fragmentCoordinate The position in window coordinates to transform.
14
- *
15
- * @returns {vec4} The transformed position in eye coordinates.
16
- *
17
- * @see czm_modelToWindowCoordinates
18
- * @see czm_eyeToWindowCoordinates
19
- * @see czm_inverseProjection
20
- * @see czm_viewport
21
- * @see czm_viewportTransformation
22
- *
23
- * @example
24
- * vec4 positionEC = czm_windowToEyeCoordinates(gl_FragCoord);
25
- */
26
- vec4 czm_windowToEyeCoordinates(vec4 fragmentCoordinate)
1
+ vec4 czm_screenToEyeCoordinates(vec4 screenCoordinate)
27
2
  {
28
3
  // Reconstruct NDC coordinates
29
- float x = 2.0 * (fragmentCoordinate.x - czm_viewport.x) / czm_viewport.z - 1.0;
30
- float y = 2.0 * (fragmentCoordinate.y - czm_viewport.y) / czm_viewport.w - 1.0;
31
- float z = (fragmentCoordinate.z - czm_viewportTransformation[3][2]) / czm_viewportTransformation[2][2];
4
+ float x = 2.0 * screenCoordinate.x - 1.0;
5
+ float y = 2.0 * screenCoordinate.y - 1.0;
6
+ float z = (screenCoordinate.z - czm_viewportTransformation[3][2]) / czm_viewportTransformation[2][2];
32
7
  vec4 q = vec4(x, y, z, 1.0);
33
8
 
34
9
  // Reverse the perspective division to obtain clip coordinates.
35
- q /= fragmentCoordinate.w;
10
+ q /= screenCoordinate.w;
36
11
 
37
12
  // Reverse the projection transformation to obtain eye coordinates.
38
13
  if (!(czm_inverseProjection == mat4(0.0))) // IE and Edge sometimes do something weird with != between mat4s
@@ -59,16 +34,20 @@ vec4 czm_windowToEyeCoordinates(vec4 fragmentCoordinate)
59
34
  }
60
35
 
61
36
  /**
62
- * Transforms a position given as window x/y and a depth or a log depth from window to eye coordinates.
63
- * This function produces more accurate results for window positions with log depth than
64
- * conventionally unpacking the log depth using czm_reverseLogDepth and using the standard version
65
- * of czm_windowToEyeCoordinates.
37
+ * Transforms a position from window to eye coordinates.
38
+ * The transform from window to normalized device coordinates is done using components
39
+ * of (@link czm_viewport} and {@link czm_viewportTransformation} instead of calculating
40
+ * the inverse of <code>czm_viewportTransformation</code>. The transformation from
41
+ * normalized device coordinates to clip coordinates is done using <code>fragmentCoordinate.w</code>,
42
+ * which is expected to be the scalar used in the perspective divide. The transformation
43
+ * from clip to eye coordinates is done using {@link czm_inverseProjection}.
66
44
  *
67
45
  * @name czm_windowToEyeCoordinates
68
46
  * @glslFunction
69
47
  *
70
- * @param {vec2} fragmentCoordinateXY The XY position in window coordinates to transform.
71
- * @param {float} depthOrLogDepth A depth or log depth for the fragment.
48
+ * @param {vec4} fragmentCoordinate The position in window coordinates to transform.
49
+ *
50
+ * @returns {vec4} The transformed position in eye coordinates.
72
51
  *
73
52
  * @see czm_modelToWindowCoordinates
74
53
  * @see czm_eyeToWindowCoordinates
@@ -76,24 +55,57 @@ vec4 czm_windowToEyeCoordinates(vec4 fragmentCoordinate)
76
55
  * @see czm_viewport
77
56
  * @see czm_viewportTransformation
78
57
  *
79
- * @returns {vec4} The transformed position in eye coordinates.
58
+ * @example
59
+ * vec4 positionEC = czm_windowToEyeCoordinates(gl_FragCoord);
80
60
  */
81
- vec4 czm_windowToEyeCoordinates(vec2 fragmentCoordinateXY, float depthOrLogDepth)
61
+ vec4 czm_windowToEyeCoordinates(vec4 fragmentCoordinate)
62
+ {
63
+ vec2 screenCoordXY = (fragmentCoordinate.xy - czm_viewport.xy) / czm_viewport.zw;
64
+ return czm_screenToEyeCoordinates(vec4(screenCoordXY, fragmentCoordinate.zw));
65
+ }
66
+
67
+ vec4 czm_screenToEyeCoordinates(vec2 screenCoordinateXY, float depthOrLogDepth)
82
68
  {
83
69
  // See reverseLogDepth.glsl. This is separate to re-use the pow.
84
- #ifdef LOG_DEPTH
70
+ #if defined(LOG_DEPTH) || defined(LOG_DEPTH_READ_ONLY)
85
71
  float near = czm_currentFrustum.x;
86
72
  float far = czm_currentFrustum.y;
87
73
  float log2Depth = depthOrLogDepth * czm_log2FarDepthFromNearPlusOne;
88
74
  float depthFromNear = pow(2.0, log2Depth) - 1.0;
89
75
  float depthFromCamera = depthFromNear + near;
90
- vec4 windowCoord = vec4(fragmentCoordinateXY, far * (1.0 - near / depthFromCamera) / (far - near), 1.0);
91
- vec4 eyeCoordinate = czm_windowToEyeCoordinates(windowCoord);
76
+ vec4 screenCoord = vec4(screenCoordinateXY, far * (1.0 - near / depthFromCamera) / (far - near), 1.0);
77
+ vec4 eyeCoordinate = czm_screenToEyeCoordinates(screenCoord);
92
78
  eyeCoordinate.w = 1.0 / depthFromCamera; // Better precision
93
79
  return eyeCoordinate;
94
80
  #else
95
- vec4 windowCoord = vec4(fragmentCoordinateXY, depthOrLogDepth, 1.0);
96
- vec4 eyeCoordinate = czm_windowToEyeCoordinates(windowCoord);
81
+ vec4 screenCoord = vec4(screenCoordinateXY, depthOrLogDepth, 1.0);
82
+ vec4 eyeCoordinate = czm_screenToEyeCoordinates(screenCoord);
97
83
  #endif
98
84
  return eyeCoordinate;
99
85
  }
86
+
87
+ /**
88
+ * Transforms a position given as window x/y and a depth or a log depth from window to eye coordinates.
89
+ * This function produces more accurate results for window positions with log depth than
90
+ * conventionally unpacking the log depth using czm_reverseLogDepth and using the standard version
91
+ * of czm_windowToEyeCoordinates.
92
+ *
93
+ * @name czm_windowToEyeCoordinates
94
+ * @glslFunction
95
+ *
96
+ * @param {vec2} fragmentCoordinateXY The XY position in window coordinates to transform.
97
+ * @param {float} depthOrLogDepth A depth or log depth for the fragment.
98
+ *
99
+ * @see czm_modelToWindowCoordinates
100
+ * @see czm_eyeToWindowCoordinates
101
+ * @see czm_inverseProjection
102
+ * @see czm_viewport
103
+ * @see czm_viewportTransformation
104
+ *
105
+ * @returns {vec4} The transformed position in eye coordinates.
106
+ */
107
+ vec4 czm_windowToEyeCoordinates(vec2 fragmentCoordinateXY, float depthOrLogDepth)
108
+ {
109
+ vec2 screenCoordXY = (fragmentCoordinateXY.xy - czm_viewport.xy) / czm_viewport.zw;
110
+ return czm_screenToEyeCoordinates(screenCoordXY, depthOrLogDepth);
111
+ }
@@ -1,39 +1,14 @@
1
1
  //This file is automatically rebuilt by the Cesium build process.
2
- export default "/**\n\
3
- * Transforms a position from window to eye coordinates.\n\
4
- * The transform from window to normalized device coordinates is done using components\n\
5
- * of (@link czm_viewport} and {@link czm_viewportTransformation} instead of calculating\n\
6
- * the inverse of <code>czm_viewportTransformation</code>. The transformation from\n\
7
- * normalized device coordinates to clip coordinates is done using <code>fragmentCoordinate.w</code>,\n\
8
- * which is expected to be the scalar used in the perspective divide. The transformation\n\
9
- * from clip to eye coordinates is done using {@link czm_inverseProjection}.\n\
10
- *\n\
11
- * @name czm_windowToEyeCoordinates\n\
12
- * @glslFunction\n\
13
- *\n\
14
- * @param {vec4} fragmentCoordinate The position in window coordinates to transform.\n\
15
- *\n\
16
- * @returns {vec4} The transformed position in eye coordinates.\n\
17
- *\n\
18
- * @see czm_modelToWindowCoordinates\n\
19
- * @see czm_eyeToWindowCoordinates\n\
20
- * @see czm_inverseProjection\n\
21
- * @see czm_viewport\n\
22
- * @see czm_viewportTransformation\n\
23
- *\n\
24
- * @example\n\
25
- * vec4 positionEC = czm_windowToEyeCoordinates(gl_FragCoord);\n\
26
- */\n\
27
- vec4 czm_windowToEyeCoordinates(vec4 fragmentCoordinate)\n\
2
+ export default "vec4 czm_screenToEyeCoordinates(vec4 screenCoordinate)\n\
28
3
  {\n\
29
4
  // Reconstruct NDC coordinates\n\
30
- float x = 2.0 * (fragmentCoordinate.x - czm_viewport.x) / czm_viewport.z - 1.0;\n\
31
- float y = 2.0 * (fragmentCoordinate.y - czm_viewport.y) / czm_viewport.w - 1.0;\n\
32
- float z = (fragmentCoordinate.z - czm_viewportTransformation[3][2]) / czm_viewportTransformation[2][2];\n\
5
+ float x = 2.0 * screenCoordinate.x - 1.0;\n\
6
+ float y = 2.0 * screenCoordinate.y - 1.0;\n\
7
+ float z = (screenCoordinate.z - czm_viewportTransformation[3][2]) / czm_viewportTransformation[2][2];\n\
33
8
  vec4 q = vec4(x, y, z, 1.0);\n\
34
9
  \n\
35
10
  // Reverse the perspective division to obtain clip coordinates.\n\
36
- q /= fragmentCoordinate.w;\n\
11
+ q /= screenCoordinate.w;\n\
37
12
  \n\
38
13
  // Reverse the projection transformation to obtain eye coordinates.\n\
39
14
  if (!(czm_inverseProjection == mat4(0.0))) // IE and Edge sometimes do something weird with != between mat4s\n\
@@ -60,16 +35,20 @@ vec4 czm_windowToEyeCoordinates(vec4 fragmentCoordinate)\n\
60
35
  }\n\
61
36
  \n\
62
37
  /**\n\
63
- * Transforms a position given as window x/y and a depth or a log depth from window to eye coordinates.\n\
64
- * This function produces more accurate results for window positions with log depth than\n\
65
- * conventionally unpacking the log depth using czm_reverseLogDepth and using the standard version\n\
66
- * of czm_windowToEyeCoordinates.\n\
38
+ * Transforms a position from window to eye coordinates.\n\
39
+ * The transform from window to normalized device coordinates is done using components\n\
40
+ * of (@link czm_viewport} and {@link czm_viewportTransformation} instead of calculating\n\
41
+ * the inverse of <code>czm_viewportTransformation</code>. The transformation from\n\
42
+ * normalized device coordinates to clip coordinates is done using <code>fragmentCoordinate.w</code>,\n\
43
+ * which is expected to be the scalar used in the perspective divide. The transformation\n\
44
+ * from clip to eye coordinates is done using {@link czm_inverseProjection}.\n\
67
45
  *\n\
68
46
  * @name czm_windowToEyeCoordinates\n\
69
47
  * @glslFunction\n\
70
48
  *\n\
71
- * @param {vec2} fragmentCoordinateXY The XY position in window coordinates to transform.\n\
72
- * @param {float} depthOrLogDepth A depth or log depth for the fragment.\n\
49
+ * @param {vec4} fragmentCoordinate The position in window coordinates to transform.\n\
50
+ *\n\
51
+ * @returns {vec4} The transformed position in eye coordinates.\n\
73
52
  *\n\
74
53
  * @see czm_modelToWindowCoordinates\n\
75
54
  * @see czm_eyeToWindowCoordinates\n\
@@ -77,25 +56,58 @@ vec4 czm_windowToEyeCoordinates(vec4 fragmentCoordinate)\n\
77
56
  * @see czm_viewport\n\
78
57
  * @see czm_viewportTransformation\n\
79
58
  *\n\
80
- * @returns {vec4} The transformed position in eye coordinates.\n\
59
+ * @example\n\
60
+ * vec4 positionEC = czm_windowToEyeCoordinates(gl_FragCoord);\n\
81
61
  */\n\
82
- vec4 czm_windowToEyeCoordinates(vec2 fragmentCoordinateXY, float depthOrLogDepth)\n\
62
+ vec4 czm_windowToEyeCoordinates(vec4 fragmentCoordinate)\n\
63
+ {\n\
64
+ vec2 screenCoordXY = (fragmentCoordinate.xy - czm_viewport.xy) / czm_viewport.zw;\n\
65
+ return czm_screenToEyeCoordinates(vec4(screenCoordXY, fragmentCoordinate.zw));\n\
66
+ }\n\
67
+ \n\
68
+ vec4 czm_screenToEyeCoordinates(vec2 screenCoordinateXY, float depthOrLogDepth)\n\
83
69
  {\n\
84
70
  // See reverseLogDepth.glsl. This is separate to re-use the pow.\n\
85
- #ifdef LOG_DEPTH\n\
71
+ #if defined(LOG_DEPTH) || defined(LOG_DEPTH_READ_ONLY)\n\
86
72
  float near = czm_currentFrustum.x;\n\
87
73
  float far = czm_currentFrustum.y;\n\
88
74
  float log2Depth = depthOrLogDepth * czm_log2FarDepthFromNearPlusOne;\n\
89
75
  float depthFromNear = pow(2.0, log2Depth) - 1.0;\n\
90
76
  float depthFromCamera = depthFromNear + near;\n\
91
- vec4 windowCoord = vec4(fragmentCoordinateXY, far * (1.0 - near / depthFromCamera) / (far - near), 1.0);\n\
92
- vec4 eyeCoordinate = czm_windowToEyeCoordinates(windowCoord);\n\
77
+ vec4 screenCoord = vec4(screenCoordinateXY, far * (1.0 - near / depthFromCamera) / (far - near), 1.0);\n\
78
+ vec4 eyeCoordinate = czm_screenToEyeCoordinates(screenCoord);\n\
93
79
  eyeCoordinate.w = 1.0 / depthFromCamera; // Better precision\n\
94
80
  return eyeCoordinate;\n\
95
81
  #else\n\
96
- vec4 windowCoord = vec4(fragmentCoordinateXY, depthOrLogDepth, 1.0);\n\
97
- vec4 eyeCoordinate = czm_windowToEyeCoordinates(windowCoord);\n\
82
+ vec4 screenCoord = vec4(screenCoordinateXY, depthOrLogDepth, 1.0);\n\
83
+ vec4 eyeCoordinate = czm_screenToEyeCoordinates(screenCoord);\n\
98
84
  #endif\n\
99
85
  return eyeCoordinate;\n\
100
86
  }\n\
87
+ \n\
88
+ /**\n\
89
+ * Transforms a position given as window x/y and a depth or a log depth from window to eye coordinates.\n\
90
+ * This function produces more accurate results for window positions with log depth than\n\
91
+ * conventionally unpacking the log depth using czm_reverseLogDepth and using the standard version\n\
92
+ * of czm_windowToEyeCoordinates.\n\
93
+ *\n\
94
+ * @name czm_windowToEyeCoordinates\n\
95
+ * @glslFunction\n\
96
+ *\n\
97
+ * @param {vec2} fragmentCoordinateXY The XY position in window coordinates to transform.\n\
98
+ * @param {float} depthOrLogDepth A depth or log depth for the fragment.\n\
99
+ *\n\
100
+ * @see czm_modelToWindowCoordinates\n\
101
+ * @see czm_eyeToWindowCoordinates\n\
102
+ * @see czm_inverseProjection\n\
103
+ * @see czm_viewport\n\
104
+ * @see czm_viewportTransformation\n\
105
+ *\n\
106
+ * @returns {vec4} The transformed position in eye coordinates.\n\
107
+ */\n\
108
+ vec4 czm_windowToEyeCoordinates(vec2 fragmentCoordinateXY, float depthOrLogDepth)\n\
109
+ {\n\
110
+ vec2 screenCoordXY = (fragmentCoordinateXY.xy - czm_viewport.xy) / czm_viewport.zw;\n\
111
+ return czm_screenToEyeCoordinates(screenCoordXY, depthOrLogDepth);\n\
112
+ }\n\
101
113
  ";
@@ -102,6 +102,7 @@ uniform vec4 u_undergroundColorAlphaByDistance;
102
102
 
103
103
  #ifdef ENABLE_VERTEX_LIGHTING
104
104
  uniform float u_lambertDiffuseMultiplier;
105
+ uniform float u_vertexShadowDarkness;
105
106
  #endif
106
107
 
107
108
  varying vec3 v_positionMC;
@@ -405,7 +406,7 @@ void main()
405
406
  #endif
406
407
 
407
408
  #ifdef ENABLE_VERTEX_LIGHTING
408
- float diffuseIntensity = clamp(czm_getLambertDiffuse(czm_lightDirectionEC, normalize(v_normalEC)) * u_lambertDiffuseMultiplier + 0.3, 0.0, 1.0);
409
+ float diffuseIntensity = clamp(czm_getLambertDiffuse(czm_lightDirectionEC, normalize(v_normalEC)) * u_lambertDiffuseMultiplier + u_vertexShadowDarkness, 0.0, 1.0);
409
410
  vec4 finalColor = vec4(color.rgb * czm_lightColor * diffuseIntensity, color.a);
410
411
  #elif defined(ENABLE_DAYNIGHT_SHADING)
411
412
  float diffuseIntensity = clamp(czm_getLambertDiffuse(czm_lightDirectionEC, normalEC) * 5.0 + 0.3, 0.0, 1.0);
@@ -103,6 +103,7 @@ uniform vec4 u_undergroundColorAlphaByDistance;\n\
103
103
  \n\
104
104
  #ifdef ENABLE_VERTEX_LIGHTING\n\
105
105
  uniform float u_lambertDiffuseMultiplier;\n\
106
+ uniform float u_vertexShadowDarkness;\n\
106
107
  #endif\n\
107
108
  \n\
108
109
  varying vec3 v_positionMC;\n\
@@ -406,7 +407,7 @@ void main()\n\
406
407
  #endif\n\
407
408
  \n\
408
409
  #ifdef ENABLE_VERTEX_LIGHTING\n\
409
- float diffuseIntensity = clamp(czm_getLambertDiffuse(czm_lightDirectionEC, normalize(v_normalEC)) * u_lambertDiffuseMultiplier + 0.3, 0.0, 1.0);\n\
410
+ float diffuseIntensity = clamp(czm_getLambertDiffuse(czm_lightDirectionEC, normalize(v_normalEC)) * u_lambertDiffuseMultiplier + u_vertexShadowDarkness, 0.0, 1.0);\n\
410
411
  vec4 finalColor = vec4(color.rgb * czm_lightColor * diffuseIntensity, color.a);\n\
411
412
  #elif defined(ENABLE_DAYNIGHT_SHADING)\n\
412
413
  float diffuseIntensity = clamp(czm_getLambertDiffuse(czm_lightDirectionEC, normalEC) * 5.0 + 0.3, 0.0, 1.0);\n\
@@ -28,8 +28,6 @@ void main()
28
28
  float outlinePercent = outlineWidthBothSides / totalSize;
29
29
  // Scale in response to browser-zoom.
30
30
  totalSize *= czm_pixelRatio;
31
- // Add padding for anti-aliasing on both sides.
32
- totalSize += 3.0;
33
31
 
34
32
  float temp = compressedAttribute1.x * SHIFT_RIGHT8;
35
33
  float show = floor(temp);
@@ -111,6 +109,11 @@ void main()
111
109
  #ifdef EYE_DISTANCE_SCALING
112
110
  totalSize *= czm_nearFarScalar(scaleByDistance, lengthSq);
113
111
  #endif
112
+ if (totalSize > 0.0) {
113
+ // Add padding for anti-aliasing on both sides.
114
+ totalSize += 3.0;
115
+ }
116
+
114
117
  // Clamp to max point size.
115
118
  totalSize = min(totalSize, u_maxTotalPointSize);
116
119
  // If size is too small, push vertex behind near plane for clipping.
@@ -29,8 +29,6 @@ void main()\n\
29
29
  float outlinePercent = outlineWidthBothSides / totalSize;\n\
30
30
  // Scale in response to browser-zoom.\n\
31
31
  totalSize *= czm_pixelRatio;\n\
32
- // Add padding for anti-aliasing on both sides.\n\
33
- totalSize += 3.0;\n\
34
32
  \n\
35
33
  float temp = compressedAttribute1.x * SHIFT_RIGHT8;\n\
36
34
  float show = floor(temp);\n\
@@ -112,6 +110,11 @@ void main()\n\
112
110
  #ifdef EYE_DISTANCE_SCALING\n\
113
111
  totalSize *= czm_nearFarScalar(scaleByDistance, lengthSq);\n\
114
112
  #endif\n\
113
+ if (totalSize > 0.0) {\n\
114
+ // Add padding for anti-aliasing on both sides.\n\
115
+ totalSize += 3.0;\n\
116
+ }\n\
117
+ \n\
115
118
  // Clamp to max point size.\n\
116
119
  totalSize = min(totalSize, u_maxTotalPointSize);\n\
117
120
  // If size is too small, push vertex behind near plane for clipping.\n\
@@ -0,0 +1,79 @@
1
+ // See IntersectionUtils.glsl for the definitions of Ray and NO_HIT
2
+
3
+ /* Box defines (set in Scene/VoxelBoxShape.js)
4
+ #define BOX_INTERSECTION_INDEX ### // always 0
5
+ #define BOX_HAS_RENDER_BOUNDS
6
+ #define BOX_IS_2D
7
+ */
8
+
9
+ #if defined(BOX_HAS_RENDER_BOUNDS)
10
+ #if defined(BOX_IS_2D)
11
+ // This matrix bakes in an axis conversion so that the math works for XY plane.
12
+ uniform mat4 u_boxUvToRenderBoundsTransform;
13
+ #else
14
+ // Similar to u_boxTransformUvToBounds but fewer instructions needed.
15
+ uniform vec3 u_boxUvToRenderBoundsScale;
16
+ uniform vec3 u_boxUvToRenderBoundsTranslate;
17
+ #endif
18
+ #endif
19
+
20
+ vec2 intersectUnitCube(Ray ray) // Unit cube from [-1, +1]
21
+ {
22
+ vec3 o = ray.pos;
23
+ vec3 d = ray.dir;
24
+
25
+ vec3 dInv = 1.0 / d;
26
+ vec3 od = -o * dInv;
27
+ vec3 t0 = od - dInv;
28
+ vec3 t1 = od + dInv;
29
+ vec3 m0 = min(t0, t1);
30
+ vec3 m1 = max(t0, t1);
31
+ float tMin = max(max(m0.x, m0.y), m0.z);
32
+ float tMax = min(min(m1.x, m1.y), m1.z);
33
+
34
+ if (tMin >= tMax) {
35
+ return vec2(NO_HIT);
36
+ }
37
+
38
+ return vec2(tMin, tMax);
39
+ }
40
+
41
+ vec2 intersectUnitSquare(Ray ray) // Unit square from [-1, +1]
42
+ {
43
+ vec3 o = ray.pos;
44
+ vec3 d = ray.dir;
45
+
46
+ float t = -o.z / d.z;
47
+ vec2 planePos = o.xy + d.xy * t;
48
+ if (any(greaterThan(abs(planePos), vec2(1.0)))) {
49
+ return vec2(NO_HIT);
50
+ }
51
+
52
+ return vec2(t, t);
53
+ }
54
+
55
+ void intersectShape(Ray ray, inout Intersections ix)
56
+ {
57
+ #if defined(BOX_HAS_RENDER_BOUNDS)
58
+ #if defined(BOX_IS_2D)
59
+ // Transform the ray into unit square space on Z plane
60
+ // This matrix bakes in an axis conversion so that the math works for XY plane.
61
+ ray.pos = vec3(u_boxUvToRenderBoundsTransform * vec4(ray.pos, 1.0));
62
+ ray.dir = vec3(u_boxUvToRenderBoundsTransform * vec4(ray.dir, 0.0));
63
+ vec2 entryExit = intersectUnitSquare(ray);
64
+ #else
65
+ // Transform the ray into unit cube space
66
+ ray.pos = ray.pos * u_boxUvToRenderBoundsScale + u_boxUvToRenderBoundsTranslate;
67
+ ray.dir *= u_boxUvToRenderBoundsScale;
68
+ vec2 entryExit = intersectUnitCube(ray);
69
+ #endif
70
+ #else
71
+ // Position is converted from [0,1] to [-1,+1] because shape intersections assume unit space is [-1,+1].
72
+ // Direction is scaled as well to be in sync with position.
73
+ ray.pos = ray.pos * 2.0 - 1.0;
74
+ ray.dir = ray.dir * 2.0;
75
+ vec2 entryExit = intersectUnitCube(ray);
76
+ #endif
77
+
78
+ setIntersectionPair(ix, BOX_INTERSECTION_INDEX, entryExit);
79
+ }
@@ -0,0 +1,81 @@
1
+ //This file is automatically rebuilt by the Cesium build process.
2
+ export default "// See IntersectionUtils.glsl for the definitions of Ray and NO_HIT\n\
3
+ \n\
4
+ /* Box defines (set in Scene/VoxelBoxShape.js)\n\
5
+ #define BOX_INTERSECTION_INDEX ### // always 0\n\
6
+ #define BOX_HAS_RENDER_BOUNDS\n\
7
+ #define BOX_IS_2D\n\
8
+ */\n\
9
+ \n\
10
+ #if defined(BOX_HAS_RENDER_BOUNDS)\n\
11
+ #if defined(BOX_IS_2D)\n\
12
+ // This matrix bakes in an axis conversion so that the math works for XY plane.\n\
13
+ uniform mat4 u_boxUvToRenderBoundsTransform;\n\
14
+ #else\n\
15
+ // Similar to u_boxTransformUvToBounds but fewer instructions needed.\n\
16
+ uniform vec3 u_boxUvToRenderBoundsScale;\n\
17
+ uniform vec3 u_boxUvToRenderBoundsTranslate;\n\
18
+ #endif\n\
19
+ #endif\n\
20
+ \n\
21
+ vec2 intersectUnitCube(Ray ray) // Unit cube from [-1, +1]\n\
22
+ {\n\
23
+ vec3 o = ray.pos;\n\
24
+ vec3 d = ray.dir;\n\
25
+ \n\
26
+ vec3 dInv = 1.0 / d;\n\
27
+ vec3 od = -o * dInv;\n\
28
+ vec3 t0 = od - dInv;\n\
29
+ vec3 t1 = od + dInv;\n\
30
+ vec3 m0 = min(t0, t1);\n\
31
+ vec3 m1 = max(t0, t1);\n\
32
+ float tMin = max(max(m0.x, m0.y), m0.z);\n\
33
+ float tMax = min(min(m1.x, m1.y), m1.z);\n\
34
+ \n\
35
+ if (tMin >= tMax) {\n\
36
+ return vec2(NO_HIT);\n\
37
+ }\n\
38
+ \n\
39
+ return vec2(tMin, tMax);\n\
40
+ }\n\
41
+ \n\
42
+ vec2 intersectUnitSquare(Ray ray) // Unit square from [-1, +1]\n\
43
+ {\n\
44
+ vec3 o = ray.pos;\n\
45
+ vec3 d = ray.dir;\n\
46
+ \n\
47
+ float t = -o.z / d.z;\n\
48
+ vec2 planePos = o.xy + d.xy * t;\n\
49
+ if (any(greaterThan(abs(planePos), vec2(1.0)))) {\n\
50
+ return vec2(NO_HIT);\n\
51
+ }\n\
52
+ \n\
53
+ return vec2(t, t);\n\
54
+ }\n\
55
+ \n\
56
+ void intersectShape(Ray ray, inout Intersections ix)\n\
57
+ {\n\
58
+ #if defined(BOX_HAS_RENDER_BOUNDS)\n\
59
+ #if defined(BOX_IS_2D)\n\
60
+ // Transform the ray into unit square space on Z plane\n\
61
+ // This matrix bakes in an axis conversion so that the math works for XY plane.\n\
62
+ ray.pos = vec3(u_boxUvToRenderBoundsTransform * vec4(ray.pos, 1.0));\n\
63
+ ray.dir = vec3(u_boxUvToRenderBoundsTransform * vec4(ray.dir, 0.0));\n\
64
+ vec2 entryExit = intersectUnitSquare(ray);\n\
65
+ #else\n\
66
+ // Transform the ray into unit cube space\n\
67
+ ray.pos = ray.pos * u_boxUvToRenderBoundsScale + u_boxUvToRenderBoundsTranslate;\n\
68
+ ray.dir *= u_boxUvToRenderBoundsScale;\n\
69
+ vec2 entryExit = intersectUnitCube(ray);\n\
70
+ #endif\n\
71
+ #else\n\
72
+ // Position is converted from [0,1] to [-1,+1] because shape intersections assume unit space is [-1,+1].\n\
73
+ // Direction is scaled as well to be in sync with position.\n\
74
+ ray.pos = ray.pos * 2.0 - 1.0;\n\
75
+ ray.dir = ray.dir * 2.0;\n\
76
+ vec2 entryExit = intersectUnitCube(ray);\n\
77
+ #endif\n\
78
+ \n\
79
+ setIntersectionPair(ix, BOX_INTERSECTION_INDEX, entryExit);\n\
80
+ }\n\
81
+ ";
@@ -0,0 +1,70 @@
1
+ // See IntersectionUtils.glsl for the definitions of Ray, Intersections, INF_HIT,
2
+ // NO_HIT, setIntersectionPair
3
+
4
+ /* Clipping plane defines (set in Scene/VoxelRenderResources.js)
5
+ #define CLIPPING_PLANES_UNION
6
+ #define CLIPPING_PLANES_COUNT
7
+ #define CLIPPING_PLANES_INTERSECTION_INDEX
8
+ */
9
+
10
+ uniform sampler2D u_clippingPlanesTexture;
11
+ uniform mat4 u_clippingPlanesMatrix;
12
+
13
+ // Plane is in Hessian Normal Form
14
+ vec2 intersectPlane(Ray ray, vec4 plane) {
15
+ vec3 o = ray.pos;
16
+ vec3 d = ray.dir;
17
+ vec3 n = plane.xyz; // normal
18
+ float w = plane.w; // -dot(pointOnPlane, normal)
19
+
20
+ float a = dot(o, n);
21
+ float b = dot(d, n);
22
+ float t = -(w + a) / b;
23
+
24
+ if (dot(d, n) > 0.0) {
25
+ return vec2(t, +INF_HIT);
26
+ } else {
27
+ return vec2(-INF_HIT, t);
28
+ }
29
+ }
30
+
31
+ void intersectClippingPlanes(Ray ray, inout Intersections ix) {
32
+ #if (CLIPPING_PLANES_COUNT == 1)
33
+ // Union and intersection are the same when there's one clipping plane, and the code
34
+ // is more simplified.
35
+ vec4 planeUv = getClippingPlane(u_clippingPlanesTexture, 0, u_clippingPlanesMatrix);
36
+ vec2 intersection = intersectPlane(ray, planeUv);
37
+ setIntersectionPair(ix, CLIPPING_PLANES_INTERSECTION_INDEX, intersection);
38
+ #elif defined(CLIPPING_PLANES_UNION)
39
+ float minPositiveT = +INF_HIT;
40
+ float maxNegativeT = -INF_HIT;
41
+ for (int i = 0; i < CLIPPING_PLANES_COUNT; i++) {
42
+ vec4 planeUv = getClippingPlane(u_clippingPlanesTexture, i, u_clippingPlanesMatrix);
43
+ vec2 intersection = intersectPlane(ray, planeUv);
44
+ if (intersection.y == +INF_HIT) {
45
+ minPositiveT = min(minPositiveT, intersection.x);
46
+ } else {
47
+ maxNegativeT = max(maxNegativeT, intersection.y);
48
+ }
49
+ }
50
+ setIntersectionPair(ix, CLIPPING_PLANES_INTERSECTION_INDEX + 0, vec2(-INF_HIT, maxNegativeT));
51
+ setIntersectionPair(ix, CLIPPING_PLANES_INTERSECTION_INDEX + 1, vec2(minPositiveT, +INF_HIT));
52
+ #else // intersection
53
+ float maxPositiveT = -INF_HIT;
54
+ float minNegativeT = +INF_HIT;
55
+ for (int i = 0; i < CLIPPING_PLANES_COUNT; i++) {
56
+ vec4 planeUv = getClippingPlane(u_clippingPlanesTexture, i, u_clippingPlanesMatrix);
57
+ vec2 intersection = intersectPlane(ray, planeUv);
58
+ if (intersection.y == +INF_HIT) {
59
+ maxPositiveT = max(maxPositiveT, intersection.x);
60
+ } else {
61
+ minNegativeT = min(minNegativeT, intersection.y);
62
+ }
63
+ }
64
+ if (maxPositiveT < minNegativeT) {
65
+ setIntersectionPair(ix, CLIPPING_PLANES_INTERSECTION_INDEX, vec2(maxPositiveT, minNegativeT));
66
+ } else {
67
+ setIntersectionPair(ix, CLIPPING_PLANES_INTERSECTION_INDEX, vec2(NO_HIT));
68
+ }
69
+ #endif
70
+ }
@@ -0,0 +1,72 @@
1
+ //This file is automatically rebuilt by the Cesium build process.
2
+ export default "// See IntersectionUtils.glsl for the definitions of Ray, Intersections, INF_HIT,\n\
3
+ // NO_HIT, setIntersectionPair\n\
4
+ \n\
5
+ /* Clipping plane defines (set in Scene/VoxelRenderResources.js)\n\
6
+ #define CLIPPING_PLANES_UNION\n\
7
+ #define CLIPPING_PLANES_COUNT\n\
8
+ #define CLIPPING_PLANES_INTERSECTION_INDEX\n\
9
+ */\n\
10
+ \n\
11
+ uniform sampler2D u_clippingPlanesTexture;\n\
12
+ uniform mat4 u_clippingPlanesMatrix;\n\
13
+ \n\
14
+ // Plane is in Hessian Normal Form\n\
15
+ vec2 intersectPlane(Ray ray, vec4 plane) {\n\
16
+ vec3 o = ray.pos;\n\
17
+ vec3 d = ray.dir;\n\
18
+ vec3 n = plane.xyz; // normal\n\
19
+ float w = plane.w; // -dot(pointOnPlane, normal)\n\
20
+ \n\
21
+ float a = dot(o, n);\n\
22
+ float b = dot(d, n);\n\
23
+ float t = -(w + a) / b;\n\
24
+ \n\
25
+ if (dot(d, n) > 0.0) {\n\
26
+ return vec2(t, +INF_HIT);\n\
27
+ } else {\n\
28
+ return vec2(-INF_HIT, t);\n\
29
+ }\n\
30
+ }\n\
31
+ \n\
32
+ void intersectClippingPlanes(Ray ray, inout Intersections ix) {\n\
33
+ #if (CLIPPING_PLANES_COUNT == 1)\n\
34
+ // Union and intersection are the same when there's one clipping plane, and the code\n\
35
+ // is more simplified.\n\
36
+ vec4 planeUv = getClippingPlane(u_clippingPlanesTexture, 0, u_clippingPlanesMatrix);\n\
37
+ vec2 intersection = intersectPlane(ray, planeUv);\n\
38
+ setIntersectionPair(ix, CLIPPING_PLANES_INTERSECTION_INDEX, intersection);\n\
39
+ #elif defined(CLIPPING_PLANES_UNION)\n\
40
+ float minPositiveT = +INF_HIT;\n\
41
+ float maxNegativeT = -INF_HIT;\n\
42
+ for (int i = 0; i < CLIPPING_PLANES_COUNT; i++) {\n\
43
+ vec4 planeUv = getClippingPlane(u_clippingPlanesTexture, i, u_clippingPlanesMatrix);\n\
44
+ vec2 intersection = intersectPlane(ray, planeUv);\n\
45
+ if (intersection.y == +INF_HIT) {\n\
46
+ minPositiveT = min(minPositiveT, intersection.x);\n\
47
+ } else {\n\
48
+ maxNegativeT = max(maxNegativeT, intersection.y);\n\
49
+ }\n\
50
+ }\n\
51
+ setIntersectionPair(ix, CLIPPING_PLANES_INTERSECTION_INDEX + 0, vec2(-INF_HIT, maxNegativeT));\n\
52
+ setIntersectionPair(ix, CLIPPING_PLANES_INTERSECTION_INDEX + 1, vec2(minPositiveT, +INF_HIT));\n\
53
+ #else // intersection\n\
54
+ float maxPositiveT = -INF_HIT;\n\
55
+ float minNegativeT = +INF_HIT;\n\
56
+ for (int i = 0; i < CLIPPING_PLANES_COUNT; i++) {\n\
57
+ vec4 planeUv = getClippingPlane(u_clippingPlanesTexture, i, u_clippingPlanesMatrix);\n\
58
+ vec2 intersection = intersectPlane(ray, planeUv);\n\
59
+ if (intersection.y == +INF_HIT) {\n\
60
+ maxPositiveT = max(maxPositiveT, intersection.x);\n\
61
+ } else {\n\
62
+ minNegativeT = min(minNegativeT, intersection.y);\n\
63
+ }\n\
64
+ }\n\
65
+ if (maxPositiveT < minNegativeT) {\n\
66
+ setIntersectionPair(ix, CLIPPING_PLANES_INTERSECTION_INDEX, vec2(maxPositiveT, minNegativeT));\n\
67
+ } else {\n\
68
+ setIntersectionPair(ix, CLIPPING_PLANES_INTERSECTION_INDEX, vec2(NO_HIT));\n\
69
+ }\n\
70
+ #endif\n\
71
+ }\n\
72
+ ";