Skip to content

Added a property for setting the amount of the vertex shadow attenuat… #10914

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

### engine

##### Additions :tada:

- Added `vertexShadowDarkness` parameter to `Globe` to control the amount of darkness of the vertex shadow when terrain lighting is enabled. [#10914](https://github.com/CesiumGS/cesium/pull/10914)

##### Fixes :wrench:

- Fixed a bug where the scale of a `PointPrimitive` was incorrect when `scaleByDistance` was set to a `NearFarScalar` [#10912](https://github.com/CesiumGS/cesium/pull/10912)
Expand Down
1 change: 1 addition & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -338,4 +338,5 @@ See [CONTRIBUTING.md](CONTRIBUTING.md) for details on how to contribute to Cesiu
- [Gabriel Aldous](https://github.com/Sn00pyW00dst0ck)
- [金俊](https://github.com/jinjun1994)
- [Oussama Bonnor](https://github.com/oussamabonnor1)
- [Calogero Mauceri](https://github.com/calogeromauceri)
- [Marcel Wendler](https://github.com/UniquePanda)
10 changes: 10 additions & 0 deletions packages/engine/Source/Scene/Globe.js
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,15 @@ function Globe(ellipsoid) {

this._oceanNormalMap = undefined;
this._zoomedOutOceanSpecularIntensity = undefined;

/**
* Determines the darkness of the vertex shadow.
* This only takes effect when <code>enableLighting</code> is <code>true</code>.
*
* @type {Number}
* @default 0.3
*/
this.vertexShadowDarkness = 0.3;
}

Object.defineProperties(Globe.prototype, {
Expand Down Expand Up @@ -1046,6 +1055,7 @@ Globe.prototype.beginFrame = function (frameState) {
tileProvider.fillHighlightColor = this.fillHighlightColor;
tileProvider.showSkirts = this.showSkirts;
tileProvider.backFaceCulling = this.backFaceCulling;
tileProvider.vertexShadowDarkness = this.vertexShadowDarkness;
tileProvider.undergroundColor = this._undergroundColor;
tileProvider.undergroundColorAlphaByDistance = this._undergroundColorAlphaByDistance;
tileProvider.lambertDiffuseMultiplier = this.lambertDiffuseMultiplier;
Expand Down
7 changes: 7 additions & 0 deletions packages/engine/Source/Scene/GlobeSurfaceTileProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ function GlobeSurfaceTileProvider(options) {
this.dynamicAtmosphereLightingFromSun = false;
this.showGroundAtmosphere = false;
this.shadows = ShadowMode.RECEIVE_ONLY;
this.vertexShadowDarkness = 0.3;

/**
* The color to use to highlight terrain fill tiles. If undefined, fill tiles are not
Expand Down Expand Up @@ -1785,6 +1786,9 @@ function createTileUniformMap(frameState, globeSurfaceTileProvider) {
u_lambertDiffuseMultiplier: function () {
return this.properties.lambertDiffuseMultiplier;
},
u_vertexShadowDarkness: function () {
return this.properties.vertexShadowDarkness;
},

// make a separate object so that changes to the properties are seen on
// derived commands that combine another uniform map with this one.
Expand Down Expand Up @@ -1846,6 +1850,7 @@ function createTileUniformMap(frameState, globeSurfaceTileProvider) {
undergroundColor: Color.clone(Color.TRANSPARENT),
undergroundColorAlphaByDistance: new Cartesian4(),
lambertDiffuseMultiplier: 0.0,
vertexShadowDarkness: 0.0,
},
};

Expand Down Expand Up @@ -2112,6 +2117,7 @@ function addDrawCommandsForTile(tileProvider, tile, frameState) {
undergroundColorAlphaByDistance.farValue > 0.0);

const lambertDiffuseMultiplier = tileProvider.lambertDiffuseMultiplier;
const vertexShadowDarkness = tileProvider.vertexShadowDarkness;

const showReflectiveOcean =
tileProvider.hasWaterMask && defined(waterMaskTexture);
Expand Down Expand Up @@ -2416,6 +2422,7 @@ function addDrawCommandsForTile(tileProvider, tile, frameState) {
Color.clone(undergroundColor, uniformMapProperties.undergroundColor);

uniformMapProperties.lambertDiffuseMultiplier = lambertDiffuseMultiplier;
uniformMapProperties.vertexShadowDarkness = vertexShadowDarkness;

const highlightFillTile =
!defined(surfaceTile.vertexArray) &&
Expand Down
3 changes: 2 additions & 1 deletion packages/engine/Source/Shaders/GlobeFS.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ uniform vec4 u_undergroundColorAlphaByDistance;

#ifdef ENABLE_VERTEX_LIGHTING
uniform float u_lambertDiffuseMultiplier;
uniform float u_vertexShadowDarkness;
#endif

varying vec3 v_positionMC;
Expand Down Expand Up @@ -405,7 +406,7 @@ void main()
#endif

#ifdef ENABLE_VERTEX_LIGHTING
float diffuseIntensity = clamp(czm_getLambertDiffuse(czm_lightDirectionEC, normalize(v_normalEC)) * u_lambertDiffuseMultiplier + 0.3, 0.0, 1.0);
float diffuseIntensity = clamp(czm_getLambertDiffuse(czm_lightDirectionEC, normalize(v_normalEC)) * u_lambertDiffuseMultiplier + u_vertexShadowDarkness, 0.0, 1.0);
vec4 finalColor = vec4(color.rgb * czm_lightColor * diffuseIntensity, color.a);
#elif defined(ENABLE_DAYNIGHT_SHADING)
float diffuseIntensity = clamp(czm_getLambertDiffuse(czm_lightDirectionEC, normalEC) * 5.0 + 0.3, 0.0, 1.0);
Expand Down
57 changes: 57 additions & 0 deletions packages/engine/Specs/Scene/GlobeSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,63 @@ describe(
});
});

it("renders terrain with vertexShadowDarkness", function () {
const renderOptions = {
scene: scene,
time: new JulianDate(2557522.0),
};
globe.enableLighting = true;

const layerCollection = globe.imageryLayers;
layerCollection.removeAll();
const imageryProvider = new SingleTileImageryProvider({
url: "Data/Images/Red16x16.png",
});
layerCollection.addImageryProvider(imageryProvider);
return imageryProvider.readyPromise.then(function () {
Resource._Implementations.loadWithXhr = function (
url,
responseType,
method,
data,
headers,
deferred,
overrideMimeType
) {
Resource._DefaultImplementations.loadWithXhr(
"Data/CesiumTerrainTileJson/tile.vertexnormals.terrain",
responseType,
method,
data,
headers,
deferred
);
};

returnVertexNormalTileJson();

const terrainProvider = new CesiumTerrainProvider({
url: "made/up/url",
requestVertexNormals: true,
});

globe.terrainProvider = terrainProvider;
scene.camera.setView({
destination: new Rectangle(0.0001, 0.0001, 0.0025, 0.0025),
});

return updateUntilDone(globe).then(function () {
let initialRgba;
expect(renderOptions).toRenderAndCall(function (rgba) {
initialRgba = rgba;
expect(renderOptions).notToRender([0, 0, 0, 255]);
globe.vertexShadowDarkness = 0.1;
expect(renderOptions).notToRender(initialRgba);
});
});
});
});

it("renders with hue shift", function () {
const layerCollection = globe.imageryLayers;
layerCollection.removeAll();
Expand Down