@cesium/engine 1.0.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 (196) 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/decodeI3S.js +1 -1
  80. package/Build/Workers/package.js +25 -1
  81. package/Build/Workers/transferTypedArrayTest.js +25 -1
  82. package/Build/Workers/upsampleQuantizedTerrainMesh.js +1 -1
  83. package/Source/Core/EarthOrientationParameters.js +67 -63
  84. package/Source/Core/Ion.js +1 -1
  85. package/Source/Core/Matrix2.js +2 -1
  86. package/Source/Core/Matrix3.js +2 -1
  87. package/Source/Core/Matrix4.js +1 -0
  88. package/Source/Core/OrientedBoundingBox.js +4 -4
  89. package/Source/Core/S2Cell.js +3 -3
  90. package/Source/Core/Transforms.js +3 -7
  91. package/Source/DataSources/GpxDataSource.js +4 -6
  92. package/Source/DataSources/KmlDataSource.js +3 -5
  93. package/Source/Renderer/Context.js +27 -9
  94. package/Source/Renderer/Pass.js +3 -2
  95. package/Source/Scene/Cesium3DTileContentType.js +19 -0
  96. package/Source/Scene/Cesium3DTilesVoxelProvider.js +482 -0
  97. package/Source/Scene/Cesium3DTilesetMetadata.js +2 -2
  98. package/Source/Scene/ContentMetadata.js +2 -2
  99. package/Source/Scene/DerivedCommand.js +7 -0
  100. package/Source/Scene/Expression.js +1 -1
  101. package/Source/Scene/Globe.js +10 -0
  102. package/Source/Scene/GlobeSurfaceTileProvider.js +7 -0
  103. package/Source/Scene/GltfImageLoader.js +1 -1
  104. package/Source/Scene/GltfVertexBufferLoader.js +10 -2
  105. package/Source/Scene/GroupMetadata.js +2 -2
  106. package/Source/Scene/ImplicitMetadataView.js +2 -2
  107. package/Source/Scene/ImplicitSubtreeCache.js +127 -0
  108. package/Source/Scene/ImplicitSubtreeMetadata.js +2 -2
  109. package/Source/Scene/ImplicitTileset.js +3 -2
  110. package/Source/Scene/KeyframeNode.js +47 -0
  111. package/Source/Scene/Megatexture.js +490 -0
  112. package/Source/Scene/MetadataClass.js +60 -25
  113. package/Source/Scene/MetadataClassProperty.js +132 -68
  114. package/Source/Scene/MetadataComponentType.js +78 -57
  115. package/Source/Scene/MetadataEnum.js +59 -23
  116. package/Source/Scene/MetadataEnumValue.js +49 -15
  117. package/Source/Scene/MetadataSchema.js +53 -24
  118. package/Source/Scene/MetadataSchemaLoader.js +2 -2
  119. package/Source/Scene/MetadataTableProperty.js +2 -2
  120. package/Source/Scene/MetadataType.js +6 -14
  121. package/Source/Scene/Model/GeoJsonLoader.js +1 -1
  122. package/Source/Scene/Model/Model.js +2 -3
  123. package/Source/Scene/Model/buildDrawCommand.js +19 -11
  124. package/Source/Scene/PointCloud.js +1 -1
  125. package/Source/Scene/PropertyAttribute.js +2 -2
  126. package/Source/Scene/PropertyAttributeProperty.js +2 -2
  127. package/Source/Scene/PropertyTable.js +2 -2
  128. package/Source/Scene/PropertyTexture.js +2 -2
  129. package/Source/Scene/PropertyTextureProperty.js +2 -2
  130. package/Source/Scene/ResourceCache.js +9 -1
  131. package/Source/Scene/ResourceCacheKey.js +9 -1
  132. package/Source/Scene/Scene.js +17 -0
  133. package/Source/Scene/SpatialNode.js +375 -0
  134. package/Source/Scene/StructuralMetadata.js +2 -2
  135. package/Source/Scene/TileMetadata.js +2 -2
  136. package/Source/Scene/TilesetMetadata.js +2 -2
  137. package/Source/Scene/VoxelBoxShape.js +527 -0
  138. package/Source/Scene/VoxelContent.js +169 -0
  139. package/Source/Scene/VoxelCylinderShape.js +937 -0
  140. package/Source/Scene/VoxelEllipsoidShape.js +937 -0
  141. package/Source/Scene/VoxelPrimitive.js +1919 -0
  142. package/Source/Scene/VoxelProvider.js +255 -0
  143. package/Source/Scene/VoxelRenderResources.js +224 -0
  144. package/Source/Scene/VoxelShape.js +152 -0
  145. package/Source/Scene/VoxelShapeType.js +105 -0
  146. package/Source/Scene/VoxelTraversal.js +1144 -0
  147. package/Source/Scene/buildVoxelDrawCommands.js +116 -0
  148. package/Source/Scene/parseBatchTable.js +18 -2
  149. package/Source/Scene/preprocess3DTileContent.js +8 -0
  150. package/Source/Scene/processVoxelProperties.js +455 -0
  151. package/Source/Shaders/BillboardCollectionVS.glsl +1 -1
  152. package/Source/Shaders/BillboardCollectionVS.js +1 -1
  153. package/Source/Shaders/Builtin/Constants/passOverlay.glsl +1 -1
  154. package/Source/Shaders/Builtin/Constants/passOverlay.js +1 -1
  155. package/Source/Shaders/Builtin/Constants/passVoxels.glsl +9 -0
  156. package/Source/Shaders/Builtin/Constants/passVoxels.js +11 -0
  157. package/Source/Shaders/Builtin/CzmBuiltins.js +17 -15
  158. package/Source/Shaders/Builtin/Functions/windowToEyeCoordinates.glsl +55 -43
  159. package/Source/Shaders/Builtin/Functions/windowToEyeCoordinates.js +55 -43
  160. package/Source/Shaders/GlobeFS.glsl +2 -1
  161. package/Source/Shaders/GlobeFS.js +2 -1
  162. package/Source/Shaders/PointPrimitiveCollectionVS.glsl +5 -2
  163. package/Source/Shaders/PointPrimitiveCollectionVS.js +5 -2
  164. package/Source/Shaders/Voxels/IntersectBox.glsl +79 -0
  165. package/Source/Shaders/Voxels/IntersectBox.js +81 -0
  166. package/Source/Shaders/Voxels/IntersectClippingPlanes.glsl +70 -0
  167. package/Source/Shaders/Voxels/IntersectClippingPlanes.js +72 -0
  168. package/Source/Shaders/Voxels/IntersectCylinder.glsl +273 -0
  169. package/Source/Shaders/Voxels/IntersectCylinder.js +275 -0
  170. package/Source/Shaders/Voxels/IntersectDepth.glsl +23 -0
  171. package/Source/Shaders/Voxels/IntersectDepth.js +25 -0
  172. package/Source/Shaders/Voxels/IntersectEllipsoid.glsl +337 -0
  173. package/Source/Shaders/Voxels/IntersectEllipsoid.js +339 -0
  174. package/Source/Shaders/Voxels/Intersection.glsl +54 -0
  175. package/Source/Shaders/Voxels/Intersection.js +56 -0
  176. package/Source/Shaders/Voxels/IntersectionUtils.glsl +151 -0
  177. package/Source/Shaders/Voxels/IntersectionUtils.js +153 -0
  178. package/Source/Shaders/Voxels/Megatexture.glsl +136 -0
  179. package/Source/Shaders/Voxels/Megatexture.js +138 -0
  180. package/Source/Shaders/Voxels/Octree.glsl +221 -0
  181. package/Source/Shaders/Voxels/Octree.js +223 -0
  182. package/Source/Shaders/Voxels/VoxelFS.glsl +150 -0
  183. package/Source/Shaders/Voxels/VoxelFS.js +152 -0
  184. package/Source/Shaders/Voxels/VoxelVS.glsl +11 -0
  185. package/Source/Shaders/Voxels/VoxelVS.js +13 -0
  186. package/Source/Shaders/Voxels/convertUvToBox.glsl +16 -0
  187. package/Source/Shaders/Voxels/convertUvToBox.js +18 -0
  188. package/Source/Shaders/Voxels/convertUvToCylinder.glsl +79 -0
  189. package/Source/Shaders/Voxels/convertUvToCylinder.js +81 -0
  190. package/Source/Shaders/Voxels/convertUvToEllipsoid.glsl +133 -0
  191. package/Source/Shaders/Voxels/convertUvToEllipsoid.js +135 -0
  192. package/Source/ThirdParty/Workers/z-worker-pako.js +0 -0
  193. package/index.d.ts +3124 -2287
  194. package/index.js +1117 -1085
  195. package/package.json +3 -4
  196. package/Build/Workers/PolygonPipeline-774a8aaf.js +0 -1341
@@ -0,0 +1,153 @@
1
+ //This file is automatically rebuilt by the Cesium build process.
2
+ export default "/* Intersection defines\n\
3
+ #define INTERSECTION_COUNT ###\n\
4
+ */\n\
5
+ \n\
6
+ #define NO_HIT (-czm_infinity)\n\
7
+ #define INF_HIT (czm_infinity * 0.5)\n\
8
+ \n\
9
+ struct Ray {\n\
10
+ vec3 pos;\n\
11
+ vec3 dir;\n\
12
+ };\n\
13
+ \n\
14
+ struct Intersections {\n\
15
+ // Don't access these member variables directly - call the functions instead.\n\
16
+ \n\
17
+ #if (INTERSECTION_COUNT > 1)\n\
18
+ // Store an array of intersections. Each intersection is composed of:\n\
19
+ // x for the T value\n\
20
+ // y for the shape type - which encodes positive vs negative and entering vs exiting\n\
21
+ // For example:\n\
22
+ // y = 0: positive shape entry\n\
23
+ // y = 1: positive shape exit\n\
24
+ // y = 2: negative shape entry\n\
25
+ // y = 3: negative shape exit\n\
26
+ vec2 intersections[INTERSECTION_COUNT * 2];\n\
27
+ \n\
28
+ // Maintain state for future nextIntersection calls\n\
29
+ int index;\n\
30
+ int surroundCount;\n\
31
+ bool surroundIsPositive;\n\
32
+ #else\n\
33
+ // When there's only one positive shape intersection none of the extra stuff is needed.\n\
34
+ float intersections[2];\n\
35
+ #endif\n\
36
+ };\n\
37
+ \n\
38
+ // Using a define instead of a real function because WebGL1 cannot access array with non-constant index.\n\
39
+ #if (INTERSECTION_COUNT > 1)\n\
40
+ #define getIntersection(/*inout Intersections*/ ix, /*int*/ index) (ix).intersections[(index)].x\n\
41
+ #else\n\
42
+ #define getIntersection(/*inout Intersections*/ ix, /*int*/ index) (ix).intersections[(index)]\n\
43
+ #endif\n\
44
+ \n\
45
+ // Using a define instead of a real function because WebGL1 cannot access array with non-constant index.\n\
46
+ #define getIntersectionPair(/*inout Intersections*/ ix, /*int*/ index) vec2(getIntersection((ix), (index) * 2 + 0), getIntersection((ix), (index) * 2 + 1))\n\
47
+ \n\
48
+ // Using a define instead of a real function because WebGL1 cannot access array with non-constant index.\n\
49
+ #if (INTERSECTION_COUNT > 1)\n\
50
+ #define setIntersection(/*inout Intersections*/ ix, /*int*/ index, /*float*/ t, /*bool*/ positive, /*enter*/ enter) (ix).intersections[(index)] = vec2((t), float(!positive) * 2.0 + float(!enter))\n\
51
+ #else\n\
52
+ #define setIntersection(/*inout Intersections*/ ix, /*int*/ index, /*float*/ t, /*bool*/ positive, /*enter*/ enter) (ix).intersections[(index)] = (t)\n\
53
+ #endif\n\
54
+ \n\
55
+ // Using a define instead of a real function because WebGL1 cannot access array with non-constant index.\n\
56
+ #if (INTERSECTION_COUNT > 1)\n\
57
+ #define setIntersectionPair(/*inout Intersections*/ ix, /*int*/ index, /*vec2*/ entryExit) (ix).intersections[(index) * 2 + 0] = vec2((entryExit).x, float((index) > 0) * 2.0 + 0.0); (ix).intersections[(index) * 2 + 1] = vec2((entryExit).y, float((index) > 0) * 2.0 + 1.0)\n\
58
+ #else\n\
59
+ #define setIntersectionPair(/*inout Intersections*/ ix, /*int*/ index, /*vec2*/ entryExit) (ix).intersections[(index) * 2 + 0] = (entryExit).x; (ix).intersections[(index) * 2 + 1] = (entryExit).y\n\
60
+ #endif\n\
61
+ \n\
62
+ #if (INTERSECTION_COUNT > 1)\n\
63
+ void initializeIntersections(inout Intersections ix) {\n\
64
+ // Sort the intersections from min T to max T with bubble sort.\n\
65
+ // Note: If this sorting function changes, some of the intersection test may\n\
66
+ // need to be updated. Search for \"bubble sort\" to find those areas.\n\
67
+ const int sortPasses = INTERSECTION_COUNT * 2 - 1;\n\
68
+ for (int n = sortPasses; n > 0; --n) {\n\
69
+ for (int i = 0; i < sortPasses; ++i) {\n\
70
+ // The loop should be: for (i = 0; i < n; ++i) {...} but WebGL1 cannot\n\
71
+ // loop with non-constant condition, so it has to break early instead\n\
72
+ if (i >= n) { break; }\n\
73
+ \n\
74
+ vec2 intersect0 = ix.intersections[i + 0];\n\
75
+ vec2 intersect1 = ix.intersections[i + 1];\n\
76
+ \n\
77
+ float t0 = intersect0.x;\n\
78
+ float t1 = intersect1.x;\n\
79
+ float b0 = intersect0.y;\n\
80
+ float b1 = intersect1.y;\n\
81
+ \n\
82
+ float tmin = min(t0, t1);\n\
83
+ float tmax = max(t0, t1);\n\
84
+ float bmin = tmin == t0 ? b0 : b1;\n\
85
+ float bmax = tmin == t0 ? b1 : b0;\n\
86
+ \n\
87
+ ix.intersections[i + 0] = vec2(tmin, bmin);\n\
88
+ ix.intersections[i + 1] = vec2(tmax, bmax);\n\
89
+ }\n\
90
+ }\n\
91
+ \n\
92
+ // Prepare initial state for nextIntersection\n\
93
+ ix.index = 0;\n\
94
+ ix.surroundCount = 0;\n\
95
+ ix.surroundIsPositive = false;\n\
96
+ }\n\
97
+ #endif\n\
98
+ \n\
99
+ #if (INTERSECTION_COUNT > 1)\n\
100
+ vec2 nextIntersection(inout Intersections ix) {\n\
101
+ vec2 entryExitT = vec2(NO_HIT);\n\
102
+ \n\
103
+ const int passCount = INTERSECTION_COUNT * 2;\n\
104
+ \n\
105
+ if (ix.index == passCount) {\n\
106
+ return entryExitT;\n\
107
+ }\n\
108
+ \n\
109
+ for (int i = 0; i < passCount; ++i) {\n\
110
+ // The loop should be: for (i = ix.index; i < passCount; ++i) {...} but WebGL1 cannot\n\
111
+ // loop with non-constant condition, so it has to continue instead.\n\
112
+ if (i < ix.index) {\n\
113
+ continue;\n\
114
+ }\n\
115
+ \n\
116
+ ix.index = i + 1;\n\
117
+ \n\
118
+ vec2 intersect = ix.intersections[i];\n\
119
+ float t = intersect.x;\n\
120
+ bool currShapeIsPositive = intersect.y < 2.0;\n\
121
+ bool enter = mod(intersect.y, 2.0) == 0.0;\n\
122
+ \n\
123
+ ix.surroundCount += enter ? +1 : -1;\n\
124
+ ix.surroundIsPositive = currShapeIsPositive ? enter : ix.surroundIsPositive;\n\
125
+ \n\
126
+ // entering positive or exiting negative\n\
127
+ if (ix.surroundCount == 1 && ix.surroundIsPositive && enter == currShapeIsPositive) {\n\
128
+ entryExitT.x = t;\n\
129
+ }\n\
130
+ \n\
131
+ // exiting positive or entering negative after being inside positive\n\
132
+ // TODO: Can this be simplified?\n\
133
+ bool exitPositive = !enter && currShapeIsPositive && ix.surroundCount == 0;\n\
134
+ bool enterNegativeFromPositive = enter && !currShapeIsPositive && ix.surroundCount == 2 && ix.surroundIsPositive;\n\
135
+ if (exitPositive || enterNegativeFromPositive) {\n\
136
+ entryExitT.y = t;\n\
137
+ \n\
138
+ // entry and exit have been found, so the loop can stop\n\
139
+ if (exitPositive) {\n\
140
+ // After exiting positive shape there is nothing left to intersect, so jump to the end index.\n\
141
+ ix.index = passCount;\n\
142
+ }\n\
143
+ break;\n\
144
+ }\n\
145
+ }\n\
146
+ \n\
147
+ return entryExitT;\n\
148
+ }\n\
149
+ #endif\n\
150
+ \n\
151
+ // NOTE: initializeIntersections, nextIntersection aren't even declared unless INTERSECTION_COUNT > 1\n\
152
+ // export { NO_HIT, INF_HIT, Ray, Intersections, getIntersectionPair, setIntersectionPair, initializeIntersections, nextIntersection };\n\
153
+ ";
@@ -0,0 +1,136 @@
1
+ // See Octree.glsl for the definitions of SampleData and intMod
2
+
3
+ /* Megatexture defines (set in Scene/VoxelRenderResources.js)
4
+ #define SAMPLE_COUNT ###
5
+ #define NEAREST_SAMPLING
6
+ #define PADDING
7
+ */
8
+
9
+ uniform ivec2 u_megatextureSliceDimensions; // number of slices per tile, in two dimensions
10
+ uniform ivec2 u_megatextureTileDimensions; // number of tiles per megatexture, in two dimensions
11
+ uniform vec2 u_megatextureVoxelSizeUv;
12
+ uniform vec2 u_megatextureSliceSizeUv;
13
+ uniform vec2 u_megatextureTileSizeUv;
14
+
15
+ uniform ivec3 u_dimensions; // does not include padding
16
+ #if defined(PADDING)
17
+ uniform ivec3 u_paddingBefore;
18
+ uniform ivec3 u_paddingAfter;
19
+ #endif
20
+
21
+ // Integer min, max, clamp: For WebGL1 only
22
+ int intMin(int a, int b) {
23
+ return a <= b ? a : b;
24
+ }
25
+ int intMax(int a, int b) {
26
+ return a >= b ? a : b;
27
+ }
28
+ int intClamp(int v, int minVal, int maxVal) {
29
+ return intMin(intMax(v, minVal), maxVal);
30
+ }
31
+
32
+ vec2 index1DTo2DTexcoord(int index, ivec2 dimensions, vec2 uvScale)
33
+ {
34
+ int indexX = intMod(index, dimensions.x);
35
+ int indexY = index / dimensions.x;
36
+ return vec2(indexX, indexY) * uvScale;
37
+ }
38
+
39
+ /*
40
+ How is 3D data stored in a 2D megatexture?
41
+
42
+ In this example there is only one loaded tile and it has 2x2x2 voxels (8 voxels total).
43
+ The data is sliced by Z. The data at Z = 0 is placed in texels (0,0), (0,1), (1,0), (1,1) and
44
+ the data at Z = 1 is placed in texels (2,0), (2,1), (3,0), (3,1).
45
+ Note that there could be empty space in the megatexture because it's a power of two.
46
+
47
+ 0 1 2 3
48
+ +---+---+---+---+
49
+ | | | | | 3
50
+ +---+---+---+---+
51
+ | | | | | 2
52
+ +-------+-------+
53
+ |010|110|011|111| 1
54
+ |--- ---|--- ---|
55
+ |000|100|001|101| 0
56
+ +-------+-------+
57
+
58
+ When doing linear interpolation the megatexture needs to be sampled twice: once for
59
+ the Z slice above the voxel coordinate and once for the slice below. The two slices
60
+ are interpolated with fract(coord.z - 0.5). For example, a Z coordinate of 1.0 is
61
+ halfway between two Z slices so the interpolation factor is 0.5. Below is a side view
62
+ of the 3D voxel grid with voxel coordinates on the left side.
63
+
64
+ 2 +---+
65
+ |001|
66
+ 1 +-z-+
67
+ |000|
68
+ 0 +---+
69
+
70
+ When doing nearest neighbor the megatexture only needs to be sampled once at the closest Z slice.
71
+ */
72
+
73
+ Properties getPropertiesFromMegatexture(in SampleData sampleData) {
74
+ vec3 tileUv = clamp(sampleData.tileUv, vec3(0.0), vec3(1.0)); // TODO is the clamp necessary?
75
+ int tileIndex = sampleData.megatextureIndex;
76
+ vec3 voxelCoord = tileUv * vec3(u_dimensions);
77
+ ivec3 voxelDimensions = u_dimensions;
78
+
79
+ #if defined(PADDING)
80
+ voxelDimensions += u_paddingBefore + u_paddingAfter;
81
+ voxelCoord += vec3(u_paddingBefore);
82
+ #endif
83
+
84
+ #if defined(NEAREST_SAMPLING)
85
+ // Round to the center of the nearest voxel
86
+ voxelCoord = floor(voxelCoord + vec3(0.5));
87
+ #endif
88
+
89
+ // Tile location
90
+ vec2 tileUvOffset = index1DTo2DTexcoord(tileIndex, u_megatextureTileDimensions, u_megatextureTileSizeUv);
91
+
92
+ // Slice location
93
+ float slice = voxelCoord.z - 0.5;
94
+ int sliceIndex = int(floor(slice));
95
+ int sliceIndex0 = intClamp(sliceIndex, 0, voxelDimensions.z - 1);
96
+ vec2 sliceUvOffset0 = index1DTo2DTexcoord(sliceIndex0, u_megatextureSliceDimensions, u_megatextureSliceSizeUv);
97
+
98
+ // Voxel location
99
+ vec2 voxelUvOffset = clamp(voxelCoord.xy, vec2(0.5), vec2(voxelDimensions.xy) - vec2(0.5)) * u_megatextureVoxelSizeUv;
100
+
101
+ // Final location in the megatexture
102
+ vec2 uv0 = tileUvOffset + sliceUvOffset0 + voxelUvOffset;
103
+
104
+ #if defined(NEAREST_SAMPLING)
105
+ return getPropertiesFromMegatextureAtUv(uv0);
106
+ #else
107
+ float sliceLerp = fract(slice);
108
+ int sliceIndex1 = intMin(sliceIndex + 1, voxelDimensions.z - 1);
109
+ vec2 sliceUvOffset1 = index1DTo2DTexcoord(sliceIndex1, u_megatextureSliceDimensions, u_megatextureSliceSizeUv);
110
+ vec2 uv1 = tileUvOffset + sliceUvOffset1 + voxelUvOffset;
111
+ Properties properties0 = getPropertiesFromMegatextureAtUv(uv0);
112
+ Properties properties1 = getPropertiesFromMegatextureAtUv(uv1);
113
+ return mixProperties(properties0, properties1, sliceLerp);
114
+ #endif
115
+ }
116
+
117
+ // Convert an array of sample datas to a final weighted properties.
118
+ Properties accumulatePropertiesFromMegatexture(in SampleData sampleDatas[SAMPLE_COUNT]) {
119
+ #if (SAMPLE_COUNT == 1)
120
+ return getPropertiesFromMegatexture(sampleDatas[0]);
121
+ #else
122
+ // When more than one sample is taken the accumulator needs to start at 0
123
+ Properties properties = clearProperties();
124
+ for (int i = 0; i < SAMPLE_COUNT; ++i) {
125
+ float weight = sampleDatas[i].weight;
126
+
127
+ // Avoid reading the megatexture when the weight is 0 as it can be costly.
128
+ if (weight > 0.0) {
129
+ Properties tempProperties = getPropertiesFromMegatexture(sampleDatas[i]);
130
+ tempProperties = scaleProperties(tempProperties, weight);
131
+ properties = sumProperties(properties, tempProperties);
132
+ }
133
+ }
134
+ return properties;
135
+ #endif
136
+ }
@@ -0,0 +1,138 @@
1
+ //This file is automatically rebuilt by the Cesium build process.
2
+ export default "// See Octree.glsl for the definitions of SampleData and intMod\n\
3
+ \n\
4
+ /* Megatexture defines (set in Scene/VoxelRenderResources.js)\n\
5
+ #define SAMPLE_COUNT ###\n\
6
+ #define NEAREST_SAMPLING\n\
7
+ #define PADDING\n\
8
+ */\n\
9
+ \n\
10
+ uniform ivec2 u_megatextureSliceDimensions; // number of slices per tile, in two dimensions\n\
11
+ uniform ivec2 u_megatextureTileDimensions; // number of tiles per megatexture, in two dimensions\n\
12
+ uniform vec2 u_megatextureVoxelSizeUv;\n\
13
+ uniform vec2 u_megatextureSliceSizeUv;\n\
14
+ uniform vec2 u_megatextureTileSizeUv;\n\
15
+ \n\
16
+ uniform ivec3 u_dimensions; // does not include padding\n\
17
+ #if defined(PADDING)\n\
18
+ uniform ivec3 u_paddingBefore;\n\
19
+ uniform ivec3 u_paddingAfter;\n\
20
+ #endif\n\
21
+ \n\
22
+ // Integer min, max, clamp: For WebGL1 only\n\
23
+ int intMin(int a, int b) {\n\
24
+ return a <= b ? a : b;\n\
25
+ }\n\
26
+ int intMax(int a, int b) {\n\
27
+ return a >= b ? a : b;\n\
28
+ }\n\
29
+ int intClamp(int v, int minVal, int maxVal) {\n\
30
+ return intMin(intMax(v, minVal), maxVal);\n\
31
+ }\n\
32
+ \n\
33
+ vec2 index1DTo2DTexcoord(int index, ivec2 dimensions, vec2 uvScale)\n\
34
+ {\n\
35
+ int indexX = intMod(index, dimensions.x);\n\
36
+ int indexY = index / dimensions.x;\n\
37
+ return vec2(indexX, indexY) * uvScale;\n\
38
+ }\n\
39
+ \n\
40
+ /*\n\
41
+ How is 3D data stored in a 2D megatexture?\n\
42
+ \n\
43
+ In this example there is only one loaded tile and it has 2x2x2 voxels (8 voxels total).\n\
44
+ The data is sliced by Z. The data at Z = 0 is placed in texels (0,0), (0,1), (1,0), (1,1) and\n\
45
+ the data at Z = 1 is placed in texels (2,0), (2,1), (3,0), (3,1).\n\
46
+ Note that there could be empty space in the megatexture because it's a power of two.\n\
47
+ \n\
48
+ 0 1 2 3\n\
49
+ +---+---+---+---+\n\
50
+ | | | | | 3\n\
51
+ +---+---+---+---+\n\
52
+ | | | | | 2\n\
53
+ +-------+-------+\n\
54
+ |010|110|011|111| 1\n\
55
+ |--- ---|--- ---|\n\
56
+ |000|100|001|101| 0\n\
57
+ +-------+-------+\n\
58
+ \n\
59
+ When doing linear interpolation the megatexture needs to be sampled twice: once for\n\
60
+ the Z slice above the voxel coordinate and once for the slice below. The two slices\n\
61
+ are interpolated with fract(coord.z - 0.5). For example, a Z coordinate of 1.0 is\n\
62
+ halfway between two Z slices so the interpolation factor is 0.5. Below is a side view\n\
63
+ of the 3D voxel grid with voxel coordinates on the left side.\n\
64
+ \n\
65
+ 2 +---+\n\
66
+ |001|\n\
67
+ 1 +-z-+\n\
68
+ |000|\n\
69
+ 0 +---+\n\
70
+ \n\
71
+ When doing nearest neighbor the megatexture only needs to be sampled once at the closest Z slice.\n\
72
+ */\n\
73
+ \n\
74
+ Properties getPropertiesFromMegatexture(in SampleData sampleData) {\n\
75
+ vec3 tileUv = clamp(sampleData.tileUv, vec3(0.0), vec3(1.0)); // TODO is the clamp necessary?\n\
76
+ int tileIndex = sampleData.megatextureIndex;\n\
77
+ vec3 voxelCoord = tileUv * vec3(u_dimensions);\n\
78
+ ivec3 voxelDimensions = u_dimensions;\n\
79
+ \n\
80
+ #if defined(PADDING)\n\
81
+ voxelDimensions += u_paddingBefore + u_paddingAfter;\n\
82
+ voxelCoord += vec3(u_paddingBefore);\n\
83
+ #endif\n\
84
+ \n\
85
+ #if defined(NEAREST_SAMPLING)\n\
86
+ // Round to the center of the nearest voxel\n\
87
+ voxelCoord = floor(voxelCoord + vec3(0.5));\n\
88
+ #endif\n\
89
+ \n\
90
+ // Tile location\n\
91
+ vec2 tileUvOffset = index1DTo2DTexcoord(tileIndex, u_megatextureTileDimensions, u_megatextureTileSizeUv);\n\
92
+ \n\
93
+ // Slice location\n\
94
+ float slice = voxelCoord.z - 0.5;\n\
95
+ int sliceIndex = int(floor(slice));\n\
96
+ int sliceIndex0 = intClamp(sliceIndex, 0, voxelDimensions.z - 1);\n\
97
+ vec2 sliceUvOffset0 = index1DTo2DTexcoord(sliceIndex0, u_megatextureSliceDimensions, u_megatextureSliceSizeUv);\n\
98
+ \n\
99
+ // Voxel location\n\
100
+ vec2 voxelUvOffset = clamp(voxelCoord.xy, vec2(0.5), vec2(voxelDimensions.xy) - vec2(0.5)) * u_megatextureVoxelSizeUv;\n\
101
+ \n\
102
+ // Final location in the megatexture\n\
103
+ vec2 uv0 = tileUvOffset + sliceUvOffset0 + voxelUvOffset;\n\
104
+ \n\
105
+ #if defined(NEAREST_SAMPLING)\n\
106
+ return getPropertiesFromMegatextureAtUv(uv0);\n\
107
+ #else\n\
108
+ float sliceLerp = fract(slice);\n\
109
+ int sliceIndex1 = intMin(sliceIndex + 1, voxelDimensions.z - 1);\n\
110
+ vec2 sliceUvOffset1 = index1DTo2DTexcoord(sliceIndex1, u_megatextureSliceDimensions, u_megatextureSliceSizeUv);\n\
111
+ vec2 uv1 = tileUvOffset + sliceUvOffset1 + voxelUvOffset;\n\
112
+ Properties properties0 = getPropertiesFromMegatextureAtUv(uv0);\n\
113
+ Properties properties1 = getPropertiesFromMegatextureAtUv(uv1);\n\
114
+ return mixProperties(properties0, properties1, sliceLerp);\n\
115
+ #endif\n\
116
+ }\n\
117
+ \n\
118
+ // Convert an array of sample datas to a final weighted properties.\n\
119
+ Properties accumulatePropertiesFromMegatexture(in SampleData sampleDatas[SAMPLE_COUNT]) {\n\
120
+ #if (SAMPLE_COUNT == 1)\n\
121
+ return getPropertiesFromMegatexture(sampleDatas[0]);\n\
122
+ #else\n\
123
+ // When more than one sample is taken the accumulator needs to start at 0\n\
124
+ Properties properties = clearProperties();\n\
125
+ for (int i = 0; i < SAMPLE_COUNT; ++i) {\n\
126
+ float weight = sampleDatas[i].weight;\n\
127
+ \n\
128
+ // Avoid reading the megatexture when the weight is 0 as it can be costly.\n\
129
+ if (weight > 0.0) {\n\
130
+ Properties tempProperties = getPropertiesFromMegatexture(sampleDatas[i]);\n\
131
+ tempProperties = scaleProperties(tempProperties, weight);\n\
132
+ properties = sumProperties(properties, tempProperties);\n\
133
+ }\n\
134
+ }\n\
135
+ return properties;\n\
136
+ #endif\n\
137
+ }\n\
138
+ ";
@@ -0,0 +1,221 @@
1
+ // These octree flags must be in sync with GpuOctreeFlag in VoxelTraversal.js
2
+ #define OCTREE_FLAG_INTERNAL 0
3
+ #define OCTREE_FLAG_LEAF 1
4
+ #define OCTREE_FLAG_PACKED_LEAF_FROM_PARENT 2
5
+
6
+ #define OCTREE_MAX_LEVELS 32 // Harcoded value because GLSL doesn't like variable length loops
7
+
8
+ uniform sampler2D u_octreeInternalNodeTexture;
9
+ uniform vec2 u_octreeInternalNodeTexelSizeUv;
10
+ uniform int u_octreeInternalNodeTilesPerRow;
11
+ uniform sampler2D u_octreeLeafNodeTexture;
12
+ uniform vec2 u_octreeLeafNodeTexelSizeUv;
13
+ uniform int u_octreeLeafNodeTilesPerRow;
14
+
15
+ uniform float u_stepSize;
16
+
17
+ struct OctreeNodeData {
18
+ int data;
19
+ int flag;
20
+ };
21
+
22
+ struct TraversalData {
23
+ float stepT;
24
+ ivec4 octreeCoords;
25
+ int parentOctreeIndex;
26
+ };
27
+
28
+ struct SampleData {
29
+ int megatextureIndex;
30
+ bool usingParentMegatextureIndex;
31
+ vec3 tileUv;
32
+ #if (SAMPLE_COUNT > 1)
33
+ float weight;
34
+ #endif
35
+ };
36
+
37
+ // Integer mod: For WebGL1 only
38
+ int intMod(in int a, in int b) {
39
+ return a - (b * (a / b));
40
+ }
41
+ int normU8_toInt(in float value) {
42
+ return int(value * 255.0);
43
+ }
44
+ int normU8x2_toInt(in vec2 value) {
45
+ return int(value.x * 255.0) + 256 * int(value.y * 255.0);
46
+ }
47
+ float normU8x2_toFloat(in vec2 value) {
48
+ return float(normU8x2_toInt(value)) / 65535.0;
49
+ }
50
+
51
+ OctreeNodeData getOctreeNodeData(in vec2 octreeUv) {
52
+ vec4 texData = texture2D(u_octreeInternalNodeTexture, octreeUv);
53
+
54
+ OctreeNodeData data;
55
+ data.data = normU8x2_toInt(texData.xy);
56
+ data.flag = normU8x2_toInt(texData.zw);
57
+ return data;
58
+ }
59
+
60
+ OctreeNodeData getOctreeChildData(in int parentOctreeIndex, in ivec3 childCoord) {
61
+ int childIndex = childCoord.z * 4 + childCoord.y * 2 + childCoord.x;
62
+ int octreeCoordX = intMod(parentOctreeIndex, u_octreeInternalNodeTilesPerRow) * 9 + 1 + childIndex;
63
+ int octreeCoordY = parentOctreeIndex / u_octreeInternalNodeTilesPerRow;
64
+ vec2 octreeUv = u_octreeInternalNodeTexelSizeUv * vec2(float(octreeCoordX) + 0.5, float(octreeCoordY) + 0.5);
65
+ return getOctreeNodeData(octreeUv);
66
+ }
67
+
68
+ int getOctreeParentIndex(in int octreeIndex) {
69
+ int octreeCoordX = intMod(octreeIndex, u_octreeInternalNodeTilesPerRow) * 9;
70
+ int octreeCoordY = octreeIndex / u_octreeInternalNodeTilesPerRow;
71
+ vec2 octreeUv = u_octreeInternalNodeTexelSizeUv * vec2(float(octreeCoordX) + 0.5, float(octreeCoordY) + 0.5);
72
+ vec4 parentData = texture2D(u_octreeInternalNodeTexture, octreeUv);
73
+ int parentOctreeIndex = normU8x2_toInt(parentData.xy);
74
+ return parentOctreeIndex;
75
+ }
76
+
77
+ /**
78
+ * Convert a position in the uv-space of the tileset bounding shape
79
+ * into the uv-space of a tile within the tileset
80
+ */
81
+ vec3 getTileUv(in vec3 shapePosition, in ivec4 octreeCoords) {
82
+ // TODO: use bit-shifting (only in WebGL2)
83
+ float dimAtLevel = pow(2.0, float(octreeCoords.w));
84
+ return shapePosition * dimAtLevel - vec3(octreeCoords.xyz);
85
+ }
86
+
87
+ void setSampleUv(in vec3 shapePosition, in ivec4 octreeCoords, inout SampleData sampleData) {
88
+ ivec4 sampleCoords = sampleData.usingParentMegatextureIndex
89
+ ? ivec4(octreeCoords.xyz / 2, octreeCoords.w - 1)
90
+ : octreeCoords;
91
+ sampleData.tileUv = getTileUv(shapePosition, sampleCoords);
92
+ }
93
+
94
+ void getOctreeLeafSampleData(in OctreeNodeData data, out SampleData sampleData) {
95
+ sampleData.megatextureIndex = data.data;
96
+ sampleData.usingParentMegatextureIndex = data.flag == OCTREE_FLAG_PACKED_LEAF_FROM_PARENT;
97
+ }
98
+
99
+ #if (SAMPLE_COUNT > 1)
100
+ void getOctreeLeafSampleDatas(in OctreeNodeData data, out SampleData sampleData0, out SampleData sampleData1) {
101
+ int leafIndex = data.data;
102
+ int leafNodeTexelCount = 2;
103
+ // Adding 0.5 moves to the center of the texel
104
+ float leafCoordXStart = float(intMod(leafIndex, u_octreeLeafNodeTilesPerRow) * leafNodeTexelCount) + 0.5;
105
+ float leafCoordY = float(leafIndex / u_octreeLeafNodeTilesPerRow) + 0.5;
106
+
107
+ vec2 leafUv0 = u_octreeLeafNodeTexelSizeUv * vec2(leafCoordXStart + 0.0, leafCoordY);
108
+ vec2 leafUv1 = u_octreeLeafNodeTexelSizeUv * vec2(leafCoordXStart + 1.0, leafCoordY);
109
+ vec4 leafData0 = texture2D(u_octreeLeafNodeTexture, leafUv0);
110
+ vec4 leafData1 = texture2D(u_octreeLeafNodeTexture, leafUv1);
111
+
112
+ float lerp = normU8x2_toFloat(leafData0.xy);
113
+
114
+ sampleData0.megatextureIndex = normU8x2_toInt(leafData1.xy);
115
+ sampleData1.megatextureIndex = normU8x2_toInt(leafData1.zw);
116
+ // TODO: this looks wrong? Should be comparing to OCTREE_FLAG_PACKED_LEAF_FROM_PARENT
117
+ sampleData0.usingParentMegatextureIndex = normU8_toInt(leafData0.z) == 1;
118
+ sampleData1.usingParentMegatextureIndex = normU8_toInt(leafData0.w) == 1;
119
+ sampleData0.weight = 1.0 - lerp;
120
+ sampleData1.weight = lerp;
121
+ }
122
+ #endif
123
+
124
+ void traverseOctreeDownwards(in vec3 shapePosition, inout TraversalData traversalData, out SampleData sampleDatas[SAMPLE_COUNT]) {
125
+ float sizeAtLevel = 1.0 / pow(2.0, float(traversalData.octreeCoords.w));
126
+ vec3 start = vec3(traversalData.octreeCoords.xyz) * sizeAtLevel;
127
+ vec3 end = start + vec3(sizeAtLevel);
128
+
129
+ for (int i = 0; i < OCTREE_MAX_LEVELS; ++i) {
130
+ // Find out which octree child contains the position
131
+ // 0 if before center, 1 if after
132
+ vec3 center = 0.5 * (start + end);
133
+ vec3 childCoord = step(center, shapePosition);
134
+
135
+ OctreeNodeData childData = getOctreeChildData(traversalData.parentOctreeIndex, ivec3(childCoord));
136
+
137
+ // Get octree coords for the next level down
138
+ ivec4 octreeCoords = traversalData.octreeCoords;
139
+ traversalData.octreeCoords = ivec4(octreeCoords.xyz * 2 + ivec3(childCoord), octreeCoords.w + 1);
140
+
141
+ if (childData.flag == OCTREE_FLAG_INTERNAL) {
142
+ // interior tile - keep going deeper
143
+ start = mix(start, center, childCoord);
144
+ end = mix(center, end, childCoord);
145
+ traversalData.parentOctreeIndex = childData.data;
146
+ } else {
147
+ // leaf tile - stop traversing
148
+ float dimAtLevel = pow(2.0, float(traversalData.octreeCoords.w));
149
+ traversalData.stepT = u_stepSize / dimAtLevel;
150
+ #if (SAMPLE_COUNT == 1)
151
+ getOctreeLeafSampleData(childData, sampleDatas[0]);
152
+ setSampleUv(shapePosition, traversalData.octreeCoords, sampleDatas[0]);
153
+ #else
154
+ getOctreeLeafSampleDatas(childData, sampleDatas[0], sampleDatas[1]);
155
+ setSampleUv(shapePosition, traversalData.octreeCoords, sampleDatas[0]);
156
+ setSampleUv(shapePosition, traversalData.octreeCoords, sampleDatas[1]);
157
+ #endif
158
+ return;
159
+ }
160
+ }
161
+ }
162
+
163
+ /**
164
+ * Transform a given position to an octree tile coordinate and a position within that tile,
165
+ * and find the corresponding megatexture index and texture coordinates
166
+ */
167
+ void traverseOctreeFromBeginning(in vec3 shapePosition, out TraversalData traversalData, out SampleData sampleDatas[SAMPLE_COUNT]) {
168
+ traversalData.octreeCoords = ivec4(0);
169
+ traversalData.parentOctreeIndex = 0;
170
+
171
+ OctreeNodeData rootData = getOctreeNodeData(vec2(0.0));
172
+ if (rootData.flag == OCTREE_FLAG_LEAF) {
173
+ // No child data, only the root tile has data
174
+ traversalData.stepT = u_stepSize;
175
+ #if (SAMPLE_COUNT == 1)
176
+ getOctreeLeafSampleData(rootData, sampleDatas[0]);
177
+ setSampleUv(shapePosition, traversalData.octreeCoords, sampleDatas[0]);
178
+ #else
179
+ getOctreeLeafSampleDatas(rootData, sampleDatas[0], sampleDatas[1]);
180
+ setSampleUv(shapePosition, traversalData.octreeCoords, sampleDatas[0]);
181
+ setSampleUv(shapePosition, traversalData.octreeCoords, sampleDatas[1]);
182
+ #endif
183
+ } else {
184
+ traverseOctreeDownwards(shapePosition, traversalData, sampleDatas);
185
+ }
186
+ }
187
+
188
+ bool inRange(in vec3 v, in vec3 minVal, in vec3 maxVal) {
189
+ return clamp(v, minVal, maxVal) == v;
190
+ }
191
+
192
+ bool insideTile(in vec3 shapePosition, in ivec4 octreeCoords) {
193
+ vec3 tileUv = getTileUv(shapePosition, octreeCoords);
194
+ bool inside = inRange(tileUv, vec3(0.0), vec3(1.0));
195
+ // Assume (!) the position is always inside the root tile.
196
+ return inside || octreeCoords.w == 0;
197
+ }
198
+
199
+ void traverseOctreeFromExisting(in vec3 shapePosition, inout TraversalData traversalData, inout SampleData sampleDatas[SAMPLE_COUNT]) {
200
+ if (insideTile(shapePosition, traversalData.octreeCoords)) {
201
+ for (int i = 0; i < SAMPLE_COUNT; i++) {
202
+ setSampleUv(shapePosition, traversalData.octreeCoords, sampleDatas[i]);
203
+ }
204
+ } else {
205
+ // Go up tree
206
+ for (int i = 0; i < OCTREE_MAX_LEVELS; ++i)
207
+ {
208
+ traversalData.octreeCoords.xyz /= 2;
209
+ traversalData.octreeCoords.w -= 1;
210
+
211
+ if (!insideTile(shapePosition, traversalData.octreeCoords)) {
212
+ traversalData.parentOctreeIndex = getOctreeParentIndex(traversalData.parentOctreeIndex);
213
+ } else {
214
+ break;
215
+ }
216
+ }
217
+
218
+ // Go down tree
219
+ traverseOctreeDownwards(shapePosition, traversalData, sampleDatas);
220
+ }
221
+ }