@cesium/engine 12.0.1 → 13.0.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 (152) hide show
  1. package/Build/Workers/{chunk-WMHJAREU.js → chunk-22NU5WU5.js} +2 -2
  2. package/Build/Workers/{chunk-NL73INJS.js → chunk-2IIE2UZ3.js} +2 -2
  3. package/Build/Workers/{chunk-54NYY4U4.js → chunk-2OD54CUD.js} +7 -7
  4. package/Build/Workers/{chunk-NELAPOO6.js → chunk-2TSF7N76.js} +2 -2
  5. package/Build/Workers/{chunk-KKMH4BKN.js → chunk-3VHIUS7I.js} +6 -6
  6. package/Build/Workers/{chunk-U7SH6OK7.js → chunk-3ZMTG4X5.js} +4 -4
  7. package/Build/Workers/{chunk-ENARO52I.js → chunk-4HS475MU.js} +14 -14
  8. package/Build/Workers/{chunk-7CKQ7PVJ.js → chunk-4IM6WQEI.js} +6 -6
  9. package/Build/Workers/{chunk-3Y4UGAYI.js → chunk-6HWW6KNV.js} +6 -6
  10. package/Build/Workers/{chunk-VO4SXJXT.js → chunk-6ZOS2ACR.js} +7 -7
  11. package/Build/Workers/{chunk-7D6T2WYT.js → chunk-BFNZUP2C.js} +7 -41
  12. package/Build/Workers/{chunk-Q7IIOKAT.js → chunk-BLTSMJIP.js} +1 -1
  13. package/Build/Workers/{chunk-VXVQITFC.js → chunk-BZMHXDKV.js} +13 -13
  14. package/Build/Workers/{chunk-DR56WFYZ.js → chunk-CQDSGG3R.js} +7 -7
  15. package/Build/Workers/{chunk-DJ7K7EYK.js → chunk-CUMDCSMT.js} +11 -11
  16. package/Build/Workers/{chunk-2F42VIW6.js → chunk-D3VPMNUR.js} +13 -13
  17. package/Build/Workers/{chunk-76KRKKEF.js → chunk-DIAH2ZTB.js} +9 -9
  18. package/Build/Workers/{chunk-X6YBZOOA.js → chunk-EXDSJZ7J.js} +4 -4
  19. package/Build/Workers/{chunk-EMCXAVSG.js → chunk-FANORJU6.js} +2 -2
  20. package/Build/Workers/{chunk-GBPW65E3.js → chunk-FLPIQK2R.js} +6 -6
  21. package/Build/Workers/{chunk-ZPTNVB3S.js → chunk-GBXJIWAZ.js} +34 -8
  22. package/Build/Workers/{chunk-BH5M522L.js → chunk-GJZQSAES.js} +7 -7
  23. package/Build/Workers/{chunk-LBNGHEJY.js → chunk-GNG3V432.js} +4 -4
  24. package/Build/Workers/{chunk-2IJZVFHY.js → chunk-H4Y7ADFL.js} +5 -5
  25. package/Build/Workers/{chunk-ETXXXGMP.js → chunk-H7BML7HH.js} +6 -6
  26. package/Build/Workers/{chunk-PISTPJXS.js → chunk-HMMPNR4Z.js} +12 -12
  27. package/Build/Workers/{chunk-XDJ7V4NZ.js → chunk-JISDBAYP.js} +5 -5
  28. package/Build/Workers/{chunk-VHGI7D3P.js → chunk-KCCTLUKK.js} +10 -10
  29. package/Build/Workers/{chunk-2XOUWNPN.js → chunk-KKVKSTWC.js} +5 -5
  30. package/Build/Workers/{chunk-PNA47CR7.js → chunk-KRCUHV7P.js} +1 -1
  31. package/Build/Workers/{chunk-KJ65M35B.js → chunk-MMILY4S7.js} +11 -11
  32. package/Build/Workers/{chunk-22FZ334F.js → chunk-MSKD73KW.js} +10 -10
  33. package/Build/Workers/{chunk-PH3T7LNP.js → chunk-NVFEDMX4.js} +15 -15
  34. package/Build/Workers/{chunk-MV7YO647.js → chunk-OUIF26MQ.js} +6 -6
  35. package/Build/Workers/{chunk-IAX6MIST.js → chunk-OZZD3VY4.js} +17 -17
  36. package/Build/Workers/{chunk-647NL6VU.js → chunk-PD2MCNV7.js} +2 -2
  37. package/Build/Workers/{chunk-PJHRB4YJ.js → chunk-PMNQULFU.js} +7 -7
  38. package/Build/Workers/{chunk-YT5PQMSP.js → chunk-Q4MTXEB7.js} +6 -6
  39. package/Build/Workers/{chunk-JAKTB6CE.js → chunk-RC5N5SJL.js} +7 -7
  40. package/Build/Workers/{chunk-LVHHB5T6.js → chunk-RGZWZ4PP.js} +4 -4
  41. package/Build/Workers/{chunk-IVCFTVYW.js → chunk-RIQGQMS4.js} +4 -4
  42. package/Build/Workers/{chunk-GRQQHWMD.js → chunk-RR4M3ZGF.js} +7 -7
  43. package/Build/Workers/{chunk-K7QC3WDT.js → chunk-S4SCKDK4.js} +1 -1
  44. package/Build/Workers/{chunk-AGYO4ZSF.js → chunk-T5H7YWC7.js} +17 -17
  45. package/Build/Workers/{chunk-GSJ6LWIS.js → chunk-W2DVQETH.js} +10 -10
  46. package/Build/Workers/{chunk-JPNFQRN7.js → chunk-W2E67GLE.js} +13 -13
  47. package/Build/Workers/{chunk-ZCCI55EY.js → chunk-WXJY6NDI.js} +13 -13
  48. package/Build/Workers/{chunk-AER5CLXD.js → chunk-XQP37R5E.js} +5 -5
  49. package/Build/Workers/{chunk-7EBHNJTG.js → chunk-YBDL7YPF.js} +1 -1
  50. package/Build/Workers/{chunk-IJWXYSFC.js → chunk-YDEZMDB7.js} +2 -2
  51. package/Build/Workers/{chunk-H3RMGG7L.js → chunk-Z7OYBX6P.js} +5 -5
  52. package/Build/Workers/{chunk-COHL4R3G.js → chunk-ZIWULRRD.js} +1 -1
  53. package/Build/Workers/combineGeometry.js +22 -22
  54. package/Build/Workers/createBoxGeometry.js +16 -16
  55. package/Build/Workers/createBoxOutlineGeometry.js +14 -14
  56. package/Build/Workers/createCircleGeometry.js +24 -24
  57. package/Build/Workers/createCircleOutlineGeometry.js +17 -17
  58. package/Build/Workers/createCoplanarPolygonGeometry.js +31 -31
  59. package/Build/Workers/createCoplanarPolygonOutlineGeometry.js +29 -29
  60. package/Build/Workers/createCorridorGeometry.js +27 -27
  61. package/Build/Workers/createCorridorOutlineGeometry.js +26 -26
  62. package/Build/Workers/createCylinderGeometry.js +18 -18
  63. package/Build/Workers/createCylinderOutlineGeometry.js +16 -16
  64. package/Build/Workers/createEllipseGeometry.js +24 -24
  65. package/Build/Workers/createEllipseOutlineGeometry.js +17 -17
  66. package/Build/Workers/createEllipsoidGeometry.js +17 -17
  67. package/Build/Workers/createEllipsoidOutlineGeometry.js +16 -16
  68. package/Build/Workers/createFrustumGeometry.js +16 -16
  69. package/Build/Workers/createFrustumOutlineGeometry.js +16 -16
  70. package/Build/Workers/createGeometry.js +22 -22
  71. package/Build/Workers/createGroundPolylineGeometry.js +20 -20
  72. package/Build/Workers/createPlaneGeometry.js +14 -14
  73. package/Build/Workers/createPlaneOutlineGeometry.js +13 -13
  74. package/Build/Workers/createPolygonGeometry.js +30 -30
  75. package/Build/Workers/createPolygonOutlineGeometry.js +28 -28
  76. package/Build/Workers/createPolylineGeometry.js +23 -23
  77. package/Build/Workers/createPolylineVolumeGeometry.js +31 -32
  78. package/Build/Workers/createPolylineVolumeOutlineGeometry.js +25 -25
  79. package/Build/Workers/createRectangleGeometry.js +25 -25
  80. package/Build/Workers/createRectangleOutlineGeometry.js +18 -18
  81. package/Build/Workers/createSimplePolylineGeometry.js +21 -21
  82. package/Build/Workers/createSphereGeometry.js +17 -17
  83. package/Build/Workers/createSphereOutlineGeometry.js +16 -16
  84. package/Build/Workers/createTaskProcessorWorker.js +3 -3
  85. package/Build/Workers/createVectorTileClampedPolylines.js +13 -13
  86. package/Build/Workers/createVectorTileGeometries.js +22 -22
  87. package/Build/Workers/createVectorTilePoints.js +12 -12
  88. package/Build/Workers/createVectorTilePolygons.js +20 -20
  89. package/Build/Workers/createVectorTilePolylines.js +13 -13
  90. package/Build/Workers/createVerticesFromGoogleEarthEnterpriseBuffer.js +20 -20
  91. package/Build/Workers/createVerticesFromHeightmap.js +20 -20
  92. package/Build/Workers/createVerticesFromQuantizedTerrainMesh.js +17 -17
  93. package/Build/Workers/createWallGeometry.js +22 -22
  94. package/Build/Workers/createWallOutlineGeometry.js +21 -21
  95. package/Build/Workers/decodeDraco.js +11 -11
  96. package/Build/Workers/decodeGoogleEarthEnterprisePacket.js +5 -5
  97. package/Build/Workers/decodeI3S.js +10 -10
  98. package/Build/Workers/transcodeKTX2.js +7 -7
  99. package/Build/Workers/transferTypedArrayTest.js +1 -1
  100. package/Build/Workers/upsampleQuantizedTerrainMesh.js +20 -20
  101. package/Source/Core/BingMapsGeocoderService.js +2 -0
  102. package/Source/Core/GoogleGeocoderService.js +110 -0
  103. package/Source/Core/ITwinPlatform.js +359 -0
  104. package/Source/Core/Ion.js +1 -1
  105. package/Source/Core/IonGeocodeProviderType.js +33 -0
  106. package/Source/Core/IonGeocoderService.js +72 -0
  107. package/Source/Core/Rectangle.js +0 -20
  108. package/Source/Core/TrackingReferenceFrame.js +45 -0
  109. package/Source/DataSources/Entity.js +15 -1
  110. package/Source/DataSources/EntityView.js +55 -4
  111. package/Source/DataSources/SampledProperty.js +24 -0
  112. package/Source/Renderer/ContextLimits.js +1 -1
  113. package/Source/Renderer/Texture.js +104 -92
  114. package/Source/Scene/ArcGisMapService.js +1 -1
  115. package/Source/Scene/Cesium3DTilesetStatistics.js +109 -42
  116. package/Source/Scene/DerivedCommand.js +109 -16
  117. package/Source/Scene/DynamicEnvironmentMapManager.js +87 -7
  118. package/Source/Scene/GltfTextureLoader.js +16 -1
  119. package/Source/Scene/ITwinData.js +138 -0
  120. package/Source/Scene/Label.js +17 -3
  121. package/Source/Scene/MetadataClassProperty.js +26 -0
  122. package/Source/Scene/MetadataPicking.js +108 -17
  123. package/Source/Scene/MetadataType.js +20 -0
  124. package/Source/Scene/Model/Extensions/Gpm/GltfMeshPrimitiveGpmLoader.js +6 -11
  125. package/Source/Scene/Model/Model3DTileContent.js +23 -1
  126. package/Source/Scene/Model/ModelStatistics.js +33 -5
  127. package/Source/Scene/Model/PointCloudStylingPipelineStage.js +2 -1
  128. package/Source/Scene/PickedMetadataInfo.js +21 -3
  129. package/Source/Scene/Picking.js +7 -1
  130. package/Source/Scene/PostProcessStage.js +14 -17
  131. package/Source/Scene/PostProcessStageCollection.js +4 -16
  132. package/Source/Scene/PostProcessStageLibrary.js +13 -51
  133. package/Source/Scene/PropertyAttributeProperty.js +15 -3
  134. package/Source/Scene/PropertyTextureProperty.js +12 -0
  135. package/Source/Scene/Scene.js +17 -2
  136. package/Source/Scene/SkyBox.js +23 -4
  137. package/Source/Scene/UrlTemplateImageryProvider.js +5 -5
  138. package/Source/Scene/createGooglePhotorealistic3DTileset.js +55 -16
  139. package/Source/Scene/getMetadataProperty.js +48 -0
  140. package/Source/Shaders/Builtin/Functions/reverseLogDepth.glsl +1 -1
  141. package/Source/Shaders/Builtin/Functions/reverseLogDepth.js +1 -1
  142. package/Source/Shaders/ConvolveSpecularMapFS.glsl +1 -1
  143. package/Source/Shaders/ConvolveSpecularMapFS.js +1 -1
  144. package/Source/Shaders/Model/ModelFS.glsl +7 -0
  145. package/Source/Shaders/Model/ModelFS.js +7 -0
  146. package/Source/Shaders/Model/ModelVS.glsl +9 -1
  147. package/Source/Shaders/Model/ModelVS.js +9 -1
  148. package/Source/Shaders/PostProcessStages/AmbientOcclusionGenerate.glsl +66 -37
  149. package/Source/Shaders/PostProcessStages/AmbientOcclusionGenerate.js +66 -37
  150. package/index.d.ts +270 -39
  151. package/index.js +59 -53
  152. package/package.json +1 -1
@@ -5,16 +5,21 @@ uniform sampler2D depthTexture;
5
5
  uniform float intensity;
6
6
  uniform float bias;
7
7
  uniform float lengthCap;
8
- uniform float stepSize;
9
- uniform float frustumLength;
8
+ uniform int stepCount;
9
+ uniform int directionCount;
10
10
 
11
- vec3 pixelToEye(vec2 screenCoordinate)
11
+ vec4 pixelToEye(vec2 screenCoordinate)
12
12
  {
13
13
  vec2 uv = screenCoordinate / czm_viewport.zw;
14
14
  float depth = czm_readDepth(depthTexture, uv);
15
15
  vec2 xy = 2.0 * uv - vec2(1.0);
16
16
  vec4 posEC = czm_inverseProjection * vec4(xy, depth, 1.0);
17
- return posEC.xyz / posEC.w;
17
+ posEC = posEC / posEC.w;
18
+ // Avoid numerical error at far plane
19
+ if (depth >= 1.0) {
20
+ posEC.z = czm_currentFrustum.y;
21
+ }
22
+ return posEC;
18
23
  }
19
24
 
20
25
  // Reconstruct surface normal in eye coordinates, avoiding edges
@@ -22,10 +27,10 @@ vec3 getNormalXEdge(vec3 positionEC)
22
27
  {
23
28
  // Find the 3D surface positions at adjacent screen pixels
24
29
  vec2 centerCoord = gl_FragCoord.xy;
25
- vec3 positionLeft = pixelToEye(centerCoord + vec2(-1.0, 0.0));
26
- vec3 positionRight = pixelToEye(centerCoord + vec2(1.0, 0.0));
27
- vec3 positionUp = pixelToEye(centerCoord + vec2(0.0, 1.0));
28
- vec3 positionDown = pixelToEye(centerCoord + vec2(0.0, -1.0));
30
+ vec3 positionLeft = pixelToEye(centerCoord + vec2(-1.0, 0.0)).xyz;
31
+ vec3 positionRight = pixelToEye(centerCoord + vec2(1.0, 0.0)).xyz;
32
+ vec3 positionUp = pixelToEye(centerCoord + vec2(0.0, 1.0)).xyz;
33
+ vec3 positionDown = pixelToEye(centerCoord + vec2(0.0, -1.0)).xyz;
29
34
 
30
35
  // Compute potential tangent vectors
31
36
  vec3 dx0 = positionEC - positionLeft;
@@ -40,22 +45,35 @@ vec3 getNormalXEdge(vec3 positionEC)
40
45
  return normalize(cross(dx, dy));
41
46
  }
42
47
 
48
+ const float sqrtTwoPi = sqrt(czm_twoPi);
49
+
50
+ float gaussian(float x, float standardDeviation) {
51
+ float argument = x / standardDeviation;
52
+ return exp(-0.5 * argument * argument) / (sqrtTwoPi * standardDeviation);
53
+ }
54
+
43
55
  void main(void)
44
56
  {
45
- vec3 positionEC = pixelToEye(gl_FragCoord.xy);
57
+ vec4 positionEC = pixelToEye(gl_FragCoord.xy);
46
58
 
47
- if (positionEC.z > frustumLength)
59
+ // Exit if we are too close to the back of the frustum, where the depth value is invalid.
60
+ float maxValidDepth = czm_currentFrustum.y - lengthCap;
61
+ if (-positionEC.z > maxValidDepth)
48
62
  {
49
63
  out_FragColor = vec4(1.0);
50
64
  return;
51
65
  }
52
66
 
53
- vec3 normalEC = getNormalXEdge(positionEC);
67
+ vec3 normalEC = getNormalXEdge(positionEC.xyz);
68
+ float gaussianVariance = lengthCap * sqrt(-positionEC.z);
69
+ // Choose a step length such that the marching stops just before 3 * variance.
70
+ float stepLength = 3.0 * gaussianVariance / (float(stepCount) + 1.0);
71
+ float metersPerPixel = czm_metersPerPixel(positionEC, 1.0);
72
+ // Minimum step is 1 pixel to avoid double sampling
73
+ float pixelsPerStep = max(stepLength / metersPerPixel, 1.0);
74
+ stepLength = pixelsPerStep * metersPerPixel;
54
75
 
55
- float ao = 0.0;
56
-
57
- const int ANGLE_STEPS = 4;
58
- float angleStepScale = 1.0 / float(ANGLE_STEPS);
76
+ float angleStepScale = 1.0 / float(directionCount);
59
77
  float angleStep = angleStepScale * czm_twoPi;
60
78
  float cosStep = cos(angleStep);
61
79
  float sinStep = sin(angleStep);
@@ -67,48 +85,59 @@ void main(void)
67
85
  float randomVal = texture(randomTexture, randomTexCoord).x;
68
86
  vec2 sampleDirection = vec2(cos(angleStep * randomVal), sin(angleStep * randomVal));
69
87
 
88
+ float ao = 0.0;
70
89
  // Loop over sampling directions
71
- for (int i = 0; i < ANGLE_STEPS; i++)
90
+ #if __VERSION__ == 300
91
+ for (int i = 0; i < directionCount; i++)
92
+ {
93
+ #else
94
+ for (int i = 0; i < 16; i++)
72
95
  {
96
+ if (i >= directionCount) {
97
+ break;
98
+ }
99
+ #endif
73
100
  sampleDirection = rotateStep * sampleDirection;
74
101
 
75
102
  float localAO = 0.0;
76
- vec2 radialStep = stepSize * sampleDirection;
103
+ vec2 radialStep = pixelsPerStep * sampleDirection;
77
104
 
78
- for (int j = 0; j < 6; j++)
105
+ #if __VERSION__ == 300
106
+ for (int j = 0; j < stepCount; j++)
107
+ {
108
+ #else
109
+ for (int j = 0; j < 64; j++)
79
110
  {
111
+ if (j >= stepCount) {
112
+ break;
113
+ }
114
+ #endif
80
115
  // Step along sampling direction, away from output pixel
81
- vec2 newCoords = floor(gl_FragCoord.xy + float(j + 1) * radialStep) + vec2(0.5);
116
+ vec2 samplePixel = floor(gl_FragCoord.xy + float(j + 1) * radialStep) + vec2(0.5);
82
117
 
83
118
  // Exit if we stepped off the screen
84
- if (clamp(newCoords, vec2(0.0), czm_viewport.zw) != newCoords)
85
- {
119
+ if (clamp(samplePixel, vec2(0.0), czm_viewport.zw) != samplePixel) {
86
120
  break;
87
121
  }
88
122
 
89
- vec3 stepPositionEC = pixelToEye(newCoords);
90
- vec3 stepVector = stepPositionEC - positionEC;
91
- float stepLength = length(stepVector);
92
-
93
- if (stepLength > lengthCap)
94
- {
95
- break;
96
- }
123
+ // Compute step vector from output point to sampled point
124
+ vec4 samplePositionEC = pixelToEye(samplePixel);
125
+ vec3 stepVector = samplePositionEC.xyz - positionEC.xyz;
97
126
 
127
+ // Estimate the angle from the surface normal.
98
128
  float dotVal = clamp(dot(normalEC, normalize(stepVector)), 0.0, 1.0);
99
- if (dotVal < bias)
100
- {
101
- dotVal = 0.0;
102
- }
129
+ dotVal = czm_branchFreeTernary(dotVal > bias, dotVal, 0.0);
130
+ dotVal = czm_branchFreeTernary(-samplePositionEC.z <= maxValidDepth, dotVal, 0.0);
103
131
 
104
- float weight = stepLength / lengthCap;
105
- weight = 1.0 - weight * weight;
106
- localAO = max(localAO, dotVal * weight);
132
+ // Weight contribution based on the distance from the output point
133
+ float sampleDistance = length(stepVector);
134
+ float weight = gaussian(sampleDistance, gaussianVariance);
135
+ localAO += weight * dotVal;
107
136
  }
108
137
  ao += localAO;
109
138
  }
110
139
 
111
- ao *= angleStepScale;
140
+ ao *= angleStepScale * stepLength;
112
141
  ao = 1.0 - clamp(ao, 0.0, 1.0);
113
142
  ao = pow(ao, intensity);
114
143
  out_FragColor = vec4(vec3(ao), 1.0);
@@ -6,16 +6,21 @@ uniform sampler2D depthTexture;\n\
6
6
  uniform float intensity;\n\
7
7
  uniform float bias;\n\
8
8
  uniform float lengthCap;\n\
9
- uniform float stepSize;\n\
10
- uniform float frustumLength;\n\
9
+ uniform int stepCount;\n\
10
+ uniform int directionCount;\n\
11
11
  \n\
12
- vec3 pixelToEye(vec2 screenCoordinate)\n\
12
+ vec4 pixelToEye(vec2 screenCoordinate)\n\
13
13
  {\n\
14
14
  vec2 uv = screenCoordinate / czm_viewport.zw;\n\
15
15
  float depth = czm_readDepth(depthTexture, uv);\n\
16
16
  vec2 xy = 2.0 * uv - vec2(1.0);\n\
17
17
  vec4 posEC = czm_inverseProjection * vec4(xy, depth, 1.0);\n\
18
- return posEC.xyz / posEC.w;\n\
18
+ posEC = posEC / posEC.w;\n\
19
+ // Avoid numerical error at far plane\n\
20
+ if (depth >= 1.0) {\n\
21
+ posEC.z = czm_currentFrustum.y;\n\
22
+ }\n\
23
+ return posEC;\n\
19
24
  }\n\
20
25
  \n\
21
26
  // Reconstruct surface normal in eye coordinates, avoiding edges\n\
@@ -23,10 +28,10 @@ vec3 getNormalXEdge(vec3 positionEC)\n\
23
28
  {\n\
24
29
  // Find the 3D surface positions at adjacent screen pixels\n\
25
30
  vec2 centerCoord = gl_FragCoord.xy;\n\
26
- vec3 positionLeft = pixelToEye(centerCoord + vec2(-1.0, 0.0));\n\
27
- vec3 positionRight = pixelToEye(centerCoord + vec2(1.0, 0.0));\n\
28
- vec3 positionUp = pixelToEye(centerCoord + vec2(0.0, 1.0));\n\
29
- vec3 positionDown = pixelToEye(centerCoord + vec2(0.0, -1.0));\n\
31
+ vec3 positionLeft = pixelToEye(centerCoord + vec2(-1.0, 0.0)).xyz;\n\
32
+ vec3 positionRight = pixelToEye(centerCoord + vec2(1.0, 0.0)).xyz;\n\
33
+ vec3 positionUp = pixelToEye(centerCoord + vec2(0.0, 1.0)).xyz;\n\
34
+ vec3 positionDown = pixelToEye(centerCoord + vec2(0.0, -1.0)).xyz;\n\
30
35
  \n\
31
36
  // Compute potential tangent vectors\n\
32
37
  vec3 dx0 = positionEC - positionLeft;\n\
@@ -41,22 +46,35 @@ vec3 getNormalXEdge(vec3 positionEC)\n\
41
46
  return normalize(cross(dx, dy));\n\
42
47
  }\n\
43
48
  \n\
49
+ const float sqrtTwoPi = sqrt(czm_twoPi);\n\
50
+ \n\
51
+ float gaussian(float x, float standardDeviation) {\n\
52
+ float argument = x / standardDeviation;\n\
53
+ return exp(-0.5 * argument * argument) / (sqrtTwoPi * standardDeviation);\n\
54
+ }\n\
55
+ \n\
44
56
  void main(void)\n\
45
57
  {\n\
46
- vec3 positionEC = pixelToEye(gl_FragCoord.xy);\n\
58
+ vec4 positionEC = pixelToEye(gl_FragCoord.xy);\n\
47
59
  \n\
48
- if (positionEC.z > frustumLength)\n\
60
+ // Exit if we are too close to the back of the frustum, where the depth value is invalid.\n\
61
+ float maxValidDepth = czm_currentFrustum.y - lengthCap;\n\
62
+ if (-positionEC.z > maxValidDepth)\n\
49
63
  {\n\
50
64
  out_FragColor = vec4(1.0);\n\
51
65
  return;\n\
52
66
  }\n\
53
67
  \n\
54
- vec3 normalEC = getNormalXEdge(positionEC);\n\
68
+ vec3 normalEC = getNormalXEdge(positionEC.xyz);\n\
69
+ float gaussianVariance = lengthCap * sqrt(-positionEC.z);\n\
70
+ // Choose a step length such that the marching stops just before 3 * variance.\n\
71
+ float stepLength = 3.0 * gaussianVariance / (float(stepCount) + 1.0);\n\
72
+ float metersPerPixel = czm_metersPerPixel(positionEC, 1.0);\n\
73
+ // Minimum step is 1 pixel to avoid double sampling\n\
74
+ float pixelsPerStep = max(stepLength / metersPerPixel, 1.0);\n\
75
+ stepLength = pixelsPerStep * metersPerPixel;\n\
55
76
  \n\
56
- float ao = 0.0;\n\
57
- \n\
58
- const int ANGLE_STEPS = 4;\n\
59
- float angleStepScale = 1.0 / float(ANGLE_STEPS);\n\
77
+ float angleStepScale = 1.0 / float(directionCount);\n\
60
78
  float angleStep = angleStepScale * czm_twoPi;\n\
61
79
  float cosStep = cos(angleStep);\n\
62
80
  float sinStep = sin(angleStep);\n\
@@ -68,48 +86,59 @@ void main(void)\n\
68
86
  float randomVal = texture(randomTexture, randomTexCoord).x;\n\
69
87
  vec2 sampleDirection = vec2(cos(angleStep * randomVal), sin(angleStep * randomVal));\n\
70
88
  \n\
89
+ float ao = 0.0;\n\
71
90
  // Loop over sampling directions\n\
72
- for (int i = 0; i < ANGLE_STEPS; i++)\n\
91
+ #if __VERSION__ == 300\n\
92
+ for (int i = 0; i < directionCount; i++)\n\
93
+ {\n\
94
+ #else\n\
95
+ for (int i = 0; i < 16; i++)\n\
73
96
  {\n\
97
+ if (i >= directionCount) {\n\
98
+ break;\n\
99
+ }\n\
100
+ #endif\n\
74
101
  sampleDirection = rotateStep * sampleDirection;\n\
75
102
  \n\
76
103
  float localAO = 0.0;\n\
77
- vec2 radialStep = stepSize * sampleDirection;\n\
104
+ vec2 radialStep = pixelsPerStep * sampleDirection;\n\
78
105
  \n\
79
- for (int j = 0; j < 6; j++)\n\
106
+ #if __VERSION__ == 300\n\
107
+ for (int j = 0; j < stepCount; j++)\n\
108
+ {\n\
109
+ #else\n\
110
+ for (int j = 0; j < 64; j++)\n\
80
111
  {\n\
112
+ if (j >= stepCount) {\n\
113
+ break;\n\
114
+ }\n\
115
+ #endif\n\
81
116
  // Step along sampling direction, away from output pixel\n\
82
- vec2 newCoords = floor(gl_FragCoord.xy + float(j + 1) * radialStep) + vec2(0.5);\n\
117
+ vec2 samplePixel = floor(gl_FragCoord.xy + float(j + 1) * radialStep) + vec2(0.5);\n\
83
118
  \n\
84
119
  // Exit if we stepped off the screen\n\
85
- if (clamp(newCoords, vec2(0.0), czm_viewport.zw) != newCoords)\n\
86
- {\n\
120
+ if (clamp(samplePixel, vec2(0.0), czm_viewport.zw) != samplePixel) {\n\
87
121
  break;\n\
88
122
  }\n\
89
123
  \n\
90
- vec3 stepPositionEC = pixelToEye(newCoords);\n\
91
- vec3 stepVector = stepPositionEC - positionEC;\n\
92
- float stepLength = length(stepVector);\n\
93
- \n\
94
- if (stepLength > lengthCap)\n\
95
- {\n\
96
- break;\n\
97
- }\n\
124
+ // Compute step vector from output point to sampled point\n\
125
+ vec4 samplePositionEC = pixelToEye(samplePixel);\n\
126
+ vec3 stepVector = samplePositionEC.xyz - positionEC.xyz;\n\
98
127
  \n\
128
+ // Estimate the angle from the surface normal.\n\
99
129
  float dotVal = clamp(dot(normalEC, normalize(stepVector)), 0.0, 1.0);\n\
100
- if (dotVal < bias)\n\
101
- {\n\
102
- dotVal = 0.0;\n\
103
- }\n\
130
+ dotVal = czm_branchFreeTernary(dotVal > bias, dotVal, 0.0);\n\
131
+ dotVal = czm_branchFreeTernary(-samplePositionEC.z <= maxValidDepth, dotVal, 0.0);\n\
104
132
  \n\
105
- float weight = stepLength / lengthCap;\n\
106
- weight = 1.0 - weight * weight;\n\
107
- localAO = max(localAO, dotVal * weight);\n\
133
+ // Weight contribution based on the distance from the output point\n\
134
+ float sampleDistance = length(stepVector);\n\
135
+ float weight = gaussian(sampleDistance, gaussianVariance);\n\
136
+ localAO += weight * dotVal;\n\
108
137
  }\n\
109
138
  ao += localAO;\n\
110
139
  }\n\
111
140
  \n\
112
- ao *= angleStepScale;\n\
141
+ ao *= angleStepScale * stepLength;\n\
113
142
  ao = 1.0 - clamp(ao, 0.0, 1.0);\n\
114
143
  ao = pow(ao, intensity);\n\
115
144
  out_FragColor = vec4(vec3(ao), 1.0);\n\