Skip to content

Commit

Permalink
fix: ibl shader logic (#37)
Browse files Browse the repository at this point in the history
  • Loading branch information
keiya01 authored Aug 1, 2024
1 parent 34f8404 commit 5223560
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 27 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
"@typescript-eslint/eslint-plugin": "7.2.0",
"@typescript-eslint/parser": "7.2.0",
"@vitejs/plugin-react": "4.2.1",
"cesium": "1.116.0",
"cesium": "1.118.0",
"eslint": "8.57.0",
"eslint-config-reearth": "0.3.0",
"eslint-plugin-react-hooks": "4.6.0",
Expand Down
16 changes: 6 additions & 10 deletions src/engines/Cesium/Shaders/OverriddenShaders/GlobeFS/IBL.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
// https://github.com/CesiumGS/cesium/blob/1.106/packages/engine/Source/Shaders/Model/ImageBasedLightingStageFS.glsl
// Specular term was removed, as I never apply it on terrain.
vec3 reearth_imageBasedLightingStage(vec3 positionEC, vec3 normalEC,
vec3 lightDirectionEC, vec3 lightColorHdr,
czm_pbrParameters pbrParameters) {
vec3 lightDirectionEC, czm_modelMaterial material) {
vec3 v = -positionEC;
vec3 n = normalEC;
vec3 l = normalize(lightDirectionEC);
Expand All @@ -24,21 +23,18 @@ vec3 reearth_imageBasedLightingStage(vec3 positionEC, vec3 normalEC,
vec3 diffuseIrradiance =
czm_sphericalHarmonics(cubeDir, u_reearth_sphericalHarmonicCoefficients);

return pbrParameters.diffuseColor * diffuseIrradiance;
return material.diffuse * diffuseIrradiance;
}

vec4 reearth_computeImageBasedLightingColor(vec4 color) {
if (u_reearth_globeImageBasedLighting) {
czm_pbrParameters pbrParameters;
pbrParameters.diffuseColor = color.rgb;
czm_modelMaterial material;
material.diffuse = color.rgb;

vec3 normalEC = normalize(v_normalEC);
vec3 lighting =
czm_pbrLighting(v_positionEC, normalEC, czm_lightDirectionEC,
czm_lightColorHdr, pbrParameters);
lighting += reearth_imageBasedLightingStage(
v_positionEC, normalEC, czm_lightDirectionEC,
czm_lightColorHdr, pbrParameters) *
czm_pbrLighting(v_positionEC, normalEC, czm_lightDirectionEC, material) * czm_lightColorHdr;
lighting += reearth_imageBasedLightingStage(v_positionEC, normalEC, czm_lightDirectionEC, material) *
u_vertexShadowDarkness;

#ifndef HDR
Expand Down
2 changes: 1 addition & 1 deletion src/engines/Cesium/useOverrideGlobeShader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ const useTerrainHeatmap = ({
[
"#ifdef APPLY_COLOR_TO_ALPHA",
"vec3 colorDiff = abs(color.rgb - colorToAlpha.rgb);",
"colorDiff.r = max(max(colorDiff.r, colorDiff.g), colorDiff.b);",
"colorDiff.r = czm_maximumComponent(colorDiff);",
"alpha = czm_branchFreeTernary(colorDiff.r < colorToAlpha.a, 0.0, alpha);",
"#endif",
],
Expand Down
30 changes: 15 additions & 15 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1076,10 +1076,10 @@
resolved "https://registry.yarnpkg.com/@base2/pretty-print-object/-/pretty-print-object-1.0.1.tgz#371ba8be66d556812dc7fb169ebc3c08378f69d4"
integrity sha512-4iri8i1AqYHJE2DstZYkyEprg6Pq6sKx3xn5FpySk9sNhH7qN2LLlHJCfDTZRILNwQNPD7mATWM0TBui7uC1pA==

"@cesium/engine@^9.0.0":
version "9.0.0"
resolved "https://registry.yarnpkg.com/@cesium/engine/-/engine-9.0.0.tgz#74573f52100ef84ba5fcde9cd1084c07f7fe2fa7"
integrity sha512-GIeBitHo1t6OwgWnxAsCoHuCcJEfdki2G0hbKfaP87r2EapbnDLBmfxZziscl1ksv7kQiQ6x2FOOSPuV9QFvhA==
"@cesium/engine@^9.2.0":
version "9.2.0"
resolved "https://registry.yarnpkg.com/@cesium/engine/-/engine-9.2.0.tgz#6b92d422bf8fc9498e3f7a54851f6c4ebe7ff04f"
integrity sha512-vFVITo7UwIY1H8zK53etljv1w0CVaFSzOcLyItrM88r47zyPL7/RgooVKqZXnM5V8prs33S5TO/JSqJmvpyMTQ==
dependencies:
"@tweenjs/tween.js" "^23.1.1"
"@zip.js/zip.js" "^2.7.34"
Expand All @@ -1101,12 +1101,12 @@
topojson-client "^3.1.0"
urijs "^1.19.7"

"@cesium/widgets@^6.0.0":
version "6.0.0"
resolved "https://registry.yarnpkg.com/@cesium/widgets/-/widgets-6.0.0.tgz#be68f2b696bd6239cd37d63abd429e0608a9a0cb"
integrity sha512-zq0UqHji4PgPWTVdUB2hNb/FXe60eNDB11oW35/Z3REQfE4LBOkeR/RGck7hBOfYaubMiqwuwOw2lbl54OXzIA==
"@cesium/widgets@^6.1.0":
version "6.1.2"
resolved "https://registry.yarnpkg.com/@cesium/widgets/-/widgets-6.1.2.tgz#3eab3d8bf298b863d78a60c0ca5eaa177bffdab7"
integrity sha512-RNgogbRqlzjZxxG7icAUIDFZ0rm4OpHJ9b9lS/TGVm44PVVNG0Umhp4Tlf9U6r4ggwayKUkGV5dDIDa+pJGcVQ==
dependencies:
"@cesium/engine" "^9.0.0"
"@cesium/engine" "^9.2.0"
nosleep.js "^0.12.0"

"@chromatic-com/storybook@^1.3.3":
Expand Down Expand Up @@ -5246,13 +5246,13 @@ [email protected]:
resolved "https://registry.yarnpkg.com/cesium-dnd/-/cesium-dnd-1.1.0.tgz#30c7232eec9f84ad0d4f2c959cbd61ac29028086"
integrity sha512-Peo0bGIg5eOO/BrVDCovkPhQnWW3GBAjVnghh5NVmavDZjqS+A5R4Yj3IOG9tmYNSdtunsDqj5yxnMxQWx/KAA==

cesium@1.116.0:
version "1.116.0"
resolved "https://registry.yarnpkg.com/cesium/-/cesium-1.116.0.tgz#34c025babb49dfc4eeb98f9c83c37094a2083388"
integrity sha512-RZOOMePztCVb74JU/DTCTfuha7xTsJtEm3FRZeMUXyZABeRhbYjT1GwtAtoaPPJ5/IoqNjLvZnTNJdnU3LVE5g==
cesium@1.118.0:
version "1.118.0"
resolved "https://registry.yarnpkg.com/cesium/-/cesium-1.118.0.tgz#2c553131346799d3d3d1aec0a80b631b983ce224"
integrity sha512-au+WQ67bDZUw25kFFod/qtWfpxNoQPg2VQXU1XMr/64Gj1ZdvDSmuxO8sbum8tHieKDt9ER7JssSbefH/C3YSg==
dependencies:
"@cesium/engine" "^9.0.0"
"@cesium/widgets" "^6.0.0"
"@cesium/engine" "^9.2.0"
"@cesium/widgets" "^6.1.0"

chai@^4.3.10, chai@^4.4.1:
version "4.4.1"
Expand Down

0 comments on commit 5223560

Please sign in to comment.