@cesium/engine 11.1.0 → 12.0.1
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/{chunk-U72QNFOJ.js → chunk-22FZ334F.js} +10 -10
- package/Build/Workers/{chunk-GNBFYG7F.js → chunk-2F42VIW6.js} +13 -13
- package/Build/Workers/{chunk-K4GQUNB5.js → chunk-2IJZVFHY.js} +5 -5
- package/Build/Workers/{chunk-7KTQP4VB.js → chunk-2XOUWNPN.js} +5 -5
- package/Build/Workers/{chunk-IBLIYJZR.js → chunk-3Y4UGAYI.js} +6 -6
- package/Build/Workers/{chunk-VJZB3WAV.js → chunk-54NYY4U4.js} +7 -7
- package/Build/Workers/{chunk-DHYHSFFJ.js → chunk-647NL6VU.js} +2 -2
- package/Build/Workers/{chunk-CKY7HOHV.js → chunk-76KRKKEF.js} +9 -9
- package/Build/Workers/{chunk-BHQJ2NT7.js → chunk-7CKQ7PVJ.js} +6 -6
- package/Build/Workers/{chunk-5PTXS2GO.js → chunk-7D6T2WYT.js} +7 -7
- package/Build/Workers/{chunk-PRGYLLJT.js → chunk-7EBHNJTG.js} +1 -1
- package/Build/Workers/{chunk-YFXQECWV.js → chunk-AER5CLXD.js} +5 -5
- package/Build/Workers/{chunk-N5KJGGCM.js → chunk-AGYO4ZSF.js} +17 -17
- package/Build/Workers/{chunk-VU2MNO7L.js → chunk-BH5M522L.js} +7 -7
- package/Build/Workers/{chunk-MXIZJAPH.js → chunk-COHL4R3G.js} +1 -1
- package/Build/Workers/{chunk-FIGIZHAQ.js → chunk-DJ7K7EYK.js} +11 -11
- package/Build/Workers/{chunk-3Q2L65QU.js → chunk-DR56WFYZ.js} +7 -7
- package/Build/Workers/{chunk-AD63PIY6.js → chunk-EMCXAVSG.js} +2 -2
- package/Build/Workers/{chunk-YSGTGQQO.js → chunk-ENARO52I.js} +14 -14
- package/Build/Workers/{chunk-5OOFQLKF.js → chunk-ETXXXGMP.js} +7 -7
- package/Build/Workers/{chunk-E27BLMDD.js → chunk-GBPW65E3.js} +6 -6
- package/Build/Workers/{chunk-NGPPMXRM.js → chunk-GRQQHWMD.js} +7 -7
- package/Build/Workers/{chunk-SMDOP47J.js → chunk-GSJ6LWIS.js} +10 -10
- package/Build/Workers/{chunk-26GA3JAM.js → chunk-H3RMGG7L.js} +5 -5
- package/Build/Workers/{chunk-PGRPDNHG.js → chunk-IAX6MIST.js} +17 -17
- package/Build/Workers/{chunk-5ODQSF26.js → chunk-IJWXYSFC.js} +2 -2
- package/Build/Workers/{chunk-C6YYBQXW.js → chunk-IVCFTVYW.js} +4 -4
- package/Build/Workers/{chunk-JW4FOI6M.js → chunk-JAKTB6CE.js} +11 -11
- package/Build/Workers/{chunk-TKVT5GQM.js → chunk-JPNFQRN7.js} +13 -13
- package/Build/Workers/{chunk-E63IIM5T.js → chunk-K7QC3WDT.js} +1 -1
- package/Build/Workers/{chunk-TGONEMZO.js → chunk-KJ65M35B.js} +11 -11
- package/Build/Workers/{chunk-2ZGOQXYU.js → chunk-KKMH4BKN.js} +6 -6
- package/Build/Workers/{chunk-76BYBWHP.js → chunk-LBNGHEJY.js} +4 -4
- package/Build/Workers/{chunk-XY4BATBS.js → chunk-LVHHB5T6.js} +4 -4
- package/Build/Workers/{chunk-S6MRMMQU.js → chunk-MV7YO647.js} +6 -6
- package/Build/Workers/{chunk-6CHGCNMW.js → chunk-NELAPOO6.js} +2 -2
- package/Build/Workers/{chunk-GESF4OXQ.js → chunk-NL73INJS.js} +2 -2
- package/Build/Workers/{chunk-GGZJN2TI.js → chunk-PH3T7LNP.js} +15 -15
- package/Build/Workers/{chunk-YZ733KKS.js → chunk-PISTPJXS.js} +12 -12
- package/Build/Workers/{chunk-GWCFU2SA.js → chunk-PJHRB4YJ.js} +7 -7
- package/Build/Workers/{chunk-I2ITFFPX.js → chunk-PNA47CR7.js} +1 -1
- package/Build/Workers/{chunk-7JO7GPJN.js → chunk-Q7IIOKAT.js} +1 -1
- package/Build/Workers/{chunk-27HUZ7SA.js → chunk-U7SH6OK7.js} +4 -4
- package/Build/Workers/{chunk-M3GMB5OP.js → chunk-VHGI7D3P.js} +10 -10
- package/Build/Workers/{chunk-FDOV2LBJ.js → chunk-VO4SXJXT.js} +7 -7
- package/Build/Workers/{chunk-7BMOHCPM.js → chunk-VXVQITFC.js} +13 -13
- package/Build/Workers/{chunk-DI5NGJUP.js → chunk-WMHJAREU.js} +2 -2
- package/Build/Workers/{chunk-EJZTDTUH.js → chunk-X6YBZOOA.js} +4 -4
- package/Build/Workers/{chunk-472HQ3EH.js → chunk-XDJ7V4NZ.js} +5 -5
- package/Build/Workers/{chunk-E6V6SQZW.js → chunk-YT5PQMSP.js} +6 -6
- package/Build/Workers/{chunk-O3E4OAOE.js → chunk-ZCCI55EY.js} +13 -13
- package/Build/Workers/{chunk-7O373FFS.js → chunk-ZPTNVB3S.js} +8 -8
- package/Build/Workers/combineGeometry.js +22 -22
- package/Build/Workers/createBoxGeometry.js +16 -16
- package/Build/Workers/createBoxOutlineGeometry.js +14 -14
- package/Build/Workers/createCircleGeometry.js +24 -24
- package/Build/Workers/createCircleOutlineGeometry.js +17 -17
- package/Build/Workers/createCoplanarPolygonGeometry.js +31 -31
- package/Build/Workers/createCoplanarPolygonOutlineGeometry.js +29 -29
- package/Build/Workers/createCorridorGeometry.js +27 -27
- package/Build/Workers/createCorridorOutlineGeometry.js +26 -26
- package/Build/Workers/createCylinderGeometry.js +18 -18
- package/Build/Workers/createCylinderOutlineGeometry.js +16 -16
- package/Build/Workers/createEllipseGeometry.js +24 -24
- package/Build/Workers/createEllipseOutlineGeometry.js +17 -17
- package/Build/Workers/createEllipsoidGeometry.js +17 -17
- package/Build/Workers/createEllipsoidOutlineGeometry.js +16 -16
- package/Build/Workers/createFrustumGeometry.js +16 -16
- package/Build/Workers/createFrustumOutlineGeometry.js +16 -16
- package/Build/Workers/createGeometry.js +22 -22
- package/Build/Workers/createGroundPolylineGeometry.js +20 -20
- package/Build/Workers/createPlaneGeometry.js +14 -14
- package/Build/Workers/createPlaneOutlineGeometry.js +13 -13
- package/Build/Workers/createPolygonGeometry.js +30 -30
- package/Build/Workers/createPolygonOutlineGeometry.js +28 -28
- package/Build/Workers/createPolylineGeometry.js +23 -23
- package/Build/Workers/createPolylineVolumeGeometry.js +29 -29
- package/Build/Workers/createPolylineVolumeOutlineGeometry.js +25 -25
- package/Build/Workers/createRectangleGeometry.js +25 -25
- package/Build/Workers/createRectangleOutlineGeometry.js +18 -18
- package/Build/Workers/createSimplePolylineGeometry.js +21 -21
- package/Build/Workers/createSphereGeometry.js +17 -17
- package/Build/Workers/createSphereOutlineGeometry.js +16 -16
- package/Build/Workers/createTaskProcessorWorker.js +3 -3
- package/Build/Workers/createVectorTileClampedPolylines.js +13 -13
- package/Build/Workers/createVectorTileGeometries.js +22 -22
- package/Build/Workers/createVectorTilePoints.js +12 -12
- package/Build/Workers/createVectorTilePolygons.js +20 -20
- package/Build/Workers/createVectorTilePolylines.js +13 -13
- package/Build/Workers/createVerticesFromGoogleEarthEnterpriseBuffer.js +20 -20
- package/Build/Workers/createVerticesFromHeightmap.js +20 -20
- package/Build/Workers/createVerticesFromQuantizedTerrainMesh.js +17 -17
- package/Build/Workers/createWallGeometry.js +22 -22
- package/Build/Workers/createWallOutlineGeometry.js +21 -21
- package/Build/Workers/decodeDraco.js +11 -11
- package/Build/Workers/decodeGoogleEarthEnterprisePacket.js +5 -5
- package/Build/Workers/decodeI3S.js +10 -10
- package/Build/Workers/transcodeKTX2.js +7 -7
- package/Build/Workers/transferTypedArrayTest.js +1 -1
- package/Build/Workers/upsampleQuantizedTerrainMesh.js +20 -20
- package/Source/Core/BoundingSphere.js +1 -1
- package/Source/Core/Color.js +1 -1
- package/Source/Core/CorridorGeometryLibrary.js +4 -4
- package/Source/Core/EllipseGeometry.js +1 -1
- package/Source/Core/EllipsoidGeodesic.js +1 -1
- package/Source/Core/FrustumGeometry.js +1 -1
- package/Source/Core/Ion.js +1 -1
- package/Source/Core/Math.js +2 -0
- package/Source/Core/PolylineVolumeGeometryLibrary.js +2 -2
- package/Source/Core/decodeGoogleEarthEnterpriseData.js +1 -1
- package/Source/DataSources/DataSourceDisplay.js +1 -1
- package/Source/DataSources/ModelGraphics.js +1 -0
- package/Source/Renderer/AutomaticUniforms.js +13 -0
- package/Source/Renderer/CubeMap.js +89 -12
- package/Source/Renderer/CubeMapFace.js +90 -13
- package/Source/Renderer/UniformState.js +13 -0
- package/Source/Scene/ArcGisMapService.js +1 -1
- package/Source/Scene/Atmosphere.js +22 -0
- package/Source/Scene/BingMapsImageryProvider.js +1 -1
- package/Source/Scene/Cesium3DTileset.js +39 -0
- package/Source/Scene/DynamicEnvironmentMapManager.js +894 -0
- package/Source/Scene/Fog.js +75 -82
- package/Source/Scene/FrameState.js +5 -3
- package/Source/Scene/ImageBasedLighting.js +7 -64
- package/Source/Scene/Model/AtmospherePipelineStage.js +10 -5
- package/Source/Scene/Model/ImageBasedLightingPipelineStage.js +43 -21
- package/Source/Scene/Model/Model.js +98 -25
- package/Source/Scene/Model/Model3DTileContent.js +5 -0
- package/Source/Scene/Model/ModelSceneGraph.js +1 -0
- package/Source/Scene/ScreenSpaceCameraController.js +20 -1
- package/Source/Shaders/Builtin/Functions/computeAtmosphereColor.glsl +44 -0
- package/Source/Shaders/Builtin/Functions/computeAtmosphereColor.js +44 -0
- package/Source/Shaders/Builtin/Functions/computeScattering.glsl +0 -1
- package/Source/Shaders/Builtin/Functions/computeScattering.js +0 -1
- package/Source/Shaders/Builtin/Functions/sphericalHarmonics.glsl +3 -1
- package/Source/Shaders/Builtin/Functions/sphericalHarmonics.js +3 -1
- package/Source/Shaders/ComputeIrradianceFS.glsl +103 -0
- package/Source/Shaders/ComputeIrradianceFS.js +105 -0
- package/Source/Shaders/ComputeRadianceMapFS.glsl +107 -0
- package/Source/Shaders/ComputeRadianceMapFS.js +109 -0
- package/Source/Shaders/ConvolveSpecularMapFS.glsl +70 -0
- package/Source/Shaders/ConvolveSpecularMapFS.js +72 -0
- package/Source/Shaders/ConvolveSpecularMapVS.glsl +24 -0
- package/Source/Shaders/ConvolveSpecularMapVS.js +26 -0
- package/Source/Shaders/GlobeFS.glsl +1 -2
- package/Source/Shaders/GlobeFS.js +1 -2
- package/Source/Shaders/Model/AtmosphereStageFS.glsl +1 -4
- package/Source/Shaders/Model/AtmosphereStageFS.js +1 -4
- package/Source/Shaders/Model/ImageBasedLightingStageFS.glsl +2 -155
- package/Source/Shaders/Model/ImageBasedLightingStageFS.js +3 -156
- package/Source/Shaders/Model/LightingStageFS.glsl +3 -22
- package/Source/Shaders/Model/LightingStageFS.js +3 -22
- package/Source/Shaders/SkyBoxVS.glsl +0 -1
- package/Source/Shaders/SkyBoxVS.js +0 -1
- package/Source/Widget/CesiumWidget.js +776 -1
- package/Source/Workers/decodeGoogleEarthEnterprisePacket.js +1 -1
- package/index.d.ts +281 -12
- package/index.js +62 -57
- package/package.json +2 -2
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
precision highp float;
|
|
2
|
+
|
|
3
|
+
in vec2 v_textureCoordinates;
|
|
4
|
+
|
|
5
|
+
uniform vec3 u_faceDirection; // Current cubemap face
|
|
6
|
+
uniform vec3 u_positionWC;
|
|
7
|
+
uniform mat4 u_enuToFixedFrame;
|
|
8
|
+
uniform vec4 u_brightnessSaturationGammaIntensity;
|
|
9
|
+
uniform vec4 u_groundColor; // alpha component represent albedo
|
|
10
|
+
|
|
11
|
+
vec4 getCubeMapDirection(vec2 uv, vec3 faceDir) {
|
|
12
|
+
vec2 scaledUV = uv * 2.0 - 1.0;
|
|
13
|
+
|
|
14
|
+
if (faceDir.x != 0.0) {
|
|
15
|
+
return vec4(faceDir.x, scaledUV.x * faceDir.x, -scaledUV.y, 0.0);
|
|
16
|
+
} else if (faceDir.y != 0.0) {
|
|
17
|
+
return vec4(scaledUV.x, -scaledUV.y * faceDir.y, faceDir.y, 0.0);
|
|
18
|
+
} else {
|
|
19
|
+
return vec4(scaledUV.x * faceDir.z, -faceDir.z, -scaledUV.y, 0.0);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
void main() {
|
|
24
|
+
float height = length(u_positionWC);
|
|
25
|
+
float atmosphereInnerRadius = u_radiiAndDynamicAtmosphereColor.y;
|
|
26
|
+
float ellipsoidHeight = max(height - atmosphereInnerRadius, 0.0);
|
|
27
|
+
|
|
28
|
+
// Scale the position to ensure the sky color is present, even when underground.
|
|
29
|
+
vec3 positionWC = u_positionWC / height * (ellipsoidHeight + atmosphereInnerRadius);
|
|
30
|
+
|
|
31
|
+
float atmosphereOuterRadius = u_radiiAndDynamicAtmosphereColor.x;
|
|
32
|
+
float atmosphereHeight = atmosphereOuterRadius - atmosphereInnerRadius;
|
|
33
|
+
|
|
34
|
+
vec3 direction = (u_enuToFixedFrame * getCubeMapDirection(v_textureCoordinates, u_faceDirection)).xyz;
|
|
35
|
+
vec3 normalizedDirection = normalize(direction);
|
|
36
|
+
|
|
37
|
+
czm_ray ray = czm_ray(positionWC, normalizedDirection);
|
|
38
|
+
czm_raySegment intersection = czm_raySphereIntersectionInterval(ray, vec3(0.0), atmosphereInnerRadius);
|
|
39
|
+
if (!czm_isEmpty(intersection)) {
|
|
40
|
+
intersection = czm_rayEllipsoidIntersectionInterval(ray, vec3(0.0), czm_ellipsoidInverseRadii);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
bool onEllipsoid = intersection.start >= 0.0;
|
|
44
|
+
float rayLength = czm_branchFreeTernary(onEllipsoid, intersection.start, atmosphereOuterRadius);
|
|
45
|
+
|
|
46
|
+
// Compute sky color for each position on a sphere at radius centered around the provided position's origin
|
|
47
|
+
vec3 skyPositionWC = positionWC + normalizedDirection * rayLength;
|
|
48
|
+
|
|
49
|
+
float lightEnum = u_radiiAndDynamicAtmosphereColor.z;
|
|
50
|
+
vec3 lightDirectionWC = normalize(czm_getDynamicAtmosphereLightDirection(skyPositionWC, lightEnum));
|
|
51
|
+
vec3 mieColor;
|
|
52
|
+
vec3 rayleighColor;
|
|
53
|
+
float opacity;
|
|
54
|
+
czm_computeScattering(
|
|
55
|
+
ray,
|
|
56
|
+
rayLength,
|
|
57
|
+
lightDirectionWC,
|
|
58
|
+
atmosphereInnerRadius,
|
|
59
|
+
rayleighColor,
|
|
60
|
+
mieColor,
|
|
61
|
+
opacity
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
vec4 atmopshereColor = czm_computeAtmosphereColor(ray, lightDirectionWC, rayleighColor, mieColor, opacity);
|
|
65
|
+
|
|
66
|
+
#ifdef ATMOSPHERE_COLOR_CORRECT
|
|
67
|
+
const bool ignoreBlackPixels = true;
|
|
68
|
+
atmopshereColor.rgb = czm_applyHSBShift(atmopshereColor.rgb, czm_atmosphereHsbShift, ignoreBlackPixels);
|
|
69
|
+
#endif
|
|
70
|
+
|
|
71
|
+
vec3 lookupDirection = -normalizedDirection;
|
|
72
|
+
// Flipping the X vector is a cheap way to get the inverse of czm_temeToPseudoFixed, since that's a rotation about Z.
|
|
73
|
+
lookupDirection.x = -lookupDirection.x;
|
|
74
|
+
lookupDirection = -normalize(czm_temeToPseudoFixed * lookupDirection);
|
|
75
|
+
lookupDirection.x = -lookupDirection.x;
|
|
76
|
+
|
|
77
|
+
// Values outside the atmopshere are rendered as black, when they should be treated as transparent
|
|
78
|
+
float skyAlpha = clamp((1.0 - ellipsoidHeight / atmosphereHeight) * atmopshereColor.a, 0.0, 1.0);
|
|
79
|
+
skyAlpha = czm_branchFreeTernary(length(atmopshereColor.rgb) <= czm_epsilon7, 0.0, skyAlpha); // Treat black as transparent
|
|
80
|
+
|
|
81
|
+
// Blend starmap with atmopshere scattering
|
|
82
|
+
float intensity = u_brightnessSaturationGammaIntensity.w;
|
|
83
|
+
vec4 sceneSkyBoxColor = czm_textureCube(czm_environmentMap, lookupDirection);
|
|
84
|
+
vec3 skyBackgroundColor = mix(czm_backgroundColor.rgb, sceneSkyBoxColor.rgb, sceneSkyBoxColor.a);
|
|
85
|
+
vec4 combinedSkyColor = vec4(mix(skyBackgroundColor, atmopshereColor.rgb * intensity, skyAlpha), 1.0);
|
|
86
|
+
|
|
87
|
+
// Compute ground color based on amount of reflected light, then blend it with ground atmosphere based on height
|
|
88
|
+
vec3 up = normalize(positionWC);
|
|
89
|
+
float occlusion = max(dot(lightDirectionWC, up), 0.05);
|
|
90
|
+
vec4 groundColor = vec4(u_groundColor.rgb * u_groundColor.a * (vec3(intensity * occlusion) + atmopshereColor.rgb), 1.0);
|
|
91
|
+
vec4 blendedGroundColor = mix(groundColor, atmopshereColor, clamp(ellipsoidHeight / atmosphereHeight, 0.0, 1.0));
|
|
92
|
+
|
|
93
|
+
vec4 color = czm_branchFreeTernary(onEllipsoid, blendedGroundColor, combinedSkyColor);
|
|
94
|
+
|
|
95
|
+
float brightness = u_brightnessSaturationGammaIntensity.x;
|
|
96
|
+
float saturation = u_brightnessSaturationGammaIntensity.y;
|
|
97
|
+
float gamma = u_brightnessSaturationGammaIntensity.z;
|
|
98
|
+
|
|
99
|
+
#ifdef ENVIRONMENT_COLOR_CORRECT
|
|
100
|
+
color.rgb = mix(vec3(0.0), color.rgb, brightness);
|
|
101
|
+
color.rgb = czm_saturation(color.rgb, saturation);
|
|
102
|
+
#endif
|
|
103
|
+
color.rgb = pow(color.rgb, vec3(gamma)); // Normally this would be in the ifdef above, but there is a precision issue with the atmopshere scattering transmittance (alpha). Having this line is a workaround for that issue, even when gamma is 1.0.
|
|
104
|
+
color.rgb = czm_gammaCorrect(color.rgb);
|
|
105
|
+
|
|
106
|
+
out_FragColor = color;
|
|
107
|
+
}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
//This file is automatically rebuilt by the Cesium build process.
|
|
2
|
+
export default "precision highp float;\n\
|
|
3
|
+
\n\
|
|
4
|
+
in vec2 v_textureCoordinates;\n\
|
|
5
|
+
\n\
|
|
6
|
+
uniform vec3 u_faceDirection; // Current cubemap face\n\
|
|
7
|
+
uniform vec3 u_positionWC;\n\
|
|
8
|
+
uniform mat4 u_enuToFixedFrame;\n\
|
|
9
|
+
uniform vec4 u_brightnessSaturationGammaIntensity;\n\
|
|
10
|
+
uniform vec4 u_groundColor; // alpha component represent albedo\n\
|
|
11
|
+
\n\
|
|
12
|
+
vec4 getCubeMapDirection(vec2 uv, vec3 faceDir) {\n\
|
|
13
|
+
vec2 scaledUV = uv * 2.0 - 1.0;\n\
|
|
14
|
+
\n\
|
|
15
|
+
if (faceDir.x != 0.0) {\n\
|
|
16
|
+
return vec4(faceDir.x, scaledUV.x * faceDir.x, -scaledUV.y, 0.0);\n\
|
|
17
|
+
} else if (faceDir.y != 0.0) {\n\
|
|
18
|
+
return vec4(scaledUV.x, -scaledUV.y * faceDir.y, faceDir.y, 0.0);\n\
|
|
19
|
+
} else {\n\
|
|
20
|
+
return vec4(scaledUV.x * faceDir.z, -faceDir.z, -scaledUV.y, 0.0); \n\
|
|
21
|
+
}\n\
|
|
22
|
+
}\n\
|
|
23
|
+
\n\
|
|
24
|
+
void main() { \n\
|
|
25
|
+
float height = length(u_positionWC);\n\
|
|
26
|
+
float atmosphereInnerRadius = u_radiiAndDynamicAtmosphereColor.y;\n\
|
|
27
|
+
float ellipsoidHeight = max(height - atmosphereInnerRadius, 0.0);\n\
|
|
28
|
+
\n\
|
|
29
|
+
// Scale the position to ensure the sky color is present, even when underground.\n\
|
|
30
|
+
vec3 positionWC = u_positionWC / height * (ellipsoidHeight + atmosphereInnerRadius);\n\
|
|
31
|
+
\n\
|
|
32
|
+
float atmosphereOuterRadius = u_radiiAndDynamicAtmosphereColor.x;\n\
|
|
33
|
+
float atmosphereHeight = atmosphereOuterRadius - atmosphereInnerRadius;\n\
|
|
34
|
+
\n\
|
|
35
|
+
vec3 direction = (u_enuToFixedFrame * getCubeMapDirection(v_textureCoordinates, u_faceDirection)).xyz;\n\
|
|
36
|
+
vec3 normalizedDirection = normalize(direction);\n\
|
|
37
|
+
\n\
|
|
38
|
+
czm_ray ray = czm_ray(positionWC, normalizedDirection);\n\
|
|
39
|
+
czm_raySegment intersection = czm_raySphereIntersectionInterval(ray, vec3(0.0), atmosphereInnerRadius);\n\
|
|
40
|
+
if (!czm_isEmpty(intersection)) {\n\
|
|
41
|
+
intersection = czm_rayEllipsoidIntersectionInterval(ray, vec3(0.0), czm_ellipsoidInverseRadii);\n\
|
|
42
|
+
}\n\
|
|
43
|
+
\n\
|
|
44
|
+
bool onEllipsoid = intersection.start >= 0.0;\n\
|
|
45
|
+
float rayLength = czm_branchFreeTernary(onEllipsoid, intersection.start, atmosphereOuterRadius);\n\
|
|
46
|
+
\n\
|
|
47
|
+
// Compute sky color for each position on a sphere at radius centered around the provided position's origin\n\
|
|
48
|
+
vec3 skyPositionWC = positionWC + normalizedDirection * rayLength;\n\
|
|
49
|
+
\n\
|
|
50
|
+
float lightEnum = u_radiiAndDynamicAtmosphereColor.z;\n\
|
|
51
|
+
vec3 lightDirectionWC = normalize(czm_getDynamicAtmosphereLightDirection(skyPositionWC, lightEnum));\n\
|
|
52
|
+
vec3 mieColor;\n\
|
|
53
|
+
vec3 rayleighColor;\n\
|
|
54
|
+
float opacity;\n\
|
|
55
|
+
czm_computeScattering(\n\
|
|
56
|
+
ray,\n\
|
|
57
|
+
rayLength,\n\
|
|
58
|
+
lightDirectionWC,\n\
|
|
59
|
+
atmosphereInnerRadius, \n\
|
|
60
|
+
rayleighColor,\n\
|
|
61
|
+
mieColor,\n\
|
|
62
|
+
opacity\n\
|
|
63
|
+
);\n\
|
|
64
|
+
\n\
|
|
65
|
+
vec4 atmopshereColor = czm_computeAtmosphereColor(ray, lightDirectionWC, rayleighColor, mieColor, opacity);\n\
|
|
66
|
+
\n\
|
|
67
|
+
#ifdef ATMOSPHERE_COLOR_CORRECT\n\
|
|
68
|
+
const bool ignoreBlackPixels = true;\n\
|
|
69
|
+
atmopshereColor.rgb = czm_applyHSBShift(atmopshereColor.rgb, czm_atmosphereHsbShift, ignoreBlackPixels);\n\
|
|
70
|
+
#endif\n\
|
|
71
|
+
\n\
|
|
72
|
+
vec3 lookupDirection = -normalizedDirection;\n\
|
|
73
|
+
// Flipping the X vector is a cheap way to get the inverse of czm_temeToPseudoFixed, since that's a rotation about Z.\n\
|
|
74
|
+
lookupDirection.x = -lookupDirection.x;\n\
|
|
75
|
+
lookupDirection = -normalize(czm_temeToPseudoFixed * lookupDirection);\n\
|
|
76
|
+
lookupDirection.x = -lookupDirection.x;\n\
|
|
77
|
+
\n\
|
|
78
|
+
// Values outside the atmopshere are rendered as black, when they should be treated as transparent\n\
|
|
79
|
+
float skyAlpha = clamp((1.0 - ellipsoidHeight / atmosphereHeight) * atmopshereColor.a, 0.0, 1.0);\n\
|
|
80
|
+
skyAlpha = czm_branchFreeTernary(length(atmopshereColor.rgb) <= czm_epsilon7, 0.0, skyAlpha); // Treat black as transparent\n\
|
|
81
|
+
\n\
|
|
82
|
+
// Blend starmap with atmopshere scattering\n\
|
|
83
|
+
float intensity = u_brightnessSaturationGammaIntensity.w;\n\
|
|
84
|
+
vec4 sceneSkyBoxColor = czm_textureCube(czm_environmentMap, lookupDirection);\n\
|
|
85
|
+
vec3 skyBackgroundColor = mix(czm_backgroundColor.rgb, sceneSkyBoxColor.rgb, sceneSkyBoxColor.a);\n\
|
|
86
|
+
vec4 combinedSkyColor = vec4(mix(skyBackgroundColor, atmopshereColor.rgb * intensity, skyAlpha), 1.0);\n\
|
|
87
|
+
\n\
|
|
88
|
+
// Compute ground color based on amount of reflected light, then blend it with ground atmosphere based on height\n\
|
|
89
|
+
vec3 up = normalize(positionWC);\n\
|
|
90
|
+
float occlusion = max(dot(lightDirectionWC, up), 0.05);\n\
|
|
91
|
+
vec4 groundColor = vec4(u_groundColor.rgb * u_groundColor.a * (vec3(intensity * occlusion) + atmopshereColor.rgb), 1.0);\n\
|
|
92
|
+
vec4 blendedGroundColor = mix(groundColor, atmopshereColor, clamp(ellipsoidHeight / atmosphereHeight, 0.0, 1.0));\n\
|
|
93
|
+
\n\
|
|
94
|
+
vec4 color = czm_branchFreeTernary(onEllipsoid, blendedGroundColor, combinedSkyColor);\n\
|
|
95
|
+
\n\
|
|
96
|
+
float brightness = u_brightnessSaturationGammaIntensity.x;\n\
|
|
97
|
+
float saturation = u_brightnessSaturationGammaIntensity.y;\n\
|
|
98
|
+
float gamma = u_brightnessSaturationGammaIntensity.z;\n\
|
|
99
|
+
\n\
|
|
100
|
+
#ifdef ENVIRONMENT_COLOR_CORRECT\n\
|
|
101
|
+
color.rgb = mix(vec3(0.0), color.rgb, brightness);\n\
|
|
102
|
+
color.rgb = czm_saturation(color.rgb, saturation);\n\
|
|
103
|
+
#endif\n\
|
|
104
|
+
color.rgb = pow(color.rgb, vec3(gamma)); // Normally this would be in the ifdef above, but there is a precision issue with the atmopshere scattering transmittance (alpha). Having this line is a workaround for that issue, even when gamma is 1.0.\n\
|
|
105
|
+
color.rgb = czm_gammaCorrect(color.rgb);\n\
|
|
106
|
+
\n\
|
|
107
|
+
out_FragColor = color;\n\
|
|
108
|
+
}\n\
|
|
109
|
+
";
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
precision highp float;
|
|
2
|
+
|
|
3
|
+
in vec3 v_textureCoordinates;
|
|
4
|
+
|
|
5
|
+
uniform float u_roughness;
|
|
6
|
+
uniform samplerCube u_radianceTexture;
|
|
7
|
+
uniform vec3 u_faceDirection;
|
|
8
|
+
|
|
9
|
+
float vdcRadicalInverse(int i)
|
|
10
|
+
{
|
|
11
|
+
float r;
|
|
12
|
+
float base = 2.0;
|
|
13
|
+
float value = 0.0;
|
|
14
|
+
float invBase = 1.0 / base;
|
|
15
|
+
float invBi = invBase;
|
|
16
|
+
for (int x = 0; x < 100; x++)
|
|
17
|
+
{
|
|
18
|
+
if (i <= 0)
|
|
19
|
+
{
|
|
20
|
+
break;
|
|
21
|
+
}
|
|
22
|
+
r = mod(float(i), base);
|
|
23
|
+
value += r * invBi;
|
|
24
|
+
invBi *= invBase;
|
|
25
|
+
i = int(float(i) * invBase);
|
|
26
|
+
}
|
|
27
|
+
return value;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
vec2 hammersley2D(int i, int N)
|
|
31
|
+
{
|
|
32
|
+
return vec2(float(i) / float(N), vdcRadicalInverse(i));
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
vec3 importanceSampleGGX(vec2 xi, float alphaRoughness, vec3 N)
|
|
36
|
+
{
|
|
37
|
+
float alphaRoughnessSquared = alphaRoughness * alphaRoughness;
|
|
38
|
+
float phi = czm_twoPi * xi.x;
|
|
39
|
+
float cosTheta = sqrt((1.0 - xi.y) / (1.0 + (alphaRoughnessSquared - 1.0) * xi.y));
|
|
40
|
+
float sinTheta = sqrt(1.0 - cosTheta * cosTheta);
|
|
41
|
+
vec3 H = vec3(sinTheta * cos(phi), sinTheta * sin(phi), cosTheta);
|
|
42
|
+
vec3 upVector = abs(N.z) < 0.999 ? vec3(0.0, 0.0, 1.0) : vec3(1.0, 0.0, 0.0);
|
|
43
|
+
vec3 tangentX = normalize(cross(upVector, N));
|
|
44
|
+
vec3 tangentY = cross(N, tangentX);
|
|
45
|
+
return tangentX * H.x + tangentY * H.y + N * H.z;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// Sample count is relatively low for the sake of performance, but should still be enough to prevent artifacting in lower roughnesses
|
|
49
|
+
const int samples = 128;
|
|
50
|
+
|
|
51
|
+
void main() {
|
|
52
|
+
vec3 normal = u_faceDirection;
|
|
53
|
+
vec3 V = normalize(v_textureCoordinates);
|
|
54
|
+
float roughness = u_roughness;
|
|
55
|
+
|
|
56
|
+
vec4 color = vec4(0.0);
|
|
57
|
+
float weight = 0.0;
|
|
58
|
+
for (int i = 0; i < samples; ++i) {
|
|
59
|
+
vec2 xi = hammersley2D(i, samples);
|
|
60
|
+
vec3 H = importanceSampleGGX(xi, roughness, V);
|
|
61
|
+
vec3 L = 2.0 * dot(V, H) * H - V; // reflected vector
|
|
62
|
+
|
|
63
|
+
float NdotL = max(dot(V, L), 0.0);
|
|
64
|
+
if (NdotL > 0.0) {
|
|
65
|
+
color += vec4(texture(u_radianceTexture, L).rgb, 1.0) * NdotL;
|
|
66
|
+
weight += NdotL;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
out_FragColor = color / weight;
|
|
70
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
//This file is automatically rebuilt by the Cesium build process.
|
|
2
|
+
export default "precision highp float;\n\
|
|
3
|
+
\n\
|
|
4
|
+
in vec3 v_textureCoordinates;\n\
|
|
5
|
+
\n\
|
|
6
|
+
uniform float u_roughness;\n\
|
|
7
|
+
uniform samplerCube u_radianceTexture;\n\
|
|
8
|
+
uniform vec3 u_faceDirection;\n\
|
|
9
|
+
\n\
|
|
10
|
+
float vdcRadicalInverse(int i)\n\
|
|
11
|
+
{\n\
|
|
12
|
+
float r;\n\
|
|
13
|
+
float base = 2.0;\n\
|
|
14
|
+
float value = 0.0;\n\
|
|
15
|
+
float invBase = 1.0 / base;\n\
|
|
16
|
+
float invBi = invBase;\n\
|
|
17
|
+
for (int x = 0; x < 100; x++)\n\
|
|
18
|
+
{\n\
|
|
19
|
+
if (i <= 0)\n\
|
|
20
|
+
{\n\
|
|
21
|
+
break;\n\
|
|
22
|
+
}\n\
|
|
23
|
+
r = mod(float(i), base);\n\
|
|
24
|
+
value += r * invBi;\n\
|
|
25
|
+
invBi *= invBase;\n\
|
|
26
|
+
i = int(float(i) * invBase);\n\
|
|
27
|
+
}\n\
|
|
28
|
+
return value;\n\
|
|
29
|
+
}\n\
|
|
30
|
+
\n\
|
|
31
|
+
vec2 hammersley2D(int i, int N)\n\
|
|
32
|
+
{\n\
|
|
33
|
+
return vec2(float(i) / float(N), vdcRadicalInverse(i));\n\
|
|
34
|
+
}\n\
|
|
35
|
+
\n\
|
|
36
|
+
vec3 importanceSampleGGX(vec2 xi, float alphaRoughness, vec3 N)\n\
|
|
37
|
+
{\n\
|
|
38
|
+
float alphaRoughnessSquared = alphaRoughness * alphaRoughness;\n\
|
|
39
|
+
float phi = czm_twoPi * xi.x;\n\
|
|
40
|
+
float cosTheta = sqrt((1.0 - xi.y) / (1.0 + (alphaRoughnessSquared - 1.0) * xi.y));\n\
|
|
41
|
+
float sinTheta = sqrt(1.0 - cosTheta * cosTheta);\n\
|
|
42
|
+
vec3 H = vec3(sinTheta * cos(phi), sinTheta * sin(phi), cosTheta);\n\
|
|
43
|
+
vec3 upVector = abs(N.z) < 0.999 ? vec3(0.0, 0.0, 1.0) : vec3(1.0, 0.0, 0.0);\n\
|
|
44
|
+
vec3 tangentX = normalize(cross(upVector, N));\n\
|
|
45
|
+
vec3 tangentY = cross(N, tangentX);\n\
|
|
46
|
+
return tangentX * H.x + tangentY * H.y + N * H.z;\n\
|
|
47
|
+
}\n\
|
|
48
|
+
\n\
|
|
49
|
+
// Sample count is relatively low for the sake of performance, but should still be enough to prevent artifacting in lower roughnesses\n\
|
|
50
|
+
const int samples = 128;\n\
|
|
51
|
+
\n\
|
|
52
|
+
void main() {\n\
|
|
53
|
+
vec3 normal = u_faceDirection;\n\
|
|
54
|
+
vec3 V = normalize(v_textureCoordinates);\n\
|
|
55
|
+
float roughness = u_roughness;\n\
|
|
56
|
+
\n\
|
|
57
|
+
vec4 color = vec4(0.0);\n\
|
|
58
|
+
float weight = 0.0;\n\
|
|
59
|
+
for (int i = 0; i < samples; ++i) {\n\
|
|
60
|
+
vec2 xi = hammersley2D(i, samples);\n\
|
|
61
|
+
vec3 H = importanceSampleGGX(xi, roughness, V);\n\
|
|
62
|
+
vec3 L = 2.0 * dot(V, H) * H - V; // reflected vector\n\
|
|
63
|
+
\n\
|
|
64
|
+
float NdotL = max(dot(V, L), 0.0);\n\
|
|
65
|
+
if (NdotL > 0.0) {\n\
|
|
66
|
+
color += vec4(texture(u_radianceTexture, L).rgb, 1.0) * NdotL;\n\
|
|
67
|
+
weight += NdotL;\n\
|
|
68
|
+
}\n\
|
|
69
|
+
}\n\
|
|
70
|
+
out_FragColor = color / weight;\n\
|
|
71
|
+
}\n\
|
|
72
|
+
";
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
in vec3 position;
|
|
2
|
+
out vec3 v_textureCoordinates;
|
|
3
|
+
|
|
4
|
+
uniform vec3 u_faceDirection;
|
|
5
|
+
|
|
6
|
+
vec3 getCubeMapDirection(vec2 uv, vec3 faceDir) {
|
|
7
|
+
vec2 scaledUV = uv;
|
|
8
|
+
|
|
9
|
+
if (faceDir.x != 0.0) {
|
|
10
|
+
return vec3(faceDir.x, scaledUV.y, scaledUV.x * faceDir.x);
|
|
11
|
+
} else if (faceDir.y != 0.0) {
|
|
12
|
+
return vec3(scaledUV.x, -faceDir.y, -scaledUV.y * faceDir.y);
|
|
13
|
+
} else {
|
|
14
|
+
return vec3(scaledUV.x * faceDir.z, scaledUV.y, -faceDir.z);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
void main()
|
|
19
|
+
{
|
|
20
|
+
v_textureCoordinates = getCubeMapDirection(position.xy, u_faceDirection);
|
|
21
|
+
v_textureCoordinates.y = -v_textureCoordinates.y;
|
|
22
|
+
v_textureCoordinates.z = -v_textureCoordinates.z;
|
|
23
|
+
gl_Position = vec4(position, 1.0);
|
|
24
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
//This file is automatically rebuilt by the Cesium build process.
|
|
2
|
+
export default "in vec3 position;\n\
|
|
3
|
+
out vec3 v_textureCoordinates;\n\
|
|
4
|
+
\n\
|
|
5
|
+
uniform vec3 u_faceDirection;\n\
|
|
6
|
+
\n\
|
|
7
|
+
vec3 getCubeMapDirection(vec2 uv, vec3 faceDir) {\n\
|
|
8
|
+
vec2 scaledUV = uv;\n\
|
|
9
|
+
\n\
|
|
10
|
+
if (faceDir.x != 0.0) {\n\
|
|
11
|
+
return vec3(faceDir.x, scaledUV.y, scaledUV.x * faceDir.x);\n\
|
|
12
|
+
} else if (faceDir.y != 0.0) {\n\
|
|
13
|
+
return vec3(scaledUV.x, -faceDir.y, -scaledUV.y * faceDir.y);\n\
|
|
14
|
+
} else {\n\
|
|
15
|
+
return vec3(scaledUV.x * faceDir.z, scaledUV.y, -faceDir.z); \n\
|
|
16
|
+
}\n\
|
|
17
|
+
}\n\
|
|
18
|
+
\n\
|
|
19
|
+
void main() \n\
|
|
20
|
+
{\n\
|
|
21
|
+
v_textureCoordinates = getCubeMapDirection(position.xy, u_faceDirection);\n\
|
|
22
|
+
v_textureCoordinates.y = -v_textureCoordinates.y;\n\
|
|
23
|
+
v_textureCoordinates.z = -v_textureCoordinates.z;\n\
|
|
24
|
+
gl_Position = vec4(position, 1.0);\n\
|
|
25
|
+
}\n\
|
|
26
|
+
";
|
|
@@ -499,8 +499,7 @@ void main()
|
|
|
499
499
|
fogColor.rgb = czm_inverseGamma(fogColor.rgb);
|
|
500
500
|
#endif
|
|
501
501
|
|
|
502
|
-
|
|
503
|
-
finalColor = vec4(czm_fog(v_distance, finalColor.rgb, fogColor.rgb, modifier), finalColor.a);
|
|
502
|
+
finalColor = vec4(czm_fog(v_distance, finalColor.rgb, fogColor.rgb, czm_fogVisualDensityScalar), finalColor.a);
|
|
504
503
|
|
|
505
504
|
#else
|
|
506
505
|
// Apply ground atmosphere. This happens when the camera is far away from the earth.
|
|
@@ -500,8 +500,7 @@ void main()\n\
|
|
|
500
500
|
fogColor.rgb = czm_inverseGamma(fogColor.rgb);\n\
|
|
501
501
|
#endif\n\
|
|
502
502
|
\n\
|
|
503
|
-
|
|
504
|
-
finalColor = vec4(czm_fog(v_distance, finalColor.rgb, fogColor.rgb, modifier), finalColor.a);\n\
|
|
503
|
+
finalColor = vec4(czm_fog(v_distance, finalColor.rgb, fogColor.rgb, czm_fogVisualDensityScalar), finalColor.a);\n\
|
|
505
504
|
\n\
|
|
506
505
|
#else\n\
|
|
507
506
|
// Apply ground atmosphere. This happens when the camera is far away from the earth.\n\
|
|
@@ -56,10 +56,7 @@ void applyFog(inout vec4 color, vec4 groundAtmosphereColor, vec3 lightDirection,
|
|
|
56
56
|
fogColor.rgb = czm_inverseGamma(fogColor.rgb);
|
|
57
57
|
#endif
|
|
58
58
|
|
|
59
|
-
|
|
60
|
-
// more gradual.
|
|
61
|
-
const float fogModifier = 0.15;
|
|
62
|
-
vec3 withFog = czm_fog(distanceToCamera, color.rgb, fogColor, fogModifier);
|
|
59
|
+
vec3 withFog = czm_fog(distanceToCamera, color.rgb, fogColor, czm_fogVisualDensityScalar);
|
|
63
60
|
color = vec4(withFog, color.a);
|
|
64
61
|
}
|
|
65
62
|
|
|
@@ -57,10 +57,7 @@ void applyFog(inout vec4 color, vec4 groundAtmosphereColor, vec3 lightDirection,
|
|
|
57
57
|
fogColor.rgb = czm_inverseGamma(fogColor.rgb);\n\
|
|
58
58
|
#endif\n\
|
|
59
59
|
\n\
|
|
60
|
-
|
|
61
|
-
// more gradual.\n\
|
|
62
|
-
const float fogModifier = 0.15;\n\
|
|
63
|
-
vec3 withFog = czm_fog(distanceToCamera, color.rgb, fogColor, fogModifier);\n\
|
|
60
|
+
vec3 withFog = czm_fog(distanceToCamera, color.rgb, fogColor, czm_fogVisualDensityScalar);\n\
|
|
64
61
|
color = vec4(withFog, color.a);\n\
|
|
65
62
|
}\n\
|
|
66
63
|
\n\
|
|
@@ -1,156 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Compute some metrics for a procedural sky lighting model
|
|
3
|
-
*
|
|
4
|
-
* @param {vec3} positionWC The position of the fragment in world coordinates.
|
|
5
|
-
* @param {vec3} reflectionWC A unit vector in the direction of the reflection, in world coordinates.
|
|
6
|
-
* @return {vec3} The dot products of the horizon and reflection directions with the nadir, and an atmosphere boundary distance.
|
|
7
|
-
*/
|
|
8
|
-
vec3 getProceduralSkyMetrics(vec3 positionWC, vec3 reflectionWC)
|
|
9
|
-
{
|
|
10
|
-
// Figure out if the reflection vector hits the ellipsoid
|
|
11
|
-
float horizonDotNadir = 1.0 - min(1.0, czm_ellipsoidRadii.x / length(positionWC));
|
|
12
|
-
float reflectionDotNadir = dot(reflectionWC, normalize(positionWC));
|
|
13
|
-
float atmosphereHeight = 0.05;
|
|
14
|
-
float smoothstepHeight = smoothstep(0.0, atmosphereHeight, horizonDotNadir);
|
|
15
|
-
return vec3(horizonDotNadir, reflectionDotNadir, smoothstepHeight);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Compute the diffuse irradiance for a procedural sky lighting model.
|
|
20
|
-
*
|
|
21
|
-
* @param {vec3} skyMetrics The dot products of the horizon and reflection directions with the nadir, and an atmosphere boundary distance.
|
|
22
|
-
* @return {vec3} The computed diffuse irradiance.
|
|
23
|
-
*/
|
|
24
|
-
vec3 getProceduralDiffuseIrradiance(vec3 skyMetrics)
|
|
25
|
-
{
|
|
26
|
-
vec3 blueSkyDiffuseColor = vec3(0.7, 0.85, 0.9);
|
|
27
|
-
float diffuseIrradianceFromEarth = (1.0 - skyMetrics.x) * (skyMetrics.y * 0.25 + 0.75) * skyMetrics.z;
|
|
28
|
-
float diffuseIrradianceFromSky = (1.0 - skyMetrics.z) * (1.0 - (skyMetrics.y * 0.25 + 0.25));
|
|
29
|
-
return blueSkyDiffuseColor * clamp(diffuseIrradianceFromEarth + diffuseIrradianceFromSky, 0.0, 1.0);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Compute the specular irradiance for a procedural sky lighting model.
|
|
34
|
-
*
|
|
35
|
-
* @param {vec3} reflectionWC The reflection vector in world coordinates.
|
|
36
|
-
* @param {vec3} skyMetrics The dot products of the horizon and reflection directions with the nadir, and an atmosphere boundary distance.
|
|
37
|
-
* @param {float} roughness The roughness of the material.
|
|
38
|
-
* @return {vec3} The computed specular irradiance.
|
|
39
|
-
*/
|
|
40
|
-
vec3 getProceduralSpecularIrradiance(vec3 reflectionWC, vec3 skyMetrics, float roughness)
|
|
41
|
-
{
|
|
42
|
-
// Flipping the X vector is a cheap way to get the inverse of czm_temeToPseudoFixed, since that's a rotation about Z.
|
|
43
|
-
reflectionWC.x = -reflectionWC.x;
|
|
44
|
-
reflectionWC = -normalize(czm_temeToPseudoFixed * reflectionWC);
|
|
45
|
-
reflectionWC.x = -reflectionWC.x;
|
|
46
|
-
|
|
47
|
-
float inverseRoughness = 1.0 - roughness;
|
|
48
|
-
inverseRoughness *= inverseRoughness;
|
|
49
|
-
vec3 sceneSkyBox = czm_textureCube(czm_environmentMap, reflectionWC).rgb * inverseRoughness;
|
|
50
|
-
|
|
51
|
-
// Compute colors at different angles relative to the horizon
|
|
52
|
-
vec3 belowHorizonColor = mix(vec3(0.1, 0.15, 0.25), vec3(0.4, 0.7, 0.9), skyMetrics.z);
|
|
53
|
-
vec3 nadirColor = belowHorizonColor * 0.5;
|
|
54
|
-
vec3 aboveHorizonColor = mix(vec3(0.9, 1.0, 1.2), belowHorizonColor, roughness * 0.5);
|
|
55
|
-
vec3 blueSkyColor = mix(vec3(0.18, 0.26, 0.48), aboveHorizonColor, skyMetrics.y * inverseRoughness * 0.5 + 0.75);
|
|
56
|
-
vec3 zenithColor = mix(blueSkyColor, sceneSkyBox, skyMetrics.z);
|
|
57
|
-
|
|
58
|
-
// Compute blend zones
|
|
59
|
-
float blendRegionSize = 0.1 * ((1.0 - inverseRoughness) * 8.0 + 1.1 - skyMetrics.x);
|
|
60
|
-
float blendRegionOffset = roughness * -1.0;
|
|
61
|
-
float farAboveHorizon = clamp(skyMetrics.x - blendRegionSize * 0.5 + blendRegionOffset, 1.0e-10 - blendRegionSize, 0.99999);
|
|
62
|
-
float aroundHorizon = clamp(skyMetrics.x + blendRegionSize * 0.5, 1.0e-10 - blendRegionSize, 0.99999);
|
|
63
|
-
float farBelowHorizon = clamp(skyMetrics.x + blendRegionSize * 1.5, 1.0e-10 - blendRegionSize, 0.99999);
|
|
64
|
-
|
|
65
|
-
// Blend colors
|
|
66
|
-
float notDistantRough = (1.0 - skyMetrics.x * roughness * 0.8);
|
|
67
|
-
vec3 specularIrradiance = mix(zenithColor, aboveHorizonColor, smoothstep(farAboveHorizon, aroundHorizon, skyMetrics.y) * notDistantRough);
|
|
68
|
-
specularIrradiance = mix(specularIrradiance, belowHorizonColor, smoothstep(aroundHorizon, farBelowHorizon, skyMetrics.y) * inverseRoughness);
|
|
69
|
-
specularIrradiance = mix(specularIrradiance, nadirColor, smoothstep(farBelowHorizon, 1.0, skyMetrics.y) * inverseRoughness);
|
|
70
|
-
|
|
71
|
-
return specularIrradiance;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
#ifdef USE_SUN_LUMINANCE
|
|
75
|
-
float clampedDot(vec3 x, vec3 y)
|
|
76
|
-
{
|
|
77
|
-
return clamp(dot(x, y), 0.001, 1.0);
|
|
78
|
-
}
|
|
79
|
-
/**
|
|
80
|
-
* Sun luminance following the "CIE Clear Sky Model"
|
|
81
|
-
* See page 40 of https://3dvar.com/Green2003Spherical.pdf
|
|
82
|
-
*
|
|
83
|
-
* @param {vec3} positionWC The position of the fragment in world coordinates.
|
|
84
|
-
* @param {vec3} normalEC The surface normal in eye coordinates.
|
|
85
|
-
* @param {vec3} lightDirectionEC Unit vector pointing to the light source in eye coordinates.
|
|
86
|
-
* @return {float} The computed sun luminance.
|
|
87
|
-
*/
|
|
88
|
-
float getSunLuminance(vec3 positionWC, vec3 normalEC, vec3 lightDirectionEC)
|
|
89
|
-
{
|
|
90
|
-
vec3 normalWC = normalize(czm_inverseViewRotation * normalEC);
|
|
91
|
-
vec3 lightDirectionWC = normalize(czm_inverseViewRotation * lightDirectionEC);
|
|
92
|
-
vec3 vWC = -normalize(positionWC);
|
|
93
|
-
|
|
94
|
-
// Angle between sun and zenith.
|
|
95
|
-
float LdotZenith = clampedDot(lightDirectionWC, vWC);
|
|
96
|
-
float S = acos(LdotZenith);
|
|
97
|
-
// Angle between zenith and current pixel
|
|
98
|
-
float NdotZenith = clampedDot(normalWC, vWC);
|
|
99
|
-
// Angle between sun and current pixel
|
|
100
|
-
float NdotL = clampedDot(normalEC, lightDirectionEC);
|
|
101
|
-
float gamma = acos(NdotL);
|
|
102
|
-
|
|
103
|
-
float numerator = ((0.91 + 10.0 * exp(-3.0 * gamma) + 0.45 * NdotL * NdotL) * (1.0 - exp(-0.32 / NdotZenith)));
|
|
104
|
-
float denominator = (0.91 + 10.0 * exp(-3.0 * S) + 0.45 * LdotZenith * LdotZenith) * (1.0 - exp(-0.32));
|
|
105
|
-
return model_luminanceAtZenith * (numerator / denominator);
|
|
106
|
-
}
|
|
107
|
-
#endif
|
|
108
|
-
|
|
109
|
-
/**
|
|
110
|
-
* Compute the light contribution from a procedural sky model
|
|
111
|
-
*
|
|
112
|
-
* @param {vec3} positionEC The position of the fragment in eye coordinates.
|
|
113
|
-
* @param {vec3} normalEC The surface normal in eye coordinates.
|
|
114
|
-
* @param {vec3} lightDirectionEC Unit vector pointing to the light source in eye coordinates.
|
|
115
|
-
* @param {czm_modelMaterial} The material properties.
|
|
116
|
-
* @return {vec3} The computed HDR color
|
|
117
|
-
*/
|
|
118
|
-
vec3 proceduralIBL(
|
|
119
|
-
vec3 positionEC,
|
|
120
|
-
vec3 normalEC,
|
|
121
|
-
vec3 lightDirectionEC,
|
|
122
|
-
czm_modelMaterial material
|
|
123
|
-
) {
|
|
124
|
-
vec3 viewDirectionEC = -normalize(positionEC);
|
|
125
|
-
vec3 positionWC = vec3(czm_inverseView * vec4(positionEC, 1.0));
|
|
126
|
-
vec3 reflectionWC = normalize(czm_inverseViewRotation * reflect(viewDirectionEC, normalEC));
|
|
127
|
-
vec3 skyMetrics = getProceduralSkyMetrics(positionWC, reflectionWC);
|
|
128
|
-
|
|
129
|
-
float roughness = material.roughness;
|
|
130
|
-
vec3 f0 = material.specular;
|
|
131
|
-
|
|
132
|
-
vec3 specularIrradiance = getProceduralSpecularIrradiance(reflectionWC, skyMetrics, roughness);
|
|
133
|
-
float NdotV = abs(dot(normalEC, viewDirectionEC)) + 0.001;
|
|
134
|
-
vec2 brdfLut = texture(czm_brdfLut, vec2(NdotV, roughness)).rg;
|
|
135
|
-
vec3 specularColor = czm_srgbToLinear(f0 * brdfLut.x + brdfLut.y);
|
|
136
|
-
vec3 specularContribution = specularIrradiance * specularColor * model_iblFactor.y;
|
|
137
|
-
#ifdef USE_SPECULAR
|
|
138
|
-
specularContribution *= material.specularWeight;
|
|
139
|
-
#endif
|
|
140
|
-
|
|
141
|
-
vec3 diffuseIrradiance = getProceduralDiffuseIrradiance(skyMetrics);
|
|
142
|
-
vec3 diffuseColor = material.diffuse;
|
|
143
|
-
vec3 diffuseContribution = diffuseIrradiance * diffuseColor * model_iblFactor.x;
|
|
144
|
-
|
|
145
|
-
vec3 iblColor = specularContribution + diffuseContribution;
|
|
146
|
-
|
|
147
|
-
#ifdef USE_SUN_LUMINANCE
|
|
148
|
-
iblColor *= getSunLuminance(positionWC, normalEC, lightDirectionEC);
|
|
149
|
-
#endif
|
|
150
|
-
|
|
151
|
-
return iblColor;
|
|
152
|
-
}
|
|
153
|
-
|
|
154
1
|
#ifdef DIFFUSE_IBL
|
|
155
2
|
vec3 sampleDiffuseEnvironment(vec3 cubeDir)
|
|
156
3
|
{
|
|
@@ -223,7 +70,7 @@ vec3 textureIBL(vec3 viewDirectionEC, vec3 normalEC, czm_modelMaterial material)
|
|
|
223
70
|
float Ems = specularWeight * (1.0 - brdfLut.x - brdfLut.y);
|
|
224
71
|
vec3 FmsEms = FssEss * averageFresnel * Ems / (1.0 - averageFresnel * Ems);
|
|
225
72
|
vec3 dielectricScattering = (1.0 - FssEss - FmsEms) * material.diffuse;
|
|
226
|
-
vec3 diffuseContribution = irradiance * (FmsEms + dielectricScattering);
|
|
73
|
+
vec3 diffuseContribution = irradiance * (FmsEms + dielectricScattering) * model_iblFactor.x;
|
|
227
74
|
#else
|
|
228
75
|
vec3 diffuseContribution = vec3(0.0);
|
|
229
76
|
#endif
|
|
@@ -244,7 +91,7 @@ vec3 textureIBL(vec3 viewDirectionEC, vec3 normalEC, czm_modelMaterial material)
|
|
|
244
91
|
#ifdef SPECULAR_IBL
|
|
245
92
|
vec3 reflectMC = normalize(model_iblReferenceFrameMatrix * reflectEC);
|
|
246
93
|
vec3 radiance = sampleSpecularEnvironment(reflectMC, roughness);
|
|
247
|
-
vec3 specularContribution = radiance * FssEss;
|
|
94
|
+
vec3 specularContribution = radiance * FssEss * model_iblFactor.y;
|
|
248
95
|
#else
|
|
249
96
|
vec3 specularContribution = vec3(0.0);
|
|
250
97
|
#endif
|