@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.
- package/Build/Workers/{AttributeCompression-4589338a.js → AttributeCompression-b646d393.js} +1 -1
- package/Build/Workers/{AxisAlignedBoundingBox-bfb1234f.js → AxisAlignedBoundingBox-a4321399.js} +1 -1
- package/Build/Workers/{BoundingRectangle-7ffc2153.js → BoundingRectangle-80d8801f.js} +1 -1
- package/Build/Workers/{BoxGeometry-93f344a3.js → BoxGeometry-33c10a4f.js} +1 -1
- package/Build/Workers/{Color-0c5aaf47.js → Color-1bf9a6e0.js} +1 -1
- package/Build/Workers/{CoplanarPolygonGeometryLibrary-6597982a.js → CoplanarPolygonGeometryLibrary-5c5b981b.js} +1 -1
- package/Build/Workers/{CorridorGeometryLibrary-2119580e.js → CorridorGeometryLibrary-7cbae7a0.js} +1 -1
- package/Build/Workers/{CylinderGeometry-f9503c6d.js → CylinderGeometry-42740df0.js} +1 -1
- package/Build/Workers/{EllipseGeometry-fedf72d5.js → EllipseGeometry-49a3ac21.js} +1 -1
- package/Build/Workers/{EllipseGeometryLibrary-4ea68687.js → EllipseGeometryLibrary-b891b2f8.js} +1 -1
- package/Build/Workers/{EllipseOutlineGeometry-e2ae6a35.js → EllipseOutlineGeometry-fbd72e07.js} +1 -1
- package/Build/Workers/{EllipsoidGeodesic-16de63ea.js → EllipsoidGeodesic-98c62a56.js} +1 -1
- package/Build/Workers/{EllipsoidGeometry-95c0330e.js → EllipsoidGeometry-a351dba8.js} +1 -1
- package/Build/Workers/{EllipsoidOutlineGeometry-d6d2ceec.js → EllipsoidOutlineGeometry-3e8779bf.js} +1 -1
- package/Build/Workers/{EllipsoidRhumbLine-ae5e65e0.js → EllipsoidRhumbLine-19756602.js} +1 -1
- package/Build/Workers/{EllipsoidTangentPlane-bfc674bf.js → EllipsoidTangentPlane-cfb50678.js} +1 -1
- package/Build/Workers/{EncodedCartesian3-f473ea18.js → EncodedCartesian3-81f70735.js} +1 -1
- package/Build/Workers/{FrustumGeometry-3bf2e4eb.js → FrustumGeometry-c5754412.js} +1 -1
- package/Build/Workers/{GeometryAttribute-df5f473e.js → GeometryAttribute-0bfd05e8.js} +1 -1
- package/Build/Workers/{GeometryInstance-aa75b4cf.js → GeometryInstance-451dc1cd.js} +1 -1
- package/Build/Workers/{GeometryPipeline-f0e46c42.js → GeometryPipeline-0166905d.js} +1 -1
- package/Build/Workers/{IntersectionTests-9de29d51.js → IntersectionTests-a93d3de9.js} +1 -1
- package/Build/Workers/{Matrix2-ce637455.js → Matrix2-13178034.js} +4 -2
- package/Build/Workers/{Matrix3-4f4df527.js → Matrix3-315394f6.js} +2 -1
- package/Build/Workers/{OrientedBoundingBox-d3ff3d4d.js → OrientedBoundingBox-b450cb61.js} +5 -5
- package/Build/Workers/{Plane-b81241c2.js → Plane-900aa728.js} +1 -1
- package/Build/Workers/{PolygonGeometryLibrary-6f4937bb.js → PolygonGeometryLibrary-f918ac26.js} +1 -1
- package/Build/Workers/PolygonPipeline-f59a8f0a.js +1345 -0
- package/Build/Workers/{PolylinePipeline-2e2b015c.js → PolylinePipeline-d8e6bd9b.js} +1 -1
- package/Build/Workers/{PolylineVolumeGeometryLibrary-7ee1d449.js → PolylineVolumeGeometryLibrary-125d2edf.js} +1 -1
- package/Build/Workers/{PrimitivePipeline-a9b7aae0.js → PrimitivePipeline-0d7b5ed4.js} +1 -1
- package/Build/Workers/{RectangleGeometryLibrary-9aa6c8f6.js → RectangleGeometryLibrary-0768db63.js} +1 -1
- package/Build/Workers/{TerrainEncoding-b52dcfc5.js → TerrainEncoding-06470d7f.js} +1 -1
- package/Build/Workers/{Transforms-2f755df8.js → Transforms-26539bce.js} +97 -83
- package/Build/Workers/{WallGeometryLibrary-ab19a93d.js → WallGeometryLibrary-6167b0fc.js} +1 -1
- package/Build/Workers/{WebMercatorProjection-9f25de49.js → WebMercatorProjection-13a90d41.js} +1 -1
- package/Build/Workers/cesiumWorkerBootstrapper.js +25 -1
- package/Build/Workers/combineGeometry.js +1 -1
- package/Build/Workers/createBoxGeometry.js +1 -1
- package/Build/Workers/createBoxOutlineGeometry.js +1 -1
- package/Build/Workers/createCircleGeometry.js +1 -1
- package/Build/Workers/createCircleOutlineGeometry.js +1 -1
- package/Build/Workers/createCoplanarPolygonGeometry.js +1 -1
- package/Build/Workers/createCoplanarPolygonOutlineGeometry.js +1 -1
- package/Build/Workers/createCorridorGeometry.js +1 -1
- package/Build/Workers/createCorridorOutlineGeometry.js +1 -1
- package/Build/Workers/createCylinderGeometry.js +1 -1
- package/Build/Workers/createCylinderOutlineGeometry.js +1 -1
- package/Build/Workers/createEllipseGeometry.js +1 -1
- package/Build/Workers/createEllipseOutlineGeometry.js +1 -1
- package/Build/Workers/createEllipsoidGeometry.js +1 -1
- package/Build/Workers/createEllipsoidOutlineGeometry.js +1 -1
- package/Build/Workers/createFrustumGeometry.js +1 -1
- package/Build/Workers/createFrustumOutlineGeometry.js +1 -1
- package/Build/Workers/createGeometry.js +1 -1
- package/Build/Workers/createGroundPolylineGeometry.js +1 -1
- package/Build/Workers/createPlaneGeometry.js +1 -1
- package/Build/Workers/createPlaneOutlineGeometry.js +1 -1
- package/Build/Workers/createPolygonGeometry.js +1 -1
- package/Build/Workers/createPolygonOutlineGeometry.js +1 -1
- package/Build/Workers/createPolylineGeometry.js +1 -1
- package/Build/Workers/createPolylineVolumeGeometry.js +1 -1
- package/Build/Workers/createPolylineVolumeOutlineGeometry.js +1 -1
- package/Build/Workers/createRectangleGeometry.js +1 -1
- package/Build/Workers/createRectangleOutlineGeometry.js +1 -1
- package/Build/Workers/createSimplePolylineGeometry.js +1 -1
- package/Build/Workers/createSphereGeometry.js +1 -1
- package/Build/Workers/createSphereOutlineGeometry.js +1 -1
- package/Build/Workers/createVectorTileClampedPolylines.js +1 -1
- package/Build/Workers/createVectorTileGeometries.js +1 -1
- package/Build/Workers/createVectorTilePoints.js +1 -1
- package/Build/Workers/createVectorTilePolygons.js +1 -1
- package/Build/Workers/createVectorTilePolylines.js +1 -1
- package/Build/Workers/createVerticesFromGoogleEarthEnterpriseBuffer.js +1 -1
- package/Build/Workers/createVerticesFromHeightmap.js +7 -3
- package/Build/Workers/createVerticesFromQuantizedTerrainMesh.js +1 -1
- package/Build/Workers/createWallGeometry.js +1 -1
- package/Build/Workers/createWallOutlineGeometry.js +1 -1
- package/Build/Workers/decodeI3S.js +1 -1
- package/Build/Workers/package.js +25 -1
- package/Build/Workers/transferTypedArrayTest.js +25 -1
- package/Build/Workers/upsampleQuantizedTerrainMesh.js +1 -1
- package/Source/Core/EarthOrientationParameters.js +67 -63
- package/Source/Core/Ion.js +1 -1
- package/Source/Core/Matrix2.js +2 -1
- package/Source/Core/Matrix3.js +2 -1
- package/Source/Core/Matrix4.js +1 -0
- package/Source/Core/OrientedBoundingBox.js +4 -4
- package/Source/Core/S2Cell.js +3 -3
- package/Source/Core/Transforms.js +3 -7
- package/Source/DataSources/GpxDataSource.js +4 -6
- package/Source/DataSources/KmlDataSource.js +3 -5
- package/Source/Renderer/Context.js +27 -9
- package/Source/Renderer/Pass.js +3 -2
- package/Source/Scene/Cesium3DTileContentType.js +19 -0
- package/Source/Scene/Cesium3DTilesVoxelProvider.js +482 -0
- package/Source/Scene/Cesium3DTilesetMetadata.js +2 -2
- package/Source/Scene/ContentMetadata.js +2 -2
- package/Source/Scene/DerivedCommand.js +7 -0
- package/Source/Scene/Expression.js +1 -1
- package/Source/Scene/Globe.js +10 -0
- package/Source/Scene/GlobeSurfaceTileProvider.js +7 -0
- package/Source/Scene/GltfImageLoader.js +1 -1
- package/Source/Scene/GltfVertexBufferLoader.js +10 -2
- package/Source/Scene/GroupMetadata.js +2 -2
- package/Source/Scene/ImplicitMetadataView.js +2 -2
- package/Source/Scene/ImplicitSubtreeCache.js +127 -0
- package/Source/Scene/ImplicitSubtreeMetadata.js +2 -2
- package/Source/Scene/ImplicitTileset.js +3 -2
- package/Source/Scene/KeyframeNode.js +47 -0
- package/Source/Scene/Megatexture.js +490 -0
- package/Source/Scene/MetadataClass.js +60 -25
- package/Source/Scene/MetadataClassProperty.js +132 -68
- package/Source/Scene/MetadataComponentType.js +78 -57
- package/Source/Scene/MetadataEnum.js +59 -23
- package/Source/Scene/MetadataEnumValue.js +49 -15
- package/Source/Scene/MetadataSchema.js +53 -24
- package/Source/Scene/MetadataSchemaLoader.js +2 -2
- package/Source/Scene/MetadataTableProperty.js +2 -2
- package/Source/Scene/MetadataType.js +6 -14
- package/Source/Scene/Model/GeoJsonLoader.js +1 -1
- package/Source/Scene/Model/Model.js +2 -3
- package/Source/Scene/Model/buildDrawCommand.js +19 -11
- package/Source/Scene/PointCloud.js +1 -1
- package/Source/Scene/PropertyAttribute.js +2 -2
- package/Source/Scene/PropertyAttributeProperty.js +2 -2
- package/Source/Scene/PropertyTable.js +2 -2
- package/Source/Scene/PropertyTexture.js +2 -2
- package/Source/Scene/PropertyTextureProperty.js +2 -2
- package/Source/Scene/ResourceCache.js +9 -1
- package/Source/Scene/ResourceCacheKey.js +9 -1
- package/Source/Scene/Scene.js +17 -0
- package/Source/Scene/SpatialNode.js +375 -0
- package/Source/Scene/StructuralMetadata.js +2 -2
- package/Source/Scene/TileMetadata.js +2 -2
- package/Source/Scene/TilesetMetadata.js +2 -2
- package/Source/Scene/VoxelBoxShape.js +527 -0
- package/Source/Scene/VoxelContent.js +169 -0
- package/Source/Scene/VoxelCylinderShape.js +937 -0
- package/Source/Scene/VoxelEllipsoidShape.js +937 -0
- package/Source/Scene/VoxelPrimitive.js +1919 -0
- package/Source/Scene/VoxelProvider.js +255 -0
- package/Source/Scene/VoxelRenderResources.js +224 -0
- package/Source/Scene/VoxelShape.js +152 -0
- package/Source/Scene/VoxelShapeType.js +105 -0
- package/Source/Scene/VoxelTraversal.js +1144 -0
- package/Source/Scene/buildVoxelDrawCommands.js +116 -0
- package/Source/Scene/parseBatchTable.js +18 -2
- package/Source/Scene/preprocess3DTileContent.js +8 -0
- package/Source/Scene/processVoxelProperties.js +455 -0
- package/Source/Shaders/BillboardCollectionVS.glsl +1 -1
- package/Source/Shaders/BillboardCollectionVS.js +1 -1
- package/Source/Shaders/Builtin/Constants/passOverlay.glsl +1 -1
- package/Source/Shaders/Builtin/Constants/passOverlay.js +1 -1
- package/Source/Shaders/Builtin/Constants/passVoxels.glsl +9 -0
- package/Source/Shaders/Builtin/Constants/passVoxels.js +11 -0
- package/Source/Shaders/Builtin/CzmBuiltins.js +17 -15
- package/Source/Shaders/Builtin/Functions/windowToEyeCoordinates.glsl +55 -43
- package/Source/Shaders/Builtin/Functions/windowToEyeCoordinates.js +55 -43
- package/Source/Shaders/GlobeFS.glsl +2 -1
- package/Source/Shaders/GlobeFS.js +2 -1
- package/Source/Shaders/PointPrimitiveCollectionVS.glsl +5 -2
- package/Source/Shaders/PointPrimitiveCollectionVS.js +5 -2
- package/Source/Shaders/Voxels/IntersectBox.glsl +79 -0
- package/Source/Shaders/Voxels/IntersectBox.js +81 -0
- package/Source/Shaders/Voxels/IntersectClippingPlanes.glsl +70 -0
- package/Source/Shaders/Voxels/IntersectClippingPlanes.js +72 -0
- package/Source/Shaders/Voxels/IntersectCylinder.glsl +273 -0
- package/Source/Shaders/Voxels/IntersectCylinder.js +275 -0
- package/Source/Shaders/Voxels/IntersectDepth.glsl +23 -0
- package/Source/Shaders/Voxels/IntersectDepth.js +25 -0
- package/Source/Shaders/Voxels/IntersectEllipsoid.glsl +337 -0
- package/Source/Shaders/Voxels/IntersectEllipsoid.js +339 -0
- package/Source/Shaders/Voxels/Intersection.glsl +54 -0
- package/Source/Shaders/Voxels/Intersection.js +56 -0
- package/Source/Shaders/Voxels/IntersectionUtils.glsl +151 -0
- package/Source/Shaders/Voxels/IntersectionUtils.js +153 -0
- package/Source/Shaders/Voxels/Megatexture.glsl +136 -0
- package/Source/Shaders/Voxels/Megatexture.js +138 -0
- package/Source/Shaders/Voxels/Octree.glsl +221 -0
- package/Source/Shaders/Voxels/Octree.js +223 -0
- package/Source/Shaders/Voxels/VoxelFS.glsl +150 -0
- package/Source/Shaders/Voxels/VoxelFS.js +152 -0
- package/Source/Shaders/Voxels/VoxelVS.glsl +11 -0
- package/Source/Shaders/Voxels/VoxelVS.js +13 -0
- package/Source/Shaders/Voxels/convertUvToBox.glsl +16 -0
- package/Source/Shaders/Voxels/convertUvToBox.js +18 -0
- package/Source/Shaders/Voxels/convertUvToCylinder.glsl +79 -0
- package/Source/Shaders/Voxels/convertUvToCylinder.js +81 -0
- package/Source/Shaders/Voxels/convertUvToEllipsoid.glsl +133 -0
- package/Source/Shaders/Voxels/convertUvToEllipsoid.js +135 -0
- package/Source/ThirdParty/Workers/z-worker-pako.js +0 -0
- package/index.d.ts +3124 -2287
- package/index.js +1117 -1085
- package/package.json +3 -4
- package/Build/Workers/PolygonPipeline-774a8aaf.js +0 -1341
|
@@ -0,0 +1,339 @@
|
|
|
1
|
+
//This file is automatically rebuilt by the Cesium build process.
|
|
2
|
+
export default "// See IntersectionUtils.glsl for the definitions of Ray, Intersections,\n\
|
|
3
|
+
// setIntersection, setIntersectionPair, INF_HIT, NO_HIT\n\
|
|
4
|
+
\n\
|
|
5
|
+
/* Ellipsoid defines (set in Scene/VoxelEllipsoidShape.js)\n\
|
|
6
|
+
#define ELLIPSOID_HAS_RENDER_BOUNDS_LONGITUDE\n\
|
|
7
|
+
#define ELLIPSOID_HAS_RENDER_BOUNDS_LONGITUDE_RANGE_EQUAL_ZERO\n\
|
|
8
|
+
#define ELLIPSOID_HAS_RENDER_BOUNDS_LONGITUDE_RANGE_UNDER_HALF\n\
|
|
9
|
+
#define ELLIPSOID_HAS_RENDER_BOUNDS_LONGITUDE_RANGE_EQUAL_HALF\n\
|
|
10
|
+
#define ELLIPSOID_HAS_RENDER_BOUNDS_LONGITUDE_RANGE_OVER_HALF\n\
|
|
11
|
+
#define ELLIPSOID_HAS_RENDER_BOUNDS_LATITUDE\n\
|
|
12
|
+
#define ELLIPSOID_HAS_RENDER_BOUNDS_LATITUDE_MAX_UNDER_HALF\n\
|
|
13
|
+
#define ELLIPSOID_HAS_RENDER_BOUNDS_LATITUDE_MAX_EQUAL_HALF\n\
|
|
14
|
+
#define ELLIPSOID_HAS_RENDER_BOUNDS_LATITUDE_MAX_OVER_HALF\n\
|
|
15
|
+
#define ELLIPSOID_HAS_RENDER_BOUNDS_LATITUDE_MIN_UNDER_HALF\n\
|
|
16
|
+
#define ELLIPSOID_HAS_RENDER_BOUNDS_LATITUDE_MIN_EQUAL_HALF\n\
|
|
17
|
+
#define ELLIPSOID_HAS_RENDER_BOUNDS_LATITUDE_MIN_OVER_HALF\n\
|
|
18
|
+
#define ELLIPSOID_HAS_RENDER_BOUNDS_HEIGHT_MIN\n\
|
|
19
|
+
#define ELLIPSOID_HAS_RENDER_BOUNDS_HEIGHT_FLAT\n\
|
|
20
|
+
#define ELLIPSOID_INTERSECTION_INDEX_LONGITUDE\n\
|
|
21
|
+
#define ELLIPSOID_INTERSECTION_INDEX_LATITUDE_MAX\n\
|
|
22
|
+
#define ELLIPSOID_INTERSECTION_INDEX_LATITUDE_MIN\n\
|
|
23
|
+
#define ELLIPSOID_INTERSECTION_INDEX_HEIGHT_MAX\n\
|
|
24
|
+
#define ELLIPSOID_INTERSECTION_INDEX_HEIGHT_MIN\n\
|
|
25
|
+
*/\n\
|
|
26
|
+
\n\
|
|
27
|
+
#if defined(ELLIPSOID_HAS_RENDER_BOUNDS_LONGITUDE)\n\
|
|
28
|
+
uniform vec2 u_ellipsoidRenderLongitudeMinMax;\n\
|
|
29
|
+
#endif\n\
|
|
30
|
+
#if defined(ELLIPSOID_HAS_RENDER_BOUNDS_LATITUDE_MIN_UNDER_HALF) || defined(ELLIPSOID_HAS_RENDER_BOUNDS_LATITUDE_MIN_OVER_HALF) || defined(ELLIPSOID_HAS_RENDER_BOUNDS_LATITUDE_MAX_UNDER_HALF) || defined(ELLIPSOID_HAS_RENDER_BOUNDS_LATITUDE_MAX_OVER_HALF)\n\
|
|
31
|
+
uniform vec2 u_ellipsoidRenderLatitudeCosSqrHalfMinMax;\n\
|
|
32
|
+
#endif\n\
|
|
33
|
+
#if defined(ELLIPSOID_HAS_RENDER_BOUNDS_HEIGHT_MIN)\n\
|
|
34
|
+
uniform float u_ellipsoidInverseInnerScaleUv;\n\
|
|
35
|
+
#endif\n\
|
|
36
|
+
\n\
|
|
37
|
+
vec2 intersectZPlane(Ray ray)\n\
|
|
38
|
+
{\n\
|
|
39
|
+
float o = ray.pos.z;\n\
|
|
40
|
+
float d = ray.dir.z;\n\
|
|
41
|
+
float t = -o / d;\n\
|
|
42
|
+
float s = sign(o);\n\
|
|
43
|
+
\n\
|
|
44
|
+
if (t >= 0.0 != s >= 0.0) return vec2(t, +INF_HIT);\n\
|
|
45
|
+
else return vec2(-INF_HIT, t);\n\
|
|
46
|
+
}\n\
|
|
47
|
+
\n\
|
|
48
|
+
vec4 intersectHalfPlane(Ray ray, float angle) {\n\
|
|
49
|
+
vec2 o = ray.pos.xy;\n\
|
|
50
|
+
vec2 d = ray.dir.xy;\n\
|
|
51
|
+
vec2 planeDirection = vec2(cos(angle), sin(angle));\n\
|
|
52
|
+
vec2 planeNormal = vec2(planeDirection.y, -planeDirection.x);\n\
|
|
53
|
+
\n\
|
|
54
|
+
float a = dot(o, planeNormal);\n\
|
|
55
|
+
float b = dot(d, planeNormal);\n\
|
|
56
|
+
float t = -a / b;\n\
|
|
57
|
+
\n\
|
|
58
|
+
vec2 p = o + t * d;\n\
|
|
59
|
+
bool outside = dot(p, planeDirection) < 0.0;\n\
|
|
60
|
+
if (outside) return vec4(-INF_HIT, +INF_HIT, NO_HIT, NO_HIT);\n\
|
|
61
|
+
\n\
|
|
62
|
+
return vec4(-INF_HIT, t, t, +INF_HIT);\n\
|
|
63
|
+
}\n\
|
|
64
|
+
\n\
|
|
65
|
+
vec2 intersectHalfSpace(Ray ray, float angle)\n\
|
|
66
|
+
{\n\
|
|
67
|
+
vec2 o = ray.pos.xy;\n\
|
|
68
|
+
vec2 d = ray.dir.xy;\n\
|
|
69
|
+
vec2 n = vec2(sin(angle), -cos(angle));\n\
|
|
70
|
+
\n\
|
|
71
|
+
float a = dot(o, n);\n\
|
|
72
|
+
float b = dot(d, n);\n\
|
|
73
|
+
float t = -a / b;\n\
|
|
74
|
+
float s = sign(a);\n\
|
|
75
|
+
\n\
|
|
76
|
+
if (t >= 0.0 != s >= 0.0) return vec2(t, +INF_HIT);\n\
|
|
77
|
+
else return vec2(-INF_HIT, t);\n\
|
|
78
|
+
}\n\
|
|
79
|
+
\n\
|
|
80
|
+
vec2 intersectRegularWedge(Ray ray, float minAngle, float maxAngle)\n\
|
|
81
|
+
{\n\
|
|
82
|
+
vec2 o = ray.pos.xy;\n\
|
|
83
|
+
vec2 d = ray.dir.xy;\n\
|
|
84
|
+
vec2 n1 = vec2(sin(minAngle), -cos(minAngle));\n\
|
|
85
|
+
vec2 n2 = vec2(-sin(maxAngle), cos(maxAngle));\n\
|
|
86
|
+
\n\
|
|
87
|
+
float a1 = dot(o, n1);\n\
|
|
88
|
+
float a2 = dot(o, n2);\n\
|
|
89
|
+
float b1 = dot(d, n1);\n\
|
|
90
|
+
float b2 = dot(d, n2);\n\
|
|
91
|
+
\n\
|
|
92
|
+
float t1 = -a1 / b1;\n\
|
|
93
|
+
float t2 = -a2 / b2;\n\
|
|
94
|
+
float s1 = sign(a1);\n\
|
|
95
|
+
float s2 = sign(a2);\n\
|
|
96
|
+
\n\
|
|
97
|
+
float tmin = min(t1, t2);\n\
|
|
98
|
+
float tmax = max(t1, t2);\n\
|
|
99
|
+
float smin = tmin == t1 ? s1 : s2;\n\
|
|
100
|
+
float smax = tmin == t1 ? s2 : s1;\n\
|
|
101
|
+
\n\
|
|
102
|
+
bool e = tmin >= 0.0;\n\
|
|
103
|
+
bool f = tmax >= 0.0;\n\
|
|
104
|
+
bool g = smin >= 0.0;\n\
|
|
105
|
+
bool h = smax >= 0.0;\n\
|
|
106
|
+
\n\
|
|
107
|
+
if (e != g && f == h) return vec2(tmin, tmax);\n\
|
|
108
|
+
else if (e == g && f == h) return vec2(-INF_HIT, tmin);\n\
|
|
109
|
+
else if (e != g && f != h) return vec2(tmax, +INF_HIT);\n\
|
|
110
|
+
else return vec2(NO_HIT);\n\
|
|
111
|
+
}\n\
|
|
112
|
+
\n\
|
|
113
|
+
vec4 intersectFlippedWedge(Ray ray, float minAngle, float maxAngle)\n\
|
|
114
|
+
{\n\
|
|
115
|
+
vec2 planeIntersectMin = intersectHalfSpace(ray, minAngle);\n\
|
|
116
|
+
vec2 planeIntersectMax = intersectHalfSpace(ray, maxAngle + czm_pi);\n\
|
|
117
|
+
return vec4(planeIntersectMin, planeIntersectMax);\n\
|
|
118
|
+
}\n\
|
|
119
|
+
\n\
|
|
120
|
+
vec2 intersectUnitSphere(Ray ray)\n\
|
|
121
|
+
{\n\
|
|
122
|
+
vec3 o = ray.pos;\n\
|
|
123
|
+
vec3 d = ray.dir;\n\
|
|
124
|
+
\n\
|
|
125
|
+
float b = dot(d, o);\n\
|
|
126
|
+
float c = dot(o, o) - 1.0;\n\
|
|
127
|
+
float det = b * b - c;\n\
|
|
128
|
+
\n\
|
|
129
|
+
if (det < 0.0) {\n\
|
|
130
|
+
return vec2(NO_HIT);\n\
|
|
131
|
+
}\n\
|
|
132
|
+
\n\
|
|
133
|
+
det = sqrt(det);\n\
|
|
134
|
+
float t1 = -b - det;\n\
|
|
135
|
+
float t2 = -b + det;\n\
|
|
136
|
+
float tmin = min(t1, t2);\n\
|
|
137
|
+
float tmax = max(t1, t2);\n\
|
|
138
|
+
\n\
|
|
139
|
+
return vec2(tmin, tmax);\n\
|
|
140
|
+
}\n\
|
|
141
|
+
\n\
|
|
142
|
+
vec2 intersectUnitSphereUnnormalizedDirection(Ray ray)\n\
|
|
143
|
+
{\n\
|
|
144
|
+
vec3 o = ray.pos;\n\
|
|
145
|
+
vec3 d = ray.dir;\n\
|
|
146
|
+
\n\
|
|
147
|
+
float a = dot(d, d);\n\
|
|
148
|
+
float b = dot(d, o);\n\
|
|
149
|
+
float c = dot(o, o) - 1.0;\n\
|
|
150
|
+
float det = b * b - a * c;\n\
|
|
151
|
+
\n\
|
|
152
|
+
if (det < 0.0) {\n\
|
|
153
|
+
return vec2(NO_HIT);\n\
|
|
154
|
+
}\n\
|
|
155
|
+
\n\
|
|
156
|
+
det = sqrt(det);\n\
|
|
157
|
+
float t1 = (-b - det) / a;\n\
|
|
158
|
+
float t2 = (-b + det) / a;\n\
|
|
159
|
+
float tmin = min(t1, t2);\n\
|
|
160
|
+
float tmax = max(t1, t2);\n\
|
|
161
|
+
\n\
|
|
162
|
+
return vec2(tmin, tmax);\n\
|
|
163
|
+
}\n\
|
|
164
|
+
\n\
|
|
165
|
+
vec2 intersectDoubleEndedCone(Ray ray, float cosSqrHalfAngle)\n\
|
|
166
|
+
{\n\
|
|
167
|
+
vec3 o = ray.pos;\n\
|
|
168
|
+
vec3 d = ray.dir;\n\
|
|
169
|
+
float a = d.z * d.z - dot(d, d) * cosSqrHalfAngle;\n\
|
|
170
|
+
float b = d.z * o.z - dot(o, d) * cosSqrHalfAngle;\n\
|
|
171
|
+
float c = o.z * o.z - dot(o, o) * cosSqrHalfAngle;\n\
|
|
172
|
+
float det = b * b - a * c;\n\
|
|
173
|
+
\n\
|
|
174
|
+
if (det < 0.0) {\n\
|
|
175
|
+
return vec2(NO_HIT);\n\
|
|
176
|
+
}\n\
|
|
177
|
+
\n\
|
|
178
|
+
det = sqrt(det);\n\
|
|
179
|
+
float t1 = (-b - det) / a;\n\
|
|
180
|
+
float t2 = (-b + det) / a;\n\
|
|
181
|
+
float tmin = min(t1, t2);\n\
|
|
182
|
+
float tmax = max(t1, t2);\n\
|
|
183
|
+
return vec2(tmin, tmax);\n\
|
|
184
|
+
}\n\
|
|
185
|
+
\n\
|
|
186
|
+
vec4 intersectFlippedCone(Ray ray, float cosSqrHalfAngle) {\n\
|
|
187
|
+
vec2 intersect = intersectDoubleEndedCone(ray, cosSqrHalfAngle);\n\
|
|
188
|
+
\n\
|
|
189
|
+
if (intersect.x == NO_HIT) {\n\
|
|
190
|
+
return vec4(-INF_HIT, +INF_HIT, NO_HIT, NO_HIT);\n\
|
|
191
|
+
}\n\
|
|
192
|
+
\n\
|
|
193
|
+
vec3 o = ray.pos;\n\
|
|
194
|
+
vec3 d = ray.dir;\n\
|
|
195
|
+
float tmin = intersect.x;\n\
|
|
196
|
+
float tmax = intersect.y;\n\
|
|
197
|
+
float zmin = o.z + tmin * d.z;\n\
|
|
198
|
+
float zmax = o.z + tmax * d.z;\n\
|
|
199
|
+
\n\
|
|
200
|
+
// One interval\n\
|
|
201
|
+
if (zmin < 0.0 && zmax < 0.0) return vec4(-INF_HIT, +INF_HIT, NO_HIT, NO_HIT);\n\
|
|
202
|
+
else if (zmin < 0.0) return vec4(-INF_HIT, tmax, NO_HIT, NO_HIT);\n\
|
|
203
|
+
else if (zmax < 0.0) return vec4(tmin, +INF_HIT, NO_HIT, NO_HIT);\n\
|
|
204
|
+
// Two intervals\n\
|
|
205
|
+
else return vec4(-INF_HIT, tmin, tmax, +INF_HIT);\n\
|
|
206
|
+
}\n\
|
|
207
|
+
\n\
|
|
208
|
+
vec2 intersectRegularCone(Ray ray, float cosSqrHalfAngle) {\n\
|
|
209
|
+
vec2 intersect = intersectDoubleEndedCone(ray, cosSqrHalfAngle);\n\
|
|
210
|
+
\n\
|
|
211
|
+
if (intersect.x == NO_HIT) {\n\
|
|
212
|
+
return vec2(NO_HIT);\n\
|
|
213
|
+
}\n\
|
|
214
|
+
\n\
|
|
215
|
+
vec3 o = ray.pos;\n\
|
|
216
|
+
vec3 d = ray.dir;\n\
|
|
217
|
+
float tmin = intersect.x;\n\
|
|
218
|
+
float tmax = intersect.y;\n\
|
|
219
|
+
float zmin = o.z + tmin * d.z;\n\
|
|
220
|
+
float zmax = o.z + tmax * d.z;\n\
|
|
221
|
+
\n\
|
|
222
|
+
if (zmin < 0.0 && zmax < 0.0) return vec2(NO_HIT);\n\
|
|
223
|
+
else if (zmin < 0.0) return vec2(tmax, +INF_HIT);\n\
|
|
224
|
+
else if (zmax < 0.0) return vec2(-INF_HIT, tmin);\n\
|
|
225
|
+
else return vec2(tmin, tmax);\n\
|
|
226
|
+
}\n\
|
|
227
|
+
\n\
|
|
228
|
+
void intersectShape(in Ray ray, inout Intersections ix) {\n\
|
|
229
|
+
// Position is converted from [0,1] to [-1,+1] because shape intersections assume unit space is [-1,+1].\n\
|
|
230
|
+
// Direction is scaled as well to be in sync with position.\n\
|
|
231
|
+
ray.pos = ray.pos * 2.0 - 1.0;\n\
|
|
232
|
+
ray.dir *= 2.0;\n\
|
|
233
|
+
\n\
|
|
234
|
+
// Outer ellipsoid\n\
|
|
235
|
+
vec2 outerIntersect = intersectUnitSphereUnnormalizedDirection(ray);\n\
|
|
236
|
+
setIntersectionPair(ix, ELLIPSOID_INTERSECTION_INDEX_HEIGHT_MAX, outerIntersect);\n\
|
|
237
|
+
\n\
|
|
238
|
+
// Exit early if the outer ellipsoid was missed.\n\
|
|
239
|
+
if (outerIntersect.x == NO_HIT) {\n\
|
|
240
|
+
return;\n\
|
|
241
|
+
}\n\
|
|
242
|
+
\n\
|
|
243
|
+
// Inner ellipsoid\n\
|
|
244
|
+
#if defined(ELLIPSOID_HAS_RENDER_BOUNDS_HEIGHT_FLAT)\n\
|
|
245
|
+
// When the ellipsoid is perfectly thin it's necessary to sandwich the\n\
|
|
246
|
+
// inner ellipsoid intersection inside the outer ellipsoid intersection.\n\
|
|
247
|
+
\n\
|
|
248
|
+
// Without this special case,\n\
|
|
249
|
+
// [outerMin, outerMax, innerMin, innerMax] will bubble sort to\n\
|
|
250
|
+
// [outerMin, innerMin, outerMax, innerMax] which will cause the back\n\
|
|
251
|
+
// side of the ellipsoid to be invisible because it will think the ray\n\
|
|
252
|
+
// is still inside the inner (negative) ellipsoid after exiting the\n\
|
|
253
|
+
// outer (positive) ellipsoid.\n\
|
|
254
|
+
\n\
|
|
255
|
+
// With this special case,\n\
|
|
256
|
+
// [outerMin, innerMin, innerMax, outerMax] will bubble sort to\n\
|
|
257
|
+
// [outerMin, innerMin, innerMax, outerMax] which will work correctly.\n\
|
|
258
|
+
\n\
|
|
259
|
+
// Note: If initializeIntersections() changes its sorting function\n\
|
|
260
|
+
// from bubble sort to something else, this code may need to change.\n\
|
|
261
|
+
setIntersection(ix, 0, outerIntersect.x, true, true); // positive, enter\n\
|
|
262
|
+
setIntersection(ix, 1, outerIntersect.x, false, true); // negative, enter\n\
|
|
263
|
+
setIntersection(ix, 2, outerIntersect.y, false, false); // negative, exit\n\
|
|
264
|
+
setIntersection(ix, 3, outerIntersect.y, true, false); // positive, exit\n\
|
|
265
|
+
#elif defined(ELLIPSOID_HAS_RENDER_BOUNDS_HEIGHT_MIN)\n\
|
|
266
|
+
Ray innerRay = Ray(ray.pos * u_ellipsoidInverseInnerScaleUv, ray.dir * u_ellipsoidInverseInnerScaleUv);\n\
|
|
267
|
+
vec2 innerIntersect = intersectUnitSphereUnnormalizedDirection(innerRay);\n\
|
|
268
|
+
\n\
|
|
269
|
+
if (innerIntersect == vec2(NO_HIT)) {\n\
|
|
270
|
+
setIntersectionPair(ix, ELLIPSOID_INTERSECTION_INDEX_HEIGHT_MIN, innerIntersect);\n\
|
|
271
|
+
} else {\n\
|
|
272
|
+
// When the ellipsoid is very large and thin it's possible for floating\n\
|
|
273
|
+
// point math to cause the ray to intersect the inner ellipsoid before\n\
|
|
274
|
+
// the outer ellipsoid. To prevent this from happening, clamp innerIntersect\n\
|
|
275
|
+
// to outerIntersect and sandwhich the intersections like described above.\n\
|
|
276
|
+
//\n\
|
|
277
|
+
// In theory a similar fix is needed for cylinders, however it's more\n\
|
|
278
|
+
// complicated to implement because the inner shape is allowed to be\n\
|
|
279
|
+
// intersected first.\n\
|
|
280
|
+
innerIntersect.x = max(innerIntersect.x, outerIntersect.x);\n\
|
|
281
|
+
innerIntersect.y = min(innerIntersect.y, outerIntersect.y);\n\
|
|
282
|
+
setIntersection(ix, 0, outerIntersect.x, true, true); // positive, enter\n\
|
|
283
|
+
setIntersection(ix, 1, innerIntersect.x, false, true); // negative, enter\n\
|
|
284
|
+
setIntersection(ix, 2, innerIntersect.y, false, false); // negative, exit\n\
|
|
285
|
+
setIntersection(ix, 3, outerIntersect.y, true, false); // positive, exit\n\
|
|
286
|
+
}\n\
|
|
287
|
+
#endif\n\
|
|
288
|
+
\n\
|
|
289
|
+
// Flip the ray because the intersection function expects a cone growing towards +Z.\n\
|
|
290
|
+
#if defined(ELLIPSOID_HAS_RENDER_BOUNDS_LATITUDE_MIN_UNDER_HALF) || defined(ELLIPSOID_HAS_RENDER_BOUNDS_LATITUDE_MIN_EQUAL_HALF) || defined(ELLIPSOID_HAS_RENDER_BOUNDS_LATITUDE_MAX_UNDER_HALF)\n\
|
|
291
|
+
Ray flippedRay = ray;\n\
|
|
292
|
+
flippedRay.dir.z *= -1.0;\n\
|
|
293
|
+
flippedRay.pos.z *= -1.0;\n\
|
|
294
|
+
#endif\n\
|
|
295
|
+
\n\
|
|
296
|
+
// Bottom cone\n\
|
|
297
|
+
#if defined(ELLIPSOID_HAS_RENDER_BOUNDS_LATITUDE_MIN_UNDER_HALF)\n\
|
|
298
|
+
vec2 bottomConeIntersection = intersectRegularCone(flippedRay, u_ellipsoidRenderLatitudeCosSqrHalfMinMax.x);\n\
|
|
299
|
+
setIntersectionPair(ix, ELLIPSOID_INTERSECTION_INDEX_LATITUDE_MIN, bottomConeIntersection);\n\
|
|
300
|
+
#elif defined(ELLIPSOID_HAS_RENDER_BOUNDS_LATITUDE_MIN_EQUAL_HALF)\n\
|
|
301
|
+
vec2 bottomConeIntersection = intersectZPlane(flippedRay);\n\
|
|
302
|
+
setIntersectionPair(ix, ELLIPSOID_INTERSECTION_INDEX_LATITUDE_MIN, bottomConeIntersection);\n\
|
|
303
|
+
#elif defined(ELLIPSOID_HAS_RENDER_BOUNDS_LATITUDE_MIN_OVER_HALF)\n\
|
|
304
|
+
vec4 bottomConeIntersection = intersectFlippedCone(ray, u_ellipsoidRenderLatitudeCosSqrHalfMinMax.x);\n\
|
|
305
|
+
setIntersectionPair(ix, ELLIPSOID_INTERSECTION_INDEX_LATITUDE_MIN + 0, bottomConeIntersection.xy);\n\
|
|
306
|
+
setIntersectionPair(ix, ELLIPSOID_INTERSECTION_INDEX_LATITUDE_MIN + 1, bottomConeIntersection.zw);\n\
|
|
307
|
+
#endif\n\
|
|
308
|
+
\n\
|
|
309
|
+
// Top cone\n\
|
|
310
|
+
#if defined(ELLIPSOID_HAS_RENDER_BOUNDS_LATITUDE_MAX_UNDER_HALF)\n\
|
|
311
|
+
vec4 topConeIntersection = intersectFlippedCone(flippedRay, u_ellipsoidRenderLatitudeCosSqrHalfMinMax.y);\n\
|
|
312
|
+
setIntersectionPair(ix, ELLIPSOID_INTERSECTION_INDEX_LATITUDE_MAX + 0, topConeIntersection.xy);\n\
|
|
313
|
+
setIntersectionPair(ix, ELLIPSOID_INTERSECTION_INDEX_LATITUDE_MAX + 1, topConeIntersection.zw);\n\
|
|
314
|
+
#elif defined(ELLIPSOID_HAS_RENDER_BOUNDS_LATITUDE_MAX_EQUAL_HALF)\n\
|
|
315
|
+
vec2 topConeIntersection = intersectZPlane(ray);\n\
|
|
316
|
+
setIntersectionPair(ix, ELLIPSOID_INTERSECTION_INDEX_LATITUDE_MAX, topConeIntersection);\n\
|
|
317
|
+
#elif defined(ELLIPSOID_HAS_RENDER_BOUNDS_LATITUDE_MAX_OVER_HALF)\n\
|
|
318
|
+
vec2 topConeIntersection = intersectRegularCone(ray, u_ellipsoidRenderLatitudeCosSqrHalfMinMax.y);\n\
|
|
319
|
+
setIntersectionPair(ix, ELLIPSOID_INTERSECTION_INDEX_LATITUDE_MAX, topConeIntersection);\n\
|
|
320
|
+
#endif\n\
|
|
321
|
+
\n\
|
|
322
|
+
// Wedge\n\
|
|
323
|
+
#if defined(ELLIPSOID_HAS_RENDER_BOUNDS_LONGITUDE_RANGE_EQUAL_ZERO)\n\
|
|
324
|
+
vec4 wedgeIntersect = intersectHalfPlane(ray, u_ellipsoidRenderLongitudeMinMax.x);\n\
|
|
325
|
+
setIntersectionPair(ix, ELLIPSOID_INTERSECTION_INDEX_LONGITUDE + 0, wedgeIntersect.xy);\n\
|
|
326
|
+
setIntersectionPair(ix, ELLIPSOID_INTERSECTION_INDEX_LONGITUDE + 1, wedgeIntersect.zw);\n\
|
|
327
|
+
#elif defined(ELLIPSOID_HAS_RENDER_BOUNDS_LONGITUDE_RANGE_UNDER_HALF)\n\
|
|
328
|
+
vec2 wedgeIntersect = intersectRegularWedge(ray, u_ellipsoidRenderLongitudeMinMax.x, u_ellipsoidRenderLongitudeMinMax.y);\n\
|
|
329
|
+
setIntersectionPair(ix, ELLIPSOID_INTERSECTION_INDEX_LONGITUDE, wedgeIntersect);\n\
|
|
330
|
+
#elif defined(ELLIPSOID_HAS_RENDER_BOUNDS_LONGITUDE_RANGE_EQUAL_HALF)\n\
|
|
331
|
+
vec2 wedgeIntersect = intersectHalfSpace(ray, u_ellipsoidRenderLongitudeMinMax.x);\n\
|
|
332
|
+
setIntersectionPair(ix, ELLIPSOID_INTERSECTION_INDEX_LONGITUDE, wedgeIntersect);\n\
|
|
333
|
+
#elif defined(ELLIPSOID_HAS_RENDER_BOUNDS_LONGITUDE_RANGE_OVER_HALF)\n\
|
|
334
|
+
vec4 wedgeIntersect = intersectFlippedWedge(ray, u_ellipsoidRenderLongitudeMinMax.x, u_ellipsoidRenderLongitudeMinMax.y);\n\
|
|
335
|
+
setIntersectionPair(ix, ELLIPSOID_INTERSECTION_INDEX_LONGITUDE + 0, wedgeIntersect.xy);\n\
|
|
336
|
+
setIntersectionPair(ix, ELLIPSOID_INTERSECTION_INDEX_LONGITUDE + 1, wedgeIntersect.zw);\n\
|
|
337
|
+
#endif\n\
|
|
338
|
+
}\n\
|
|
339
|
+
";
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
// Main intersection function for Voxel scenes.
|
|
2
|
+
// See IntersectBox.glsl, IntersectCylinder.glsl, or IntersectEllipsoid.glsl
|
|
3
|
+
// for the definition of intersectShape. The appropriate function is selected
|
|
4
|
+
// based on the VoxelPrimitive shape type, and added to the shader in
|
|
5
|
+
// Scene/VoxelRenderResources.js.
|
|
6
|
+
// See also IntersectClippingPlane.glsl and IntersectDepth.glsl.
|
|
7
|
+
// See IntersectionUtils.glsl for the definitions of Ray, NO_HIT,
|
|
8
|
+
// getIntersectionPair, initializeIntersections, nextIntersection.
|
|
9
|
+
|
|
10
|
+
/* Intersection defines (set in Scene/VoxelRenderResources.js)
|
|
11
|
+
#define INTERSECTION_COUNT ###
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
vec2 intersectScene(vec2 screenCoord, vec3 positionUv, vec3 directionUv, out Intersections ix) {
|
|
15
|
+
Ray ray = Ray(positionUv, directionUv);
|
|
16
|
+
|
|
17
|
+
// Do a ray-shape intersection to find the exact starting and ending points.
|
|
18
|
+
intersectShape(ray, ix);
|
|
19
|
+
|
|
20
|
+
// Exit early if the positive shape was completely missed or behind the ray.
|
|
21
|
+
vec2 entryExitT = getIntersectionPair(ix, 0);
|
|
22
|
+
if (entryExitT.x == NO_HIT) {
|
|
23
|
+
// Positive shape was completely missed - so exit early.
|
|
24
|
+
return vec2(NO_HIT);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// Clipping planes
|
|
28
|
+
#if defined(CLIPPING_PLANES)
|
|
29
|
+
intersectClippingPlanes(ray, ix);
|
|
30
|
+
#endif
|
|
31
|
+
|
|
32
|
+
// Depth
|
|
33
|
+
#if defined(DEPTH_TEST)
|
|
34
|
+
intersectDepth(screenCoord, ray, ix);
|
|
35
|
+
#endif
|
|
36
|
+
|
|
37
|
+
// Find the first intersection that's in front of the ray
|
|
38
|
+
#if (INTERSECTION_COUNT > 1)
|
|
39
|
+
initializeIntersections(ix);
|
|
40
|
+
for (int i = 0; i < INTERSECTION_COUNT; ++i) {
|
|
41
|
+
entryExitT = nextIntersection(ix);
|
|
42
|
+
if (entryExitT.y > 0.0) {
|
|
43
|
+
// Set start to 0.0 when ray is inside the shape.
|
|
44
|
+
entryExitT.x = max(entryExitT.x, 0.0);
|
|
45
|
+
break;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
#else
|
|
49
|
+
// Set start to 0.0 when ray is inside the shape.
|
|
50
|
+
entryExitT.x = max(entryExitT.x, 0.0);
|
|
51
|
+
#endif
|
|
52
|
+
|
|
53
|
+
return entryExitT;
|
|
54
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
//This file is automatically rebuilt by the Cesium build process.
|
|
2
|
+
export default "// Main intersection function for Voxel scenes.\n\
|
|
3
|
+
// See IntersectBox.glsl, IntersectCylinder.glsl, or IntersectEllipsoid.glsl\n\
|
|
4
|
+
// for the definition of intersectShape. The appropriate function is selected\n\
|
|
5
|
+
// based on the VoxelPrimitive shape type, and added to the shader in\n\
|
|
6
|
+
// Scene/VoxelRenderResources.js.\n\
|
|
7
|
+
// See also IntersectClippingPlane.glsl and IntersectDepth.glsl.\n\
|
|
8
|
+
// See IntersectionUtils.glsl for the definitions of Ray, NO_HIT,\n\
|
|
9
|
+
// getIntersectionPair, initializeIntersections, nextIntersection.\n\
|
|
10
|
+
\n\
|
|
11
|
+
/* Intersection defines (set in Scene/VoxelRenderResources.js)\n\
|
|
12
|
+
#define INTERSECTION_COUNT ###\n\
|
|
13
|
+
*/\n\
|
|
14
|
+
\n\
|
|
15
|
+
vec2 intersectScene(vec2 screenCoord, vec3 positionUv, vec3 directionUv, out Intersections ix) {\n\
|
|
16
|
+
Ray ray = Ray(positionUv, directionUv);\n\
|
|
17
|
+
\n\
|
|
18
|
+
// Do a ray-shape intersection to find the exact starting and ending points.\n\
|
|
19
|
+
intersectShape(ray, ix);\n\
|
|
20
|
+
\n\
|
|
21
|
+
// Exit early if the positive shape was completely missed or behind the ray.\n\
|
|
22
|
+
vec2 entryExitT = getIntersectionPair(ix, 0);\n\
|
|
23
|
+
if (entryExitT.x == NO_HIT) {\n\
|
|
24
|
+
// Positive shape was completely missed - so exit early.\n\
|
|
25
|
+
return vec2(NO_HIT);\n\
|
|
26
|
+
}\n\
|
|
27
|
+
\n\
|
|
28
|
+
// Clipping planes\n\
|
|
29
|
+
#if defined(CLIPPING_PLANES)\n\
|
|
30
|
+
intersectClippingPlanes(ray, ix);\n\
|
|
31
|
+
#endif\n\
|
|
32
|
+
\n\
|
|
33
|
+
// Depth\n\
|
|
34
|
+
#if defined(DEPTH_TEST)\n\
|
|
35
|
+
intersectDepth(screenCoord, ray, ix);\n\
|
|
36
|
+
#endif\n\
|
|
37
|
+
\n\
|
|
38
|
+
// Find the first intersection that's in front of the ray\n\
|
|
39
|
+
#if (INTERSECTION_COUNT > 1)\n\
|
|
40
|
+
initializeIntersections(ix);\n\
|
|
41
|
+
for (int i = 0; i < INTERSECTION_COUNT; ++i) {\n\
|
|
42
|
+
entryExitT = nextIntersection(ix);\n\
|
|
43
|
+
if (entryExitT.y > 0.0) {\n\
|
|
44
|
+
// Set start to 0.0 when ray is inside the shape.\n\
|
|
45
|
+
entryExitT.x = max(entryExitT.x, 0.0);\n\
|
|
46
|
+
break;\n\
|
|
47
|
+
}\n\
|
|
48
|
+
}\n\
|
|
49
|
+
#else\n\
|
|
50
|
+
// Set start to 0.0 when ray is inside the shape.\n\
|
|
51
|
+
entryExitT.x = max(entryExitT.x, 0.0);\n\
|
|
52
|
+
#endif\n\
|
|
53
|
+
\n\
|
|
54
|
+
return entryExitT;\n\
|
|
55
|
+
}\n\
|
|
56
|
+
";
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
/* Intersection defines
|
|
2
|
+
#define INTERSECTION_COUNT ###
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
#define NO_HIT (-czm_infinity)
|
|
6
|
+
#define INF_HIT (czm_infinity * 0.5)
|
|
7
|
+
|
|
8
|
+
struct Ray {
|
|
9
|
+
vec3 pos;
|
|
10
|
+
vec3 dir;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
struct Intersections {
|
|
14
|
+
// Don't access these member variables directly - call the functions instead.
|
|
15
|
+
|
|
16
|
+
#if (INTERSECTION_COUNT > 1)
|
|
17
|
+
// Store an array of intersections. Each intersection is composed of:
|
|
18
|
+
// x for the T value
|
|
19
|
+
// y for the shape type - which encodes positive vs negative and entering vs exiting
|
|
20
|
+
// For example:
|
|
21
|
+
// y = 0: positive shape entry
|
|
22
|
+
// y = 1: positive shape exit
|
|
23
|
+
// y = 2: negative shape entry
|
|
24
|
+
// y = 3: negative shape exit
|
|
25
|
+
vec2 intersections[INTERSECTION_COUNT * 2];
|
|
26
|
+
|
|
27
|
+
// Maintain state for future nextIntersection calls
|
|
28
|
+
int index;
|
|
29
|
+
int surroundCount;
|
|
30
|
+
bool surroundIsPositive;
|
|
31
|
+
#else
|
|
32
|
+
// When there's only one positive shape intersection none of the extra stuff is needed.
|
|
33
|
+
float intersections[2];
|
|
34
|
+
#endif
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
// Using a define instead of a real function because WebGL1 cannot access array with non-constant index.
|
|
38
|
+
#if (INTERSECTION_COUNT > 1)
|
|
39
|
+
#define getIntersection(/*inout Intersections*/ ix, /*int*/ index) (ix).intersections[(index)].x
|
|
40
|
+
#else
|
|
41
|
+
#define getIntersection(/*inout Intersections*/ ix, /*int*/ index) (ix).intersections[(index)]
|
|
42
|
+
#endif
|
|
43
|
+
|
|
44
|
+
// Using a define instead of a real function because WebGL1 cannot access array with non-constant index.
|
|
45
|
+
#define getIntersectionPair(/*inout Intersections*/ ix, /*int*/ index) vec2(getIntersection((ix), (index) * 2 + 0), getIntersection((ix), (index) * 2 + 1))
|
|
46
|
+
|
|
47
|
+
// Using a define instead of a real function because WebGL1 cannot access array with non-constant index.
|
|
48
|
+
#if (INTERSECTION_COUNT > 1)
|
|
49
|
+
#define setIntersection(/*inout Intersections*/ ix, /*int*/ index, /*float*/ t, /*bool*/ positive, /*enter*/ enter) (ix).intersections[(index)] = vec2((t), float(!positive) * 2.0 + float(!enter))
|
|
50
|
+
#else
|
|
51
|
+
#define setIntersection(/*inout Intersections*/ ix, /*int*/ index, /*float*/ t, /*bool*/ positive, /*enter*/ enter) (ix).intersections[(index)] = (t)
|
|
52
|
+
#endif
|
|
53
|
+
|
|
54
|
+
// Using a define instead of a real function because WebGL1 cannot access array with non-constant index.
|
|
55
|
+
#if (INTERSECTION_COUNT > 1)
|
|
56
|
+
#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)
|
|
57
|
+
#else
|
|
58
|
+
#define setIntersectionPair(/*inout Intersections*/ ix, /*int*/ index, /*vec2*/ entryExit) (ix).intersections[(index) * 2 + 0] = (entryExit).x; (ix).intersections[(index) * 2 + 1] = (entryExit).y
|
|
59
|
+
#endif
|
|
60
|
+
|
|
61
|
+
#if (INTERSECTION_COUNT > 1)
|
|
62
|
+
void initializeIntersections(inout Intersections ix) {
|
|
63
|
+
// Sort the intersections from min T to max T with bubble sort.
|
|
64
|
+
// Note: If this sorting function changes, some of the intersection test may
|
|
65
|
+
// need to be updated. Search for "bubble sort" to find those areas.
|
|
66
|
+
const int sortPasses = INTERSECTION_COUNT * 2 - 1;
|
|
67
|
+
for (int n = sortPasses; n > 0; --n) {
|
|
68
|
+
for (int i = 0; i < sortPasses; ++i) {
|
|
69
|
+
// The loop should be: for (i = 0; i < n; ++i) {...} but WebGL1 cannot
|
|
70
|
+
// loop with non-constant condition, so it has to break early instead
|
|
71
|
+
if (i >= n) { break; }
|
|
72
|
+
|
|
73
|
+
vec2 intersect0 = ix.intersections[i + 0];
|
|
74
|
+
vec2 intersect1 = ix.intersections[i + 1];
|
|
75
|
+
|
|
76
|
+
float t0 = intersect0.x;
|
|
77
|
+
float t1 = intersect1.x;
|
|
78
|
+
float b0 = intersect0.y;
|
|
79
|
+
float b1 = intersect1.y;
|
|
80
|
+
|
|
81
|
+
float tmin = min(t0, t1);
|
|
82
|
+
float tmax = max(t0, t1);
|
|
83
|
+
float bmin = tmin == t0 ? b0 : b1;
|
|
84
|
+
float bmax = tmin == t0 ? b1 : b0;
|
|
85
|
+
|
|
86
|
+
ix.intersections[i + 0] = vec2(tmin, bmin);
|
|
87
|
+
ix.intersections[i + 1] = vec2(tmax, bmax);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// Prepare initial state for nextIntersection
|
|
92
|
+
ix.index = 0;
|
|
93
|
+
ix.surroundCount = 0;
|
|
94
|
+
ix.surroundIsPositive = false;
|
|
95
|
+
}
|
|
96
|
+
#endif
|
|
97
|
+
|
|
98
|
+
#if (INTERSECTION_COUNT > 1)
|
|
99
|
+
vec2 nextIntersection(inout Intersections ix) {
|
|
100
|
+
vec2 entryExitT = vec2(NO_HIT);
|
|
101
|
+
|
|
102
|
+
const int passCount = INTERSECTION_COUNT * 2;
|
|
103
|
+
|
|
104
|
+
if (ix.index == passCount) {
|
|
105
|
+
return entryExitT;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
for (int i = 0; i < passCount; ++i) {
|
|
109
|
+
// The loop should be: for (i = ix.index; i < passCount; ++i) {...} but WebGL1 cannot
|
|
110
|
+
// loop with non-constant condition, so it has to continue instead.
|
|
111
|
+
if (i < ix.index) {
|
|
112
|
+
continue;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
ix.index = i + 1;
|
|
116
|
+
|
|
117
|
+
vec2 intersect = ix.intersections[i];
|
|
118
|
+
float t = intersect.x;
|
|
119
|
+
bool currShapeIsPositive = intersect.y < 2.0;
|
|
120
|
+
bool enter = mod(intersect.y, 2.0) == 0.0;
|
|
121
|
+
|
|
122
|
+
ix.surroundCount += enter ? +1 : -1;
|
|
123
|
+
ix.surroundIsPositive = currShapeIsPositive ? enter : ix.surroundIsPositive;
|
|
124
|
+
|
|
125
|
+
// entering positive or exiting negative
|
|
126
|
+
if (ix.surroundCount == 1 && ix.surroundIsPositive && enter == currShapeIsPositive) {
|
|
127
|
+
entryExitT.x = t;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// exiting positive or entering negative after being inside positive
|
|
131
|
+
// TODO: Can this be simplified?
|
|
132
|
+
bool exitPositive = !enter && currShapeIsPositive && ix.surroundCount == 0;
|
|
133
|
+
bool enterNegativeFromPositive = enter && !currShapeIsPositive && ix.surroundCount == 2 && ix.surroundIsPositive;
|
|
134
|
+
if (exitPositive || enterNegativeFromPositive) {
|
|
135
|
+
entryExitT.y = t;
|
|
136
|
+
|
|
137
|
+
// entry and exit have been found, so the loop can stop
|
|
138
|
+
if (exitPositive) {
|
|
139
|
+
// After exiting positive shape there is nothing left to intersect, so jump to the end index.
|
|
140
|
+
ix.index = passCount;
|
|
141
|
+
}
|
|
142
|
+
break;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
return entryExitT;
|
|
147
|
+
}
|
|
148
|
+
#endif
|
|
149
|
+
|
|
150
|
+
// NOTE: initializeIntersections, nextIntersection aren't even declared unless INTERSECTION_COUNT > 1
|
|
151
|
+
// export { NO_HIT, INF_HIT, Ray, Intersections, getIntersectionPair, setIntersectionPair, initializeIntersections, nextIntersection };
|