@cesium/engine 8.0.0 → 9.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Build/ThirdParty/Workers/z-worker-pako.js +7 -10
- package/Build/Workers/{chunk-F4HFJMGM.js → chunk-2CSEEWHN.js} +6 -6
- package/Build/Workers/{chunk-7TC63SJW.js → chunk-34DGOKCO.js} +10 -12
- package/Build/Workers/{chunk-7ZFGPDJA.js → chunk-3RZK5NNV.js} +4 -4
- package/Build/Workers/{chunk-M7ERACJJ.js → chunk-3S2MFY4B.js} +13 -13
- package/Build/Workers/{chunk-BROJAZRZ.js → chunk-4AJGCQFX.js} +13 -13
- package/Build/Workers/{chunk-2FWRMUTY.js → chunk-4KIUON73.js} +4 -4
- package/Build/Workers/{chunk-5QULIR53.js → chunk-4PHPQRSH.js} +4 -4
- package/Build/Workers/{chunk-X4356LRH.js → chunk-66E3H2KU.js} +12 -12
- package/Build/Workers/{chunk-G43QFN4Q.js → chunk-6HCAQOVK.js} +6 -6
- package/Build/Workers/{chunk-23UFSGND.js → chunk-7LPEGKOF.js} +7 -7
- package/Build/Workers/{chunk-DDUQAJ4P.js → chunk-7VZNXIKG.js} +7 -7
- package/Build/Workers/{chunk-JURN7NPV.js → chunk-A6NCZSL3.js} +19 -19
- package/Build/Workers/{chunk-ZT7KWISZ.js → chunk-AOFMPKUB.js} +4 -4
- package/Build/Workers/{chunk-BIKA3NRA.js → chunk-AOIKO5Y7.js} +5 -5
- package/Build/Workers/{chunk-YWTJ2B4B.js → chunk-BDUJXBVF.js} +1 -1
- package/Build/Workers/{chunk-OGXZVPPM.js → chunk-C5CE4OG6.js} +469 -6
- package/Build/Workers/{chunk-FNIRWHJB.js → chunk-CE6GTZ4I.js} +11 -13
- package/Build/Workers/{chunk-SH5USDPI.js → chunk-CYAJYEKW.js} +6 -6
- package/Build/Workers/{chunk-Y5UQJLYE.js → chunk-FOZQIHZK.js} +6 -6
- package/Build/Workers/{chunk-2FRVPMCS.js → chunk-G7CJQKKD.js} +7 -7
- package/Build/Workers/{chunk-EERJKOAF.js → chunk-GIFJ77E4.js} +4 -4
- package/Build/Workers/{chunk-FJKNFAKQ.js → chunk-I5TDPPC4.js} +7197 -5096
- package/Build/Workers/{chunk-3VAZEH7M.js → chunk-IBXGK4WV.js} +2 -2
- package/Build/Workers/{chunk-VOXYEYJT.js → chunk-JI2445T5.js} +11 -11
- package/Build/Workers/{chunk-PGSJK77E.js → chunk-KPY4F4BW.js} +6 -6
- package/Build/Workers/{chunk-I46ZRR5W.js → chunk-LVJCR7DH.js} +17 -17
- package/Build/Workers/{chunk-T3XIFPYR.js → chunk-LW7WGHEU.js} +16 -16
- package/Build/Workers/{chunk-HU6N6EXB.js → chunk-MWYZ64MH.js} +12 -11
- package/Build/Workers/chunk-NI2R52QD.js +961 -0
- package/Build/Workers/{chunk-SOWMRMWA.js → chunk-PEABJLCK.js} +1 -1
- package/Build/Workers/{chunk-EG6PTBY2.js → chunk-PK7TEP3J.js} +15 -15
- package/Build/Workers/{chunk-GRC2ZTAF.js → chunk-POLFRINT.js} +14 -14
- package/Build/Workers/{chunk-Z3TIFFGF.js → chunk-PS6AEMBR.js} +7 -7
- package/Build/Workers/{chunk-Y2ME2IJV.js → chunk-PWF3YJJ5.js} +13 -13
- package/Build/Workers/{chunk-2A75IWRS.js → chunk-QKF7XXEQ.js} +7 -7
- package/Build/Workers/{chunk-4H7PY4U5.js → chunk-RL73GOEF.js} +2 -2
- package/Build/Workers/{chunk-MDWEGWPA.js → chunk-RR7EOKGZ.js} +10 -10
- package/Build/Workers/{chunk-F3YA3Y2Z.js → chunk-S4XDCPKD.js} +1 -1
- package/Build/Workers/{chunk-PPH7OFP3.js → chunk-TMMOULW3.js} +5 -5
- package/Build/Workers/{chunk-XGI5BXZY.js → chunk-U4IMCOF5.js} +2 -2
- package/Build/Workers/{chunk-4DO5W5XZ.js → chunk-UAJEGIWA.js} +6 -6
- package/Build/Workers/{chunk-BBWDMCVU.js → chunk-UCPPWV64.js} +1 -1
- package/Build/Workers/{chunk-FZRIVR7Y.js → chunk-V7JB576Q.js} +5 -5
- package/Build/Workers/{chunk-2UPKWTMJ.js → chunk-WEGCQ5DY.js} +6 -6
- package/Build/Workers/{chunk-STW2DGFI.js → chunk-WFICTTOE.js} +2 -2
- package/Build/Workers/{chunk-LPR3YNP2.js → chunk-WWP3I7R5.js} +5 -5
- package/Build/Workers/{chunk-A5DWLWCY.js → chunk-XHLDDE65.js} +10 -10
- package/Build/Workers/{chunk-UEXTBDBE.js → chunk-XWML5Y7N.js} +11 -13
- package/Build/Workers/{chunk-EHWHNOEX.js → chunk-YLZTCEBJ.js} +1 -1
- package/Build/Workers/{chunk-34FXV7D7.js → chunk-ZC4AGBZK.js} +2 -2
- package/Build/Workers/{chunk-GATZHF3K.js → chunk-ZDP32RQI.js} +2 -2
- package/Build/Workers/{chunk-KKCR2YOP.js → chunk-ZWPIM77Q.js} +11 -11
- package/Build/Workers/combineGeometry.js +22 -24
- package/Build/Workers/createBoxGeometry.js +16 -18
- package/Build/Workers/createBoxOutlineGeometry.js +14 -16
- package/Build/Workers/createCircleGeometry.js +24 -26
- package/Build/Workers/createCircleOutlineGeometry.js +17 -19
- package/Build/Workers/createCoplanarPolygonGeometry.js +33 -34
- package/Build/Workers/createCoplanarPolygonOutlineGeometry.js +29 -31
- package/Build/Workers/createCorridorGeometry.js +27 -29
- package/Build/Workers/createCorridorOutlineGeometry.js +26 -28
- package/Build/Workers/createCylinderGeometry.js +18 -20
- package/Build/Workers/createCylinderOutlineGeometry.js +16 -18
- package/Build/Workers/createEllipseGeometry.js +24 -26
- package/Build/Workers/createEllipseOutlineGeometry.js +17 -19
- package/Build/Workers/createEllipsoidGeometry.js +17 -19
- package/Build/Workers/createEllipsoidOutlineGeometry.js +16 -18
- package/Build/Workers/createFrustumGeometry.js +16 -18
- package/Build/Workers/createFrustumOutlineGeometry.js +18 -19
- package/Build/Workers/createGeometry.js +23 -25
- package/Build/Workers/createGroundPolylineGeometry.js +23 -25
- package/Build/Workers/createPlaneGeometry.js +14 -16
- package/Build/Workers/createPlaneOutlineGeometry.js +13 -15
- package/Build/Workers/createPolygonGeometry.js +33 -35
- package/Build/Workers/createPolygonOutlineGeometry.js +28 -30
- package/Build/Workers/createPolylineGeometry.js +23 -25
- package/Build/Workers/createPolylineVolumeGeometry.js +29 -31
- package/Build/Workers/createPolylineVolumeOutlineGeometry.js +25 -27
- package/Build/Workers/createRectangleGeometry.js +27 -29
- package/Build/Workers/createRectangleOutlineGeometry.js +18 -20
- package/Build/Workers/createSimplePolylineGeometry.js +21 -23
- package/Build/Workers/createSphereGeometry.js +17 -19
- package/Build/Workers/createSphereOutlineGeometry.js +16 -18
- package/Build/Workers/createTaskProcessorWorker.js +3 -3
- package/Build/Workers/createVectorTileClampedPolylines.js +14 -16
- package/Build/Workers/createVectorTileGeometries.js +22 -24
- package/Build/Workers/createVectorTilePoints.js +12 -12
- package/Build/Workers/createVectorTilePolygons.js +20 -22
- package/Build/Workers/createVectorTilePolylines.js +14 -16
- package/Build/Workers/createVerticesFromGoogleEarthEnterpriseBuffer.js +23 -25
- package/Build/Workers/createVerticesFromHeightmap.js +23 -25
- package/Build/Workers/createVerticesFromQuantizedTerrainMesh.js +19 -22
- package/Build/Workers/createWallGeometry.js +22 -24
- package/Build/Workers/createWallOutlineGeometry.js +21 -23
- package/Build/Workers/decodeDraco.js +11 -11
- package/Build/Workers/decodeGoogleEarthEnterprisePacket.js +5 -5
- package/Build/Workers/decodeI3S.js +10 -11
- package/Build/Workers/transcodeKTX2.js +8 -8
- package/Build/Workers/transferTypedArrayTest.js +1 -1
- package/Build/Workers/upsampleQuantizedTerrainMesh.js +20 -22
- package/Source/Core/Check.d.ts +127 -0
- package/Source/Core/Check.js +0 -1
- package/Source/Core/Geometry.js +1 -1
- package/Source/Core/Ion.js +1 -1
- package/Source/Core/PixelFormat.js +1 -0
- package/Source/Core/PolygonGeometry.js +1 -1
- package/Source/Core/Rectangle.js +89 -0
- package/Source/Core/VerticalExaggeration.js +2 -1
- package/Source/DataSources/DataSourceDisplay.js +5 -0
- package/Source/Renderer/ShaderBuilder.js +6 -3
- package/Source/Scene/ArcGisMapService.js +1 -1
- package/Source/Scene/Billboard.js +37 -3
- package/Source/Scene/BillboardCollection.js +1 -1
- package/Source/Scene/BingMapsImageryProvider.js +4 -0
- package/Source/Scene/Cesium3DTile.js +65 -0
- package/Source/Scene/Cesium3DTilesVoxelProvider.js +2 -9
- package/Source/Scene/Cesium3DTileset.js +52 -40
- package/Source/Scene/ClippingPolygon.js +212 -0
- package/Source/Scene/ClippingPolygonCollection.js +968 -0
- package/Source/Scene/Globe.js +14 -67
- package/Source/Scene/GlobeSurfaceShaderSet.js +81 -15
- package/Source/Scene/GlobeSurfaceTileProvider.js +81 -1
- package/Source/Scene/Label.js +33 -0
- package/Source/Scene/LabelCollection.js +2 -1
- package/Source/Scene/Model/Model.js +83 -0
- package/Source/Scene/Model/Model3DTileContent.js +21 -0
- package/Source/Scene/Model/ModelClippingPolygonsPipelineStage.js +92 -0
- package/Source/Scene/Model/ModelSceneGraph.js +5 -0
- package/Source/Scene/Primitive.js +0 -3
- package/Source/Scene/SensorVolumePortionToDisplay.js +1 -1
- package/Source/Scene/Terrain.js +2 -2
- package/Source/Scene/VoxelBoxShape.js +0 -15
- package/Source/Scene/VoxelCylinderShape.js +14 -131
- package/Source/Scene/VoxelEllipsoidShape.js +136 -227
- package/Source/Scene/VoxelPrimitive.js +106 -14
- package/Source/Scene/VoxelRenderResources.js +9 -3
- package/Source/Scene/VoxelShape.js +0 -10
- package/Source/Scene/processVoxelProperties.js +1 -0
- package/Source/Shaders/Builtin/CzmBuiltins.js +4 -0
- package/Source/Shaders/Builtin/Functions/clipPolygons.glsl +37 -0
- package/Source/Shaders/Builtin/Functions/clipPolygons.js +39 -0
- package/Source/Shaders/Builtin/Functions/unpackClippingExtents.glsl +14 -0
- package/Source/Shaders/Builtin/Functions/unpackClippingExtents.js +15 -0
- package/Source/Shaders/GlobeFS.glsl +12 -0
- package/Source/Shaders/GlobeFS.js +12 -0
- package/Source/Shaders/GlobeVS.glsl +32 -0
- package/Source/Shaders/GlobeVS.js +32 -0
- package/Source/Shaders/Model/GeometryStageVS.glsl +1 -1
- package/Source/Shaders/Model/GeometryStageVS.js +1 -1
- package/Source/Shaders/Model/ModelClippingPolygonsStageFS.glsl +6 -0
- package/Source/Shaders/Model/ModelClippingPolygonsStageFS.js +8 -0
- package/Source/Shaders/Model/ModelClippingPolygonsStageVS.glsl +27 -0
- package/Source/Shaders/Model/ModelClippingPolygonsStageVS.js +29 -0
- package/Source/Shaders/Model/ModelFS.glsl +6 -0
- package/Source/Shaders/Model/ModelFS.js +7 -1
- package/Source/Shaders/Model/ModelVS.glsl +4 -0
- package/Source/Shaders/Model/ModelVS.js +4 -0
- package/Source/Shaders/PolygonSignedDistanceFS.glsl +100 -0
- package/Source/Shaders/PolygonSignedDistanceFS.js +101 -0
- package/Source/Shaders/Voxels/IntersectBox.glsl +21 -47
- package/Source/Shaders/Voxels/IntersectBox.js +21 -47
- package/Source/Shaders/Voxels/IntersectClippingPlanes.glsl +1 -1
- package/Source/Shaders/Voxels/IntersectClippingPlanes.js +1 -1
- package/Source/Shaders/Voxels/IntersectCylinder.glsl +66 -96
- package/Source/Shaders/Voxels/IntersectCylinder.js +66 -96
- package/Source/Shaders/Voxels/IntersectEllipsoid.glsl +226 -154
- package/Source/Shaders/Voxels/IntersectEllipsoid.js +226 -154
- package/Source/Shaders/Voxels/IntersectionUtils.glsl +33 -11
- package/Source/Shaders/Voxels/IntersectionUtils.js +33 -11
- package/Source/Shaders/Voxels/Megatexture.glsl +1 -2
- package/Source/Shaders/Voxels/Megatexture.js +1 -2
- package/Source/Shaders/Voxels/Octree.glsl +14 -9
- package/Source/Shaders/Voxels/Octree.js +14 -9
- package/Source/Shaders/Voxels/VoxelFS.glsl +93 -43
- package/Source/Shaders/Voxels/VoxelFS.js +93 -43
- package/Source/Shaders/Voxels/VoxelUtils.glsl +31 -0
- package/Source/Shaders/Voxels/VoxelUtils.js +33 -0
- package/Source/Shaders/Voxels/convertUvToBox.glsl +24 -3
- package/Source/Shaders/Voxels/convertUvToBox.js +24 -4
- package/Source/Shaders/Voxels/convertUvToCylinder.glsl +50 -8
- package/Source/Shaders/Voxels/convertUvToCylinder.js +50 -8
- package/Source/Shaders/Voxels/convertUvToEllipsoid.glsl +82 -53
- package/Source/Shaders/Voxels/convertUvToEllipsoid.js +82 -53
- package/Source/ThirdParty/Workers/z-worker-pako.js +1 -1
- package/Source/Workers/createGeometry.js +1 -1
- package/index.d.ts +478 -35
- package/index.js +61 -52
- package/package.json +2 -2
- package/Build/Workers/chunk-BG4UCVXN.js +0 -73
- package/Build/Workers/chunk-TTUZP4BO.js +0 -501
- package/Build/Workers/chunk-YJEBABKH.js +0 -2977
|
@@ -1,6 +1,6 @@
|
|
|
1
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
|
-
//
|
|
2
|
+
export default "// See IntersectionUtils.glsl for the definitions of Ray, NO_HIT, INF_HIT, Intersections,\n\
|
|
3
|
+
// RayShapeIntersection, setSurfaceIntersection, setShapeIntersection\n\
|
|
4
4
|
// See IntersectLongitude.glsl for the definitions of intersectHalfPlane,\n\
|
|
5
5
|
// intersectFlippedWedge, intersectRegularWedge\n\
|
|
6
6
|
\n\
|
|
@@ -15,8 +15,6 @@ export default "// See IntersectionUtils.glsl for the definitions of Ray, Inters
|
|
|
15
15
|
#define ELLIPSOID_HAS_RENDER_BOUNDS_LATITUDE_MIN_UNDER_HALF\n\
|
|
16
16
|
#define ELLIPSOID_HAS_RENDER_BOUNDS_LATITUDE_MIN_EQUAL_HALF\n\
|
|
17
17
|
#define ELLIPSOID_HAS_RENDER_BOUNDS_LATITUDE_MIN_OVER_HALF\n\
|
|
18
|
-
#define ELLIPSOID_HAS_RENDER_BOUNDS_HEIGHT_MAX\n\
|
|
19
|
-
#define ELLIPSOID_HAS_RENDER_BOUNDS_HEIGHT_MIN\n\
|
|
20
18
|
#define ELLIPSOID_INTERSECTION_INDEX_LONGITUDE\n\
|
|
21
19
|
#define ELLIPSOID_INTERSECTION_INDEX_LATITUDE_MAX\n\
|
|
22
20
|
#define ELLIPSOID_INTERSECTION_INDEX_LATITUDE_MIN\n\
|
|
@@ -27,133 +25,225 @@ export default "// See IntersectionUtils.glsl for the definitions of Ray, Inters
|
|
|
27
25
|
#if defined(ELLIPSOID_HAS_RENDER_BOUNDS_LONGITUDE)\n\
|
|
28
26
|
uniform vec2 u_ellipsoidRenderLongitudeMinMax;\n\
|
|
29
27
|
#endif\n\
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
#if defined(ELLIPSOID_HAS_RENDER_BOUNDS_HEIGHT_MAX)\n\
|
|
34
|
-
uniform float u_ellipsoidInverseOuterScaleUv;\n\
|
|
35
|
-
#endif\n\
|
|
36
|
-
#if defined(ELLIPSOID_HAS_RENDER_BOUNDS_HEIGHT_MIN)\n\
|
|
37
|
-
uniform float u_ellipsoidInverseInnerScaleUv;\n\
|
|
38
|
-
#endif\n\
|
|
28
|
+
uniform float u_eccentricitySquared;\n\
|
|
29
|
+
uniform vec2 u_ellipsoidRenderLatitudeSinMinMax;\n\
|
|
30
|
+
uniform vec2 u_clipMinMaxHeight;\n\
|
|
39
31
|
\n\
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
float o = ray.pos.z;\n\
|
|
43
|
-
float d = ray.dir.z;\n\
|
|
44
|
-
float t = -o / d;\n\
|
|
45
|
-
float s = sign(o);\n\
|
|
32
|
+
RayShapeIntersection intersectZPlane(in Ray ray, in float z) {\n\
|
|
33
|
+
float t = -ray.pos.z / ray.dir.z;\n\
|
|
46
34
|
\n\
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
}\n\
|
|
35
|
+
bool startsOutside = sign(ray.pos.z) == sign(z);\n\
|
|
36
|
+
bool entry = (t >= 0.0) != startsOutside;\n\
|
|
50
37
|
\n\
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
vec3 o = ray.pos;\n\
|
|
54
|
-
vec3 d = ray.dir;\n\
|
|
38
|
+
vec4 intersect = vec4(0.0, 0.0, z, t);\n\
|
|
39
|
+
vec4 farSide = vec4(normalize(ray.dir), INF_HIT);\n\
|
|
55
40
|
\n\
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
41
|
+
if (entry) {\n\
|
|
42
|
+
return RayShapeIntersection(intersect, farSide);\n\
|
|
43
|
+
} else {\n\
|
|
44
|
+
return RayShapeIntersection(-1.0 * farSide, intersect);\n\
|
|
45
|
+
}\n\
|
|
46
|
+
}\n\
|
|
59
47
|
\n\
|
|
60
|
-
|
|
61
|
-
|
|
48
|
+
RayShapeIntersection intersectHeight(in Ray ray, in float relativeHeight, in bool convex)\n\
|
|
49
|
+
{\n\
|
|
50
|
+
// Scale the ray by the ellipsoid axes to make it a unit sphere\n\
|
|
51
|
+
// Note: approximating ellipsoid + height as an ellipsoid\n\
|
|
52
|
+
vec3 radiiCorrection = u_ellipsoidRadiiUv / (u_ellipsoidRadiiUv + relativeHeight);\n\
|
|
53
|
+
vec3 position = ray.pos * radiiCorrection;\n\
|
|
54
|
+
vec3 direction = ray.dir * radiiCorrection;\n\
|
|
55
|
+
\n\
|
|
56
|
+
float a = dot(direction, direction); // ~ 1.0 (or maybe 4.0 if ray is scaled)\n\
|
|
57
|
+
float b = dot(direction, position); // roughly inside [-1.0, 1.0] when zoomed in\n\
|
|
58
|
+
float c = dot(position, position) - 1.0; // ~ 0.0 when zoomed in.\n\
|
|
59
|
+
float determinant = b * b - a * c; // ~ b * b when zoomed in\n\
|
|
60
|
+
\n\
|
|
61
|
+
if (determinant < 0.0) {\n\
|
|
62
|
+
vec4 miss = vec4(normalize(direction), NO_HIT);\n\
|
|
63
|
+
return RayShapeIntersection(miss, miss);\n\
|
|
62
64
|
}\n\
|
|
63
65
|
\n\
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
66
|
+
determinant = sqrt(determinant);\n\
|
|
67
|
+
\n\
|
|
68
|
+
// Compute larger root using standard formula\n\
|
|
69
|
+
float signB = b < 0.0 ? -1.0 : 1.0;\n\
|
|
70
|
+
// The other root may suffer from subtractive cancellation in the standard formula.\n\
|
|
71
|
+
// Compute it from the first root instead.\n\
|
|
72
|
+
float t1 = (-b - signB * determinant) / a;\n\
|
|
73
|
+
float t2 = c / (a * t1);\n\
|
|
67
74
|
float tmin = min(t1, t2);\n\
|
|
68
75
|
float tmax = max(t1, t2);\n\
|
|
69
76
|
\n\
|
|
70
|
-
|
|
77
|
+
float directionScale = convex ? 1.0 : -1.0;\n\
|
|
78
|
+
vec3 d1 = directionScale * normalize(position + tmin * direction);\n\
|
|
79
|
+
vec3 d2 = directionScale * normalize(position + tmax * direction);\n\
|
|
80
|
+
\n\
|
|
81
|
+
return RayShapeIntersection(vec4(d1, tmin), vec4(d2, tmax));\n\
|
|
71
82
|
}\n\
|
|
72
83
|
\n\
|
|
73
|
-
|
|
84
|
+
/**\n\
|
|
85
|
+
* Given a circular cone around the z-axis, with apex at the origin,\n\
|
|
86
|
+
* find the parametric distance(s) along a ray where that ray intersects\n\
|
|
87
|
+
* the cone.\n\
|
|
88
|
+
* The cone opening angle is described by the squared cosine of\n\
|
|
89
|
+
* its half-angle (the angle between the Z-axis and the surface)\n\
|
|
90
|
+
*/\n\
|
|
91
|
+
vec2 intersectDoubleEndedCone(in Ray ray, in float cosSqrHalfAngle)\n\
|
|
74
92
|
{\n\
|
|
75
93
|
vec3 o = ray.pos;\n\
|
|
76
94
|
vec3 d = ray.dir;\n\
|
|
95
|
+
float sinSqrHalfAngle = 1.0 - cosSqrHalfAngle;\n\
|
|
96
|
+
\n\
|
|
97
|
+
float aSin = d.z * d.z * sinSqrHalfAngle;\n\
|
|
98
|
+
float aCos = -dot(d.xy, d.xy) * cosSqrHalfAngle;\n\
|
|
99
|
+
float a = aSin + aCos;\n\
|
|
77
100
|
\n\
|
|
78
|
-
float
|
|
79
|
-
float
|
|
80
|
-
float
|
|
81
|
-
float det = b * b - a * c;\n\
|
|
101
|
+
float bSin = d.z * o.z * sinSqrHalfAngle;\n\
|
|
102
|
+
float bCos = -dot(o.xy, d.xy) * cosSqrHalfAngle;\n\
|
|
103
|
+
float b = bSin + bCos;\n\
|
|
82
104
|
\n\
|
|
83
|
-
|
|
105
|
+
float cSin = o.z * o.z * sinSqrHalfAngle;\n\
|
|
106
|
+
float cCos = -dot(o.xy, o.xy) * cosSqrHalfAngle;\n\
|
|
107
|
+
float c = cSin + cCos;\n\
|
|
108
|
+
// determinant = b * b - a * c. But bSin * bSin = aSin * cSin.\n\
|
|
109
|
+
// Avoid subtractive cancellation by expanding to eliminate these terms\n\
|
|
110
|
+
float determinant = 2.0 * bSin * bCos + bCos * bCos - aSin * cCos - aCos * cSin - aCos * cCos;\n\
|
|
111
|
+
\n\
|
|
112
|
+
if (determinant < 0.0) {\n\
|
|
84
113
|
return vec2(NO_HIT);\n\
|
|
114
|
+
} else if (a == 0.0) {\n\
|
|
115
|
+
// Ray is parallel to cone surface\n\
|
|
116
|
+
return (b == 0.0)\n\
|
|
117
|
+
? vec2(NO_HIT) // Ray is on cone surface\n\
|
|
118
|
+
: vec2(-0.5 * c / b, NO_HIT);\n\
|
|
85
119
|
}\n\
|
|
86
120
|
\n\
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
121
|
+
determinant = sqrt(determinant);\n\
|
|
122
|
+
\n\
|
|
123
|
+
// Compute larger root using standard formula\n\
|
|
124
|
+
float signB = b < 0.0 ? -1.0 : 1.0;\n\
|
|
125
|
+
float t1 = (-b - signB * determinant) / a;\n\
|
|
126
|
+
// The other root may suffer from subtractive cancellation in the standard formula.\n\
|
|
127
|
+
// Compute it from the first root instead.\n\
|
|
128
|
+
float t2 = c / (a * t1);\n\
|
|
90
129
|
float tmin = min(t1, t2);\n\
|
|
91
130
|
float tmax = max(t1, t2);\n\
|
|
92
|
-
\n\
|
|
93
131
|
return vec2(tmin, tmax);\n\
|
|
94
132
|
}\n\
|
|
95
133
|
\n\
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
float
|
|
104
|
-
|
|
105
|
-
if
|
|
106
|
-
|
|
107
|
-
|
|
134
|
+
/**\n\
|
|
135
|
+
* Given a point on a conical surface, find the surface normal at that point.\n\
|
|
136
|
+
*/\n\
|
|
137
|
+
vec3 getConeNormal(in vec3 p, in bool convex) {\n\
|
|
138
|
+
// Start with radial component pointing toward z-axis\n\
|
|
139
|
+
vec2 radial = -abs(p.z) * normalize(p.xy);\n\
|
|
140
|
+
// Z component points toward opening of cone\n\
|
|
141
|
+
float zSign = (p.z < 0.0) ? -1.0 : 1.0;\n\
|
|
142
|
+
float z = length(p.xy) * zSign;\n\
|
|
143
|
+
// Flip normal if shape is convex\n\
|
|
144
|
+
float flip = (convex) ? -1.0 : 1.0;\n\
|
|
145
|
+
return normalize(vec3(radial, z) * flip);\n\
|
|
146
|
+
}\n\
|
|
108
147
|
\n\
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
148
|
+
/**\n\
|
|
149
|
+
* Compute the shift between the ellipsoid origin and the apex of a cone of latitude\n\
|
|
150
|
+
*/\n\
|
|
151
|
+
float getLatitudeConeShift(in float sinLatitude) {\n\
|
|
152
|
+
// Find prime vertical radius of curvature: \n\
|
|
153
|
+
// the distance along the ellipsoid normal to the intersection with the z-axis\n\
|
|
154
|
+
float x2 = u_eccentricitySquared * sinLatitude * sinLatitude;\n\
|
|
155
|
+
float primeVerticalRadius = inversesqrt(1.0 - x2);\n\
|
|
156
|
+
\n\
|
|
157
|
+
// Compute a shift from the origin to the intersection of the cone with the z-axis\n\
|
|
158
|
+
return primeVerticalRadius * u_eccentricitySquared * sinLatitude;\n\
|
|
115
159
|
}\n\
|
|
116
160
|
\n\
|
|
117
|
-
|
|
161
|
+
void intersectFlippedCone(in Ray ray, in float cosHalfAngle, out RayShapeIntersection intersections[2]) {\n\
|
|
162
|
+
// Undo the scaling from ellipsoid to sphere\n\
|
|
163
|
+
ray.pos = ray.pos * u_ellipsoidRadiiUv;\n\
|
|
164
|
+
ray.dir = ray.dir * u_ellipsoidRadiiUv;\n\
|
|
165
|
+
// Shift the ray to account for the latitude cone not being centered at the Earth center\n\
|
|
166
|
+
ray.pos.z += getLatitudeConeShift(cosHalfAngle);\n\
|
|
167
|
+
\n\
|
|
168
|
+
float cosSqrHalfAngle = cosHalfAngle * cosHalfAngle;\n\
|
|
118
169
|
vec2 intersect = intersectDoubleEndedCone(ray, cosSqrHalfAngle);\n\
|
|
170
|
+
\n\
|
|
171
|
+
vec4 miss = vec4(normalize(ray.dir), NO_HIT);\n\
|
|
172
|
+
vec4 farSide = vec4(normalize(ray.dir), INF_HIT);\n\
|
|
173
|
+
\n\
|
|
174
|
+
// Initialize output with no intersections\n\
|
|
175
|
+
intersections[0].entry = -1.0 * farSide;\n\
|
|
176
|
+
intersections[0].exit = farSide;\n\
|
|
177
|
+
intersections[1].entry = miss;\n\
|
|
178
|
+
intersections[1].exit = miss;\n\
|
|
119
179
|
\n\
|
|
120
180
|
if (intersect.x == NO_HIT) {\n\
|
|
121
|
-
return
|
|
181
|
+
return;\n\
|
|
122
182
|
}\n\
|
|
123
183
|
\n\
|
|
124
|
-
|
|
125
|
-
vec3 d = ray.dir;\n\
|
|
184
|
+
// Find the points of intersection\n\
|
|
126
185
|
float tmin = intersect.x;\n\
|
|
127
186
|
float tmax = intersect.y;\n\
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
\n\
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
187
|
+
vec3 p0 = ray.pos + tmin * ray.dir;\n\
|
|
188
|
+
vec3 p1 = ray.pos + tmax * ray.dir;\n\
|
|
189
|
+
\n\
|
|
190
|
+
vec4 intersect0 = vec4(getConeNormal(p0, true), tmin);\n\
|
|
191
|
+
vec4 intersect1 = vec4(getConeNormal(p1, true), tmax);\n\
|
|
192
|
+
\n\
|
|
193
|
+
bool p0InShadowCone = sign(p0.z) != sign(cosHalfAngle);\n\
|
|
194
|
+
bool p1InShadowCone = sign(p1.z) != sign(cosHalfAngle);\n\
|
|
195
|
+
\n\
|
|
196
|
+
if (p0InShadowCone && p1InShadowCone) {\n\
|
|
197
|
+
// no valid intersections\n\
|
|
198
|
+
} else if (p0InShadowCone) {\n\
|
|
199
|
+
intersections[0].exit = intersect1;\n\
|
|
200
|
+
} else if (p1InShadowCone) {\n\
|
|
201
|
+
intersections[0].entry = intersect0;\n\
|
|
202
|
+
} else {\n\
|
|
203
|
+
intersections[0].exit = intersect0;\n\
|
|
204
|
+
intersections[1].entry = intersect1;\n\
|
|
205
|
+
intersections[1].exit = farSide;\n\
|
|
206
|
+
}\n\
|
|
137
207
|
}\n\
|
|
138
208
|
\n\
|
|
139
|
-
|
|
209
|
+
RayShapeIntersection intersectRegularCone(in Ray ray, in float cosHalfAngle, in bool convex) {\n\
|
|
210
|
+
// Undo the scaling from ellipsoid to sphere\n\
|
|
211
|
+
ray.pos = ray.pos * u_ellipsoidRadiiUv;\n\
|
|
212
|
+
ray.dir = ray.dir * u_ellipsoidRadiiUv;\n\
|
|
213
|
+
// Shift the ray to account for the latitude cone not being centered at the Earth center\n\
|
|
214
|
+
ray.pos.z += getLatitudeConeShift(cosHalfAngle);\n\
|
|
215
|
+
\n\
|
|
216
|
+
float cosSqrHalfAngle = cosHalfAngle * cosHalfAngle;\n\
|
|
140
217
|
vec2 intersect = intersectDoubleEndedCone(ray, cosSqrHalfAngle);\n\
|
|
218
|
+
\n\
|
|
219
|
+
vec4 miss = vec4(normalize(ray.dir), NO_HIT);\n\
|
|
220
|
+
vec4 farSide = vec4(normalize(ray.dir), INF_HIT);\n\
|
|
141
221
|
\n\
|
|
142
222
|
if (intersect.x == NO_HIT) {\n\
|
|
143
|
-
return
|
|
223
|
+
return RayShapeIntersection(miss, miss);\n\
|
|
144
224
|
}\n\
|
|
145
225
|
\n\
|
|
146
|
-
|
|
147
|
-
vec3 d = ray.dir;\n\
|
|
226
|
+
// Find the points of intersection\n\
|
|
148
227
|
float tmin = intersect.x;\n\
|
|
149
228
|
float tmax = intersect.y;\n\
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
\n\
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
229
|
+
vec3 p0 = ray.pos + tmin * ray.dir;\n\
|
|
230
|
+
vec3 p1 = ray.pos + tmax * ray.dir;\n\
|
|
231
|
+
\n\
|
|
232
|
+
vec4 intersect0 = vec4(getConeNormal(p0, convex), tmin);\n\
|
|
233
|
+
vec4 intersect1 = vec4(getConeNormal(p1, convex), tmax);\n\
|
|
234
|
+
\n\
|
|
235
|
+
bool p0InShadowCone = sign(p0.z) != sign(cosHalfAngle);\n\
|
|
236
|
+
bool p1InShadowCone = sign(p1.z) != sign(cosHalfAngle);\n\
|
|
237
|
+
\n\
|
|
238
|
+
if (p0InShadowCone && p1InShadowCone) {\n\
|
|
239
|
+
return RayShapeIntersection(miss, miss);\n\
|
|
240
|
+
} else if (p0InShadowCone) {\n\
|
|
241
|
+
return RayShapeIntersection(intersect1, farSide);\n\
|
|
242
|
+
} else if (p1InShadowCone) {\n\
|
|
243
|
+
return RayShapeIntersection(-1.0 * farSide, intersect0);\n\
|
|
244
|
+
} else {\n\
|
|
245
|
+
return RayShapeIntersection(intersect0, intersect1);\n\
|
|
246
|
+
}\n\
|
|
157
247
|
}\n\
|
|
158
248
|
\n\
|
|
159
249
|
void intersectShape(in Ray ray, inout Intersections ix) {\n\
|
|
@@ -161,92 +251,74 @@ void intersectShape(in Ray ray, inout Intersections ix) {\n\
|
|
|
161
251
|
// Direction is scaled as well to be in sync with position.\n\
|
|
162
252
|
ray.pos = ray.pos * 2.0 - 1.0;\n\
|
|
163
253
|
ray.dir *= 2.0;\n\
|
|
164
|
-
\n\
|
|
165
|
-
#if defined(ELLIPSOID_HAS_RENDER_BOUNDS_HEIGHT_MAX)\n\
|
|
166
|
-
Ray outerRay = Ray(ray.pos * u_ellipsoidInverseOuterScaleUv, ray.dir * u_ellipsoidInverseOuterScaleUv);\n\
|
|
167
|
-
#else\n\
|
|
168
|
-
Ray outerRay = ray;\n\
|
|
169
|
-
#endif\n\
|
|
170
254
|
\n\
|
|
171
255
|
// Outer ellipsoid\n\
|
|
172
|
-
|
|
173
|
-
|
|
256
|
+
RayShapeIntersection outerIntersect = intersectHeight(ray, u_clipMinMaxHeight.y, true);\n\
|
|
257
|
+
setShapeIntersection(ix, ELLIPSOID_INTERSECTION_INDEX_HEIGHT_MAX, outerIntersect);\n\
|
|
174
258
|
\n\
|
|
175
259
|
// Exit early if the outer ellipsoid was missed.\n\
|
|
176
|
-
if (outerIntersect.
|
|
260
|
+
if (outerIntersect.entry.w == NO_HIT) {\n\
|
|
177
261
|
return;\n\
|
|
178
262
|
}\n\
|
|
179
263
|
\n\
|
|
180
264
|
// Inner ellipsoid\n\
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
\n\
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
\n\
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
\n\
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
innerIntersect.y = min(innerIntersect.y, outerIntersect.y);\n\
|
|
212
|
-
setIntersection(ix, 0, outerIntersect.x, true, true); // positive, enter\n\
|
|
213
|
-
setIntersection(ix, 1, innerIntersect.x, false, true); // negative, enter\n\
|
|
214
|
-
setIntersection(ix, 2, innerIntersect.y, false, false); // negative, exit\n\
|
|
215
|
-
setIntersection(ix, 3, outerIntersect.y, true, false); // positive, exit\n\
|
|
216
|
-
}\n\
|
|
217
|
-
#endif\n\
|
|
218
|
-
\n\
|
|
219
|
-
// Flip the ray because the intersection function expects a cone growing towards +Z.\n\
|
|
220
|
-
#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\
|
|
221
|
-
Ray flippedRay = outerRay;\n\
|
|
222
|
-
flippedRay.dir.z *= -1.0;\n\
|
|
223
|
-
flippedRay.pos.z *= -1.0;\n\
|
|
224
|
-
#endif\n\
|
|
265
|
+
RayShapeIntersection innerIntersect = intersectHeight(ray, u_clipMinMaxHeight.x, false);\n\
|
|
266
|
+
\n\
|
|
267
|
+
if (innerIntersect.entry.w == NO_HIT) {\n\
|
|
268
|
+
setShapeIntersection(ix, ELLIPSOID_INTERSECTION_INDEX_HEIGHT_MIN, innerIntersect);\n\
|
|
269
|
+
} else {\n\
|
|
270
|
+
// When the ellipsoid is large and thin it's possible for floating point math\n\
|
|
271
|
+
// to cause the ray to intersect the inner ellipsoid before the outer ellipsoid. \n\
|
|
272
|
+
// To prevent this from happening, clamp innerIntersect to outerIntersect and\n\
|
|
273
|
+
// sandwich the inner ellipsoid intersection inside the outer ellipsoid intersection.\n\
|
|
274
|
+
\n\
|
|
275
|
+
// Without this special case,\n\
|
|
276
|
+
// [outerMin, outerMax, innerMin, innerMax] will bubble sort to\n\
|
|
277
|
+
// [outerMin, innerMin, outerMax, innerMax] which will cause the back\n\
|
|
278
|
+
// side of the ellipsoid to be invisible because it will think the ray\n\
|
|
279
|
+
// is still inside the inner (negative) ellipsoid after exiting the\n\
|
|
280
|
+
// outer (positive) ellipsoid.\n\
|
|
281
|
+
\n\
|
|
282
|
+
// With this special case,\n\
|
|
283
|
+
// [outerMin, innerMin, innerMax, outerMax] will bubble sort to\n\
|
|
284
|
+
// [outerMin, innerMin, innerMax, outerMax] which will work correctly.\n\
|
|
285
|
+
\n\
|
|
286
|
+
// Note: If initializeIntersections() changes its sorting function\n\
|
|
287
|
+
// from bubble sort to something else, this code may need to change.\n\
|
|
288
|
+
innerIntersect.entry.w = max(innerIntersect.entry.w, outerIntersect.entry.w);\n\
|
|
289
|
+
innerIntersect.exit.w = min(innerIntersect.exit.w, outerIntersect.exit.w);\n\
|
|
290
|
+
setSurfaceIntersection(ix, 0, outerIntersect.entry, true, true); // positive, enter\n\
|
|
291
|
+
setSurfaceIntersection(ix, 1, innerIntersect.entry, false, true); // negative, enter\n\
|
|
292
|
+
setSurfaceIntersection(ix, 2, innerIntersect.exit, false, false); // negative, exit\n\
|
|
293
|
+
setSurfaceIntersection(ix, 3, outerIntersect.exit, true, false); // positive, exit\n\
|
|
294
|
+
}\n\
|
|
225
295
|
\n\
|
|
226
296
|
// Bottom cone\n\
|
|
227
297
|
#if defined(ELLIPSOID_HAS_RENDER_BOUNDS_LATITUDE_MIN_UNDER_HALF)\n\
|
|
228
|
-
|
|
229
|
-
|
|
298
|
+
RayShapeIntersection bottomConeIntersection = intersectRegularCone(ray, u_ellipsoidRenderLatitudeSinMinMax.x, false);\n\
|
|
299
|
+
setShapeIntersection(ix, ELLIPSOID_INTERSECTION_INDEX_LATITUDE_MIN, bottomConeIntersection);\n\
|
|
230
300
|
#elif defined(ELLIPSOID_HAS_RENDER_BOUNDS_LATITUDE_MIN_EQUAL_HALF)\n\
|
|
231
|
-
|
|
232
|
-
|
|
301
|
+
RayShapeIntersection bottomConeIntersection = intersectZPlane(ray, -1.0);\n\
|
|
302
|
+
setShapeIntersection(ix, ELLIPSOID_INTERSECTION_INDEX_LATITUDE_MIN, bottomConeIntersection);\n\
|
|
233
303
|
#elif defined(ELLIPSOID_HAS_RENDER_BOUNDS_LATITUDE_MIN_OVER_HALF)\n\
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
304
|
+
RayShapeIntersection bottomConeIntersections[2];\n\
|
|
305
|
+
intersectFlippedCone(ray, u_ellipsoidRenderLatitudeSinMinMax.x, bottomConeIntersections);\n\
|
|
306
|
+
setShapeIntersection(ix, ELLIPSOID_INTERSECTION_INDEX_LATITUDE_MIN + 0, bottomConeIntersections[0]);\n\
|
|
307
|
+
setShapeIntersection(ix, ELLIPSOID_INTERSECTION_INDEX_LATITUDE_MIN + 1, bottomConeIntersections[1]);\n\
|
|
237
308
|
#endif\n\
|
|
238
309
|
\n\
|
|
239
310
|
// Top cone\n\
|
|
240
311
|
#if defined(ELLIPSOID_HAS_RENDER_BOUNDS_LATITUDE_MAX_UNDER_HALF)\n\
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
312
|
+
RayShapeIntersection topConeIntersections[2];\n\
|
|
313
|
+
intersectFlippedCone(ray, u_ellipsoidRenderLatitudeSinMinMax.y, topConeIntersections);\n\
|
|
314
|
+
setShapeIntersection(ix, ELLIPSOID_INTERSECTION_INDEX_LATITUDE_MAX + 0, topConeIntersections[0]);\n\
|
|
315
|
+
setShapeIntersection(ix, ELLIPSOID_INTERSECTION_INDEX_LATITUDE_MAX + 1, topConeIntersections[1]);\n\
|
|
244
316
|
#elif defined(ELLIPSOID_HAS_RENDER_BOUNDS_LATITUDE_MAX_EQUAL_HALF)\n\
|
|
245
|
-
|
|
246
|
-
|
|
317
|
+
RayShapeIntersection topConeIntersection = intersectZPlane(ray, 1.0);\n\
|
|
318
|
+
setShapeIntersection(ix, ELLIPSOID_INTERSECTION_INDEX_LATITUDE_MAX, topConeIntersection);\n\
|
|
247
319
|
#elif defined(ELLIPSOID_HAS_RENDER_BOUNDS_LATITUDE_MAX_OVER_HALF)\n\
|
|
248
|
-
|
|
249
|
-
|
|
320
|
+
RayShapeIntersection topConeIntersection = intersectRegularCone(ray, u_ellipsoidRenderLatitudeSinMinMax.y, false);\n\
|
|
321
|
+
setShapeIntersection(ix, ELLIPSOID_INTERSECTION_INDEX_LATITUDE_MAX, topConeIntersection);\n\
|
|
250
322
|
#endif\n\
|
|
251
323
|
\n\
|
|
252
324
|
// Wedge\n\
|
|
@@ -4,22 +4,44 @@
|
|
|
4
4
|
|
|
5
5
|
#define NO_HIT (-czm_infinity)
|
|
6
6
|
#define INF_HIT (czm_infinity * 0.5)
|
|
7
|
-
#define RAY_SHIFT (0.000003163)
|
|
8
|
-
#define RAY_SCALE (1.003163)
|
|
9
|
-
|
|
10
|
-
struct Ray {
|
|
11
|
-
vec3 pos;
|
|
12
|
-
vec3 dir;
|
|
13
|
-
#if defined(SHAPE_BOX)
|
|
14
|
-
vec3 dInv;
|
|
15
|
-
#endif
|
|
16
|
-
};
|
|
17
7
|
|
|
18
8
|
struct RayShapeIntersection {
|
|
19
9
|
vec4 entry;
|
|
20
10
|
vec4 exit;
|
|
21
11
|
};
|
|
22
12
|
|
|
13
|
+
vec4 intersectionMin(in vec4 intersect0, in vec4 intersect1)
|
|
14
|
+
{
|
|
15
|
+
if (intersect0.w == NO_HIT) {
|
|
16
|
+
return intersect1;
|
|
17
|
+
} else if (intersect1.w == NO_HIT) {
|
|
18
|
+
return intersect0;
|
|
19
|
+
}
|
|
20
|
+
return (intersect0.w <= intersect1.w) ? intersect0 : intersect1;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
vec4 intersectionMax(in vec4 intersect0, in vec4 intersect1)
|
|
24
|
+
{
|
|
25
|
+
return (intersect0.w >= intersect1.w) ? intersect0 : intersect1;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
RayShapeIntersection intersectIntersections(in Ray ray, in RayShapeIntersection intersect0, in RayShapeIntersection intersect1)
|
|
29
|
+
{
|
|
30
|
+
bool missed = (intersect0.entry.w == NO_HIT) ||
|
|
31
|
+
(intersect1.entry.w == NO_HIT) ||
|
|
32
|
+
(intersect0.exit.w < intersect1.entry.w) ||
|
|
33
|
+
(intersect0.entry.w > intersect1.exit.w);
|
|
34
|
+
if (missed) {
|
|
35
|
+
vec4 miss = vec4(normalize(ray.dir), NO_HIT);
|
|
36
|
+
return RayShapeIntersection(miss, miss);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
vec4 entry = intersectionMax(intersect0.entry, intersect1.entry);
|
|
40
|
+
vec4 exit = intersectionMin(intersect0.exit, intersect1.exit);
|
|
41
|
+
|
|
42
|
+
return RayShapeIntersection(entry, exit);
|
|
43
|
+
}
|
|
44
|
+
|
|
23
45
|
struct Intersections {
|
|
24
46
|
// Don't access these member variables directly - call the functions instead.
|
|
25
47
|
|
|
@@ -57,7 +79,7 @@ vec4 encodeIntersectionType(vec4 intersection, int index, bool entry)
|
|
|
57
79
|
// Use defines instead of real functions because WebGL1 cannot access array with non-constant index.
|
|
58
80
|
#define setIntersection(/*inout Intersections*/ ix, /*int*/ index, /*float*/ t, /*bool*/ positive, /*bool*/ enter) (ix).intersections[(index)] = vec4(0.0, float(!positive) * 2.0 + float(!enter) + 1.0, 0.0, (t))
|
|
59
81
|
#define setIntersectionPair(/*inout Intersections*/ ix, /*int*/ index, /*vec2*/ entryExit) (ix).intersections[(index) * 2 + 0] = vec4(0.0, float((index) > 0) * 2.0 + 1.0, 0.0, (entryExit).x); (ix).intersections[(index) * 2 + 1] = vec4(0.0, float((index) > 0) * 2.0 + 2.0, 0.0, (entryExit).y)
|
|
60
|
-
#define setSurfaceIntersection(/*inout Intersections*/ ix, /*int*/ index, /*vec4*/ intersection) (ix).intersections[(index)] = intersection
|
|
82
|
+
#define setSurfaceIntersection(/*inout Intersections*/ ix, /*int*/ index, /*vec4*/ intersection, /*bool*/ positive, /*bool*/ enter) (ix).intersections[(index)] = encodeIntersectionType((intersection), int(!positive), (enter))
|
|
61
83
|
#define setShapeIntersection(/*inout Intersections*/ ix, /*int*/ index, /*RayShapeIntersection*/ intersection) (ix).intersections[(index) * 2 + 0] = encodeIntersectionType((intersection).entry, (index), true); (ix).intersections[(index) * 2 + 1] = encodeIntersectionType((intersection).exit, (index), false)
|
|
62
84
|
|
|
63
85
|
#if (INTERSECTION_COUNT > 1)
|
|
@@ -5,22 +5,44 @@ export default "/* Intersection defines\n\
|
|
|
5
5
|
\n\
|
|
6
6
|
#define NO_HIT (-czm_infinity)\n\
|
|
7
7
|
#define INF_HIT (czm_infinity * 0.5)\n\
|
|
8
|
-
#define RAY_SHIFT (0.000003163)\n\
|
|
9
|
-
#define RAY_SCALE (1.003163)\n\
|
|
10
|
-
\n\
|
|
11
|
-
struct Ray {\n\
|
|
12
|
-
vec3 pos;\n\
|
|
13
|
-
vec3 dir;\n\
|
|
14
|
-
#if defined(SHAPE_BOX)\n\
|
|
15
|
-
vec3 dInv;\n\
|
|
16
|
-
#endif\n\
|
|
17
|
-
};\n\
|
|
18
8
|
\n\
|
|
19
9
|
struct RayShapeIntersection {\n\
|
|
20
10
|
vec4 entry;\n\
|
|
21
11
|
vec4 exit;\n\
|
|
22
12
|
};\n\
|
|
23
13
|
\n\
|
|
14
|
+
vec4 intersectionMin(in vec4 intersect0, in vec4 intersect1)\n\
|
|
15
|
+
{\n\
|
|
16
|
+
if (intersect0.w == NO_HIT) {\n\
|
|
17
|
+
return intersect1;\n\
|
|
18
|
+
} else if (intersect1.w == NO_HIT) {\n\
|
|
19
|
+
return intersect0;\n\
|
|
20
|
+
}\n\
|
|
21
|
+
return (intersect0.w <= intersect1.w) ? intersect0 : intersect1;\n\
|
|
22
|
+
}\n\
|
|
23
|
+
\n\
|
|
24
|
+
vec4 intersectionMax(in vec4 intersect0, in vec4 intersect1)\n\
|
|
25
|
+
{\n\
|
|
26
|
+
return (intersect0.w >= intersect1.w) ? intersect0 : intersect1;\n\
|
|
27
|
+
}\n\
|
|
28
|
+
\n\
|
|
29
|
+
RayShapeIntersection intersectIntersections(in Ray ray, in RayShapeIntersection intersect0, in RayShapeIntersection intersect1)\n\
|
|
30
|
+
{\n\
|
|
31
|
+
bool missed = (intersect0.entry.w == NO_HIT) ||\n\
|
|
32
|
+
(intersect1.entry.w == NO_HIT) ||\n\
|
|
33
|
+
(intersect0.exit.w < intersect1.entry.w) ||\n\
|
|
34
|
+
(intersect0.entry.w > intersect1.exit.w);\n\
|
|
35
|
+
if (missed) {\n\
|
|
36
|
+
vec4 miss = vec4(normalize(ray.dir), NO_HIT);\n\
|
|
37
|
+
return RayShapeIntersection(miss, miss);\n\
|
|
38
|
+
}\n\
|
|
39
|
+
\n\
|
|
40
|
+
vec4 entry = intersectionMax(intersect0.entry, intersect1.entry);\n\
|
|
41
|
+
vec4 exit = intersectionMin(intersect0.exit, intersect1.exit);\n\
|
|
42
|
+
\n\
|
|
43
|
+
return RayShapeIntersection(entry, exit);\n\
|
|
44
|
+
}\n\
|
|
45
|
+
\n\
|
|
24
46
|
struct Intersections {\n\
|
|
25
47
|
// Don't access these member variables directly - call the functions instead.\n\
|
|
26
48
|
\n\
|
|
@@ -58,7 +80,7 @@ vec4 encodeIntersectionType(vec4 intersection, int index, bool entry)\n\
|
|
|
58
80
|
// Use defines instead of real functions because WebGL1 cannot access array with non-constant index.\n\
|
|
59
81
|
#define setIntersection(/*inout Intersections*/ ix, /*int*/ index, /*float*/ t, /*bool*/ positive, /*bool*/ enter) (ix).intersections[(index)] = vec4(0.0, float(!positive) * 2.0 + float(!enter) + 1.0, 0.0, (t))\n\
|
|
60
82
|
#define setIntersectionPair(/*inout Intersections*/ ix, /*int*/ index, /*vec2*/ entryExit) (ix).intersections[(index) * 2 + 0] = vec4(0.0, float((index) > 0) * 2.0 + 1.0, 0.0, (entryExit).x); (ix).intersections[(index) * 2 + 1] = vec4(0.0, float((index) > 0) * 2.0 + 2.0, 0.0, (entryExit).y)\n\
|
|
61
|
-
#define setSurfaceIntersection(/*inout Intersections*/ ix, /*int*/ index, /*vec4*/ intersection) (ix).intersections[(index)] = intersection
|
|
83
|
+
#define setSurfaceIntersection(/*inout Intersections*/ ix, /*int*/ index, /*vec4*/ intersection, /*bool*/ positive, /*bool*/ enter) (ix).intersections[(index)] = encodeIntersectionType((intersection), int(!positive), (enter))\n\
|
|
62
84
|
#define setShapeIntersection(/*inout Intersections*/ ix, /*int*/ index, /*RayShapeIntersection*/ intersection) (ix).intersections[(index) * 2 + 0] = encodeIntersectionType((intersection).entry, (index), true); (ix).intersections[(index) * 2 + 1] = encodeIntersectionType((intersection).exit, (index), false)\n\
|
|
63
85
|
\n\
|
|
64
86
|
#if (INTERSECTION_COUNT > 1)\n\
|
|
@@ -71,9 +71,8 @@ vec2 index1DTo2DTexcoord(int index, ivec2 dimensions, vec2 uvScale)
|
|
|
71
71
|
*/
|
|
72
72
|
|
|
73
73
|
Properties getPropertiesFromMegatexture(in SampleData sampleData) {
|
|
74
|
-
vec3 tileUv = clamp(sampleData.tileUv, vec3(0.0), vec3(1.0)); // TODO is the clamp necessary?
|
|
75
74
|
int tileIndex = sampleData.megatextureIndex;
|
|
76
|
-
vec3 voxelCoord = tileUv * vec3(u_dimensions);
|
|
75
|
+
vec3 voxelCoord = sampleData.tileUv * vec3(u_dimensions);
|
|
77
76
|
ivec3 voxelDimensions = u_dimensions;
|
|
78
77
|
|
|
79
78
|
#if defined(PADDING)
|
|
@@ -72,9 +72,8 @@ vec2 index1DTo2DTexcoord(int index, ivec2 dimensions, vec2 uvScale)\n\
|
|
|
72
72
|
*/\n\
|
|
73
73
|
\n\
|
|
74
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
75
|
int tileIndex = sampleData.megatextureIndex;\n\
|
|
77
|
-
vec3 voxelCoord = tileUv * vec3(u_dimensions);\n\
|
|
76
|
+
vec3 voxelCoord = sampleData.tileUv * vec3(u_dimensions);\n\
|
|
78
77
|
ivec3 voxelDimensions = u_dimensions;\n\
|
|
79
78
|
\n\
|
|
80
79
|
#if defined(PADDING)\n\
|