From 1fd0bc896adc144bdf20e4d2f6f2dd36a383003d Mon Sep 17 00:00:00 2001 From: Calogero Mauceri Date: Mon, 24 May 2021 14:48:32 +0200 Subject: [PATCH 01/12] added flag for enabling/disabling shadows fading when the light source is close to the horizon --- Source/Scene/ShadowMap.js | 44 +++++++++++++++++++++++++++++++-------- 1 file changed, 35 insertions(+), 9 deletions(-) diff --git a/Source/Scene/ShadowMap.js b/Source/Scene/ShadowMap.js index 7a6138faf62a..4d1552f95660 100644 --- a/Source/Scene/ShadowMap.js +++ b/Source/Scene/ShadowMap.js @@ -69,6 +69,7 @@ import ShadowMapShader from "./ShadowMapShader.js"; * @param {Boolean} [options.softShadows=false] Whether percentage-closer-filtering is enabled for producing softer shadows. * @param {Number} [options.darkness=0.3] The shadow darkness. * @param {Boolean} [options.normalOffset=true] Whether a normal bias is applied to shadows. + * @param {Boolean} [options.fadingEnabled=true] Whether Shadows start to fade out once the light gets closer to the horizon. * * @exception {DeveloperError} Only one or four cascades are supported. * @@ -117,6 +118,14 @@ function ShadowMap(options) { this.darkness = defaultValue(options.darkness, 0.3); this._darkness = this.darkness; + /** + * Determines whether shadows start to fade out once the light gets closer to the horizon. + * + * @type {Boolean} + * @default true + */ + this.fadingEnabled = defaultValue(options.fadingEnabled, true); + /** * Determines the maximum distance of the shadow map. Only applicable for cascaded shadows. Larger distances may result in lower quality shadows. * @@ -483,6 +492,20 @@ Object.defineProperties(ShadowMap.prototype, { this._debugCascadeColors = value; }, }, + + /** + * The effective shadowmap darkness. It might differ from the shadow map darkness due to ligth close to the horizon + * + * @memberof ShadowMap.prototype + * @type {Number} + * @readonly + * @private + */ + effectiveDarkness: { + get: function () { + return this._darkness; + }, + }, }); function destroyFramebuffer(shadowMap) { @@ -1421,15 +1444,18 @@ function checkVisibility(shadowMap, frameState) { scratchCartesian2 ); var dot = Cartesian3.dot(surfaceNormal, lightDirection); - - // Shadows start to fade out once the light gets closer to the horizon. - // At this point the globe uses vertex lighting alone to darken the surface. - var darknessAmount = CesiumMath.clamp(dot / 0.1, 0.0, 1.0); - shadowMap._darkness = CesiumMath.lerp( - 1.0, - shadowMap.darkness, - darknessAmount - ); + if (shadowMap.fadingEnabled) { + // Shadows start to fade out once the light gets closer to the horizon. + // At this point the globe uses vertex lighting alone to darken the surface. + var darknessAmount = CesiumMath.clamp(dot / 0.1, 0.0, 1.0); + shadowMap._darkness = CesiumMath.lerp( + 1.0, + shadowMap.darkness, + darknessAmount + ); + } else { + shadowMap._darkness = shadowMap.darkness; + } if (dot < 0.0) { shadowMap._outOfView = true; From d0765bf2f37a87d06694099a758a5e6c07bc82fc Mon Sep 17 00:00:00 2001 From: Calogero Mauceri Date: Mon, 24 May 2021 14:52:20 +0200 Subject: [PATCH 02/12] added unit test for testing shadows fading disabled --- Specs/Scene/ShadowMapSpec.js | 42 ++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/Specs/Scene/ShadowMapSpec.js b/Specs/Scene/ShadowMapSpec.js index 3ed0885f74d5..01f957bca1c3 100644 --- a/Specs/Scene/ShadowMapSpec.js +++ b/Specs/Scene/ShadowMapSpec.js @@ -941,6 +941,48 @@ describe( }); }); + it("disable shadows fading", function () { + box.show = true; + floor.show = true; + + var center = new Cartesian3.fromRadians(longitude, latitude, height); + scene.camera.lookAt( + center, + new HeadingPitchRange(0.0, CesiumMath.toRadians(-70.0), 5.0) + ); + + // Create light camera pointing straight down + var lightCamera = new Camera(scene); + lightCamera.lookAt(center, new Cartesian3(0.0, 0.0, 1.0)); + + scene.shadowMap = new ShadowMap({ + context: scene.context, + lightCamera: lightCamera, + }); + + renderAndCall(function (rgba) { + expect(scene.shadowMap.effectiveDarkness).toBe( + scene.shadowMap.darkness + ); + }); + + // light low in the horizon + lightCamera.lookAt(center, new Cartesian3(1.0, 0.0, 0.01)); + renderAndCall(function (rgba) { + expect(scene.shadowMap.effectiveDarkness).not.toBe( + scene.shadowMap.darkness + ); + }); + + // disable shadows fading + scene.shadowMap.fadingEnabled = false; + renderAndCall(function (rgba) { + expect(scene.shadowMap.effectiveDarkness).toBe( + scene.shadowMap.darkness + ); + }); + }); + function depthFramebufferSupported() { var framebuffer = new Framebuffer({ context: scene.context, From 278fe9d107504ba325ededf12cc134b7eee5dc1e Mon Sep 17 00:00:00 2001 From: Calogero Mauceri Date: Mon, 24 May 2021 15:28:33 +0200 Subject: [PATCH 03/12] updated change with ShadowMap.fadingEnabled addition --- CHANGES.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 29526f3305d4..6c5ad4dccea2 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -6,6 +6,8 @@ - Added `FeatureDetection.supportsBigInt64Array`, `FeatureDetection.supportsBigUint64Array` and `FeatureDetection.supportsBigInt`. +- Added `ShadowMap.fadingEnabled` for disabling shadows fading when the light source is close to the horizon [#9565](https://github.com/CesiumGS/cesium/pull/9565) + ##### Fixes :wrench: - Fixed `processTerrain` in `decodeGoogleEarthEnterprisePacket` to handle a newer terrain packet format that includes water surface meshes after terrain meshes. [#9519](https://github.com/CesiumGS/cesium/pull/9519) From 494943f07596b7982a44639b8f4ce241df72197d Mon Sep 17 00:00:00 2001 From: Calogero Mauceri Date: Wed, 26 May 2021 10:08:12 +0200 Subject: [PATCH 04/12] Update CHANGES.md Co-authored-by: Eli Bogomolny <31491650+ebogo1@users.noreply.github.com> --- CHANGES.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index 6c5ad4dccea2..1dae7a2f964c 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -6,7 +6,7 @@ - Added `FeatureDetection.supportsBigInt64Array`, `FeatureDetection.supportsBigUint64Array` and `FeatureDetection.supportsBigInt`. -- Added `ShadowMap.fadingEnabled` for disabling shadows fading when the light source is close to the horizon [#9565](https://github.com/CesiumGS/cesium/pull/9565) +- Added `ShadowMap.fadingEnabled` to control whether shadows fade out when the light source is close to the horizon. [#9565](https://github.com/CesiumGS/cesium/pull/9565) ##### Fixes :wrench: From 7f2f895bc9221d6d1c3d4109986e4fad965e8975 Mon Sep 17 00:00:00 2001 From: Calogero Mauceri Date: Wed, 26 May 2021 17:46:37 +0200 Subject: [PATCH 05/12] removed unneeded effectiveDarkness getter --- Source/Scene/ShadowMap.js | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/Source/Scene/ShadowMap.js b/Source/Scene/ShadowMap.js index 4d1552f95660..8d951d7c56fb 100644 --- a/Source/Scene/ShadowMap.js +++ b/Source/Scene/ShadowMap.js @@ -492,20 +492,6 @@ Object.defineProperties(ShadowMap.prototype, { this._debugCascadeColors = value; }, }, - - /** - * The effective shadowmap darkness. It might differ from the shadow map darkness due to ligth close to the horizon - * - * @memberof ShadowMap.prototype - * @type {Number} - * @readonly - * @private - */ - effectiveDarkness: { - get: function () { - return this._darkness; - }, - }, }); function destroyFramebuffer(shadowMap) { From ddc4dc8f146450fb42efb90a59813d4422fe5d75 Mon Sep 17 00:00:00 2001 From: Calogero Mauceri Date: Wed, 26 May 2021 17:48:51 +0200 Subject: [PATCH 06/12] updated shadows fading unit test --- Specs/Scene/ShadowMapSpec.js | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/Specs/Scene/ShadowMapSpec.js b/Specs/Scene/ShadowMapSpec.js index 01f957bca1c3..78e01e2291d1 100644 --- a/Specs/Scene/ShadowMapSpec.js +++ b/Specs/Scene/ShadowMapSpec.js @@ -960,26 +960,20 @@ describe( lightCamera: lightCamera, }); - renderAndCall(function (rgba) { - expect(scene.shadowMap.effectiveDarkness).toBe( - scene.shadowMap.darkness - ); - }); + // Render with light looking straight down + var shadowedColor = renderAndReadPixels(); - // light low in the horizon + // Move the light close to the horizon lightCamera.lookAt(center, new Cartesian3(1.0, 0.0, 0.01)); - renderAndCall(function (rgba) { - expect(scene.shadowMap.effectiveDarkness).not.toBe( - scene.shadowMap.darkness - ); - }); - // disable shadows fading + // Render with faded shadows + var horizonShadowedColor = renderAndReadPixels(); + expect(horizonShadowedColor).not.toEqual(shadowedColor); + + // Render with unfaded shadows scene.shadowMap.fadingEnabled = false; renderAndCall(function (rgba) { - expect(scene.shadowMap.effectiveDarkness).toBe( - scene.shadowMap.darkness - ); + expect(rgba).not.toEqual(horizonShadowedColor); }); }); From eacbe244581ac5ce636f15f234a09b9dd3e2410b Mon Sep 17 00:00:00 2001 From: Calogero Mauceri Date: Thu, 27 May 2021 09:32:56 +0200 Subject: [PATCH 07/12] unit test title change --- Specs/Scene/ShadowMapSpec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Specs/Scene/ShadowMapSpec.js b/Specs/Scene/ShadowMapSpec.js index 78e01e2291d1..433d35437d31 100644 --- a/Specs/Scene/ShadowMapSpec.js +++ b/Specs/Scene/ShadowMapSpec.js @@ -941,7 +941,7 @@ describe( }); }); - it("disable shadows fading", function () { + it("disable shadows fade out", function () { box.show = true; floor.show = true; From d02cb91f76a7c6766976b4c74c30ab4cfaa5b28a Mon Sep 17 00:00:00 2001 From: Calogero Mauceri Date: Thu, 27 May 2021 17:26:46 +0200 Subject: [PATCH 08/12] modified unit test to avoid failure --- Specs/Scene/ShadowMapSpec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Specs/Scene/ShadowMapSpec.js b/Specs/Scene/ShadowMapSpec.js index 433d35437d31..c255bbbec15f 100644 --- a/Specs/Scene/ShadowMapSpec.js +++ b/Specs/Scene/ShadowMapSpec.js @@ -968,11 +968,11 @@ describe( // Render with faded shadows var horizonShadowedColor = renderAndReadPixels(); - expect(horizonShadowedColor).not.toEqual(shadowedColor); // Render with unfaded shadows scene.shadowMap.fadingEnabled = false; renderAndCall(function (rgba) { + expect(horizonShadowedColor).not.toEqual(shadowedColor); expect(rgba).not.toEqual(horizonShadowedColor); }); }); From 7ca2e06773d84790b6bdee8d11399079fd59265a Mon Sep 17 00:00:00 2001 From: Calogero Mauceri Date: Fri, 28 May 2021 09:13:50 +0200 Subject: [PATCH 09/12] Update Source/Scene/ShadowMap.js Co-authored-by: Eli Bogomolny <31491650+ebogo1@users.noreply.github.com> --- Source/Scene/ShadowMap.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Scene/ShadowMap.js b/Source/Scene/ShadowMap.js index 8d951d7c56fb..f1193ef94ae0 100644 --- a/Source/Scene/ShadowMap.js +++ b/Source/Scene/ShadowMap.js @@ -69,7 +69,7 @@ import ShadowMapShader from "./ShadowMapShader.js"; * @param {Boolean} [options.softShadows=false] Whether percentage-closer-filtering is enabled for producing softer shadows. * @param {Number} [options.darkness=0.3] The shadow darkness. * @param {Boolean} [options.normalOffset=true] Whether a normal bias is applied to shadows. - * @param {Boolean} [options.fadingEnabled=true] Whether Shadows start to fade out once the light gets closer to the horizon. + * @param {Boolean} [options.fadingEnabled=true] Whether shadows start to fade out once the light gets closer to the horizon. * * @exception {DeveloperError} Only one or four cascades are supported. * From 3e32dd536f74b01dfb56df748c78a88168c8f60a Mon Sep 17 00:00:00 2001 From: Calogero Mauceri Date: Fri, 28 May 2021 09:14:01 +0200 Subject: [PATCH 10/12] Update Specs/Scene/ShadowMapSpec.js Co-authored-by: Eli Bogomolny <31491650+ebogo1@users.noreply.github.com> --- Specs/Scene/ShadowMapSpec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Specs/Scene/ShadowMapSpec.js b/Specs/Scene/ShadowMapSpec.js index c255bbbec15f..01a86b116bb4 100644 --- a/Specs/Scene/ShadowMapSpec.js +++ b/Specs/Scene/ShadowMapSpec.js @@ -941,7 +941,7 @@ describe( }); }); - it("disable shadows fade out", function () { + it("disables shadow fading", function () { box.show = true; floor.show = true; From d4882cc6faaca222abb5a2938790b7d55a98a6d6 Mon Sep 17 00:00:00 2001 From: ebogo1 Date: Tue, 1 Jun 2021 18:09:29 -0400 Subject: [PATCH 11/12] update CHANGES.md to 1.83 release --- CHANGES.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 1dae7a2f964c..4906b4da67c5 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,13 +1,17 @@ # Change Log +### 1.83 - 2021-07-01 + +##### Additions :tada: + +- Added `ShadowMap.fadingEnabled` to control whether shadows fade out when the light source is close to the horizon. [#9565](https://github.com/CesiumGS/cesium/pull/9565) + ### 1.82 - 2021-06-01 ##### Additions :tada: - Added `FeatureDetection.supportsBigInt64Array`, `FeatureDetection.supportsBigUint64Array` and `FeatureDetection.supportsBigInt`. -- Added `ShadowMap.fadingEnabled` to control whether shadows fade out when the light source is close to the horizon. [#9565](https://github.com/CesiumGS/cesium/pull/9565) - ##### Fixes :wrench: - Fixed `processTerrain` in `decodeGoogleEarthEnterprisePacket` to handle a newer terrain packet format that includes water surface meshes after terrain meshes. [#9519](https://github.com/CesiumGS/cesium/pull/9519) From 081f0574c8c9fbf9aef55ce8a38fa0826dcfdb3d Mon Sep 17 00:00:00 2001 From: ebogo1 Date: Tue, 1 Jun 2021 18:11:06 -0400 Subject: [PATCH 12/12] change CHANGES.md wording --- CHANGES.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index 4906b4da67c5..f329d8c2b58a 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -4,7 +4,7 @@ ##### Additions :tada: -- Added `ShadowMap.fadingEnabled` to control whether shadows fade out when the light source is close to the horizon. [#9565](https://github.com/CesiumGS/cesium/pull/9565) +- Added `options.fadingEnabled` parameter to `ShadowMap` to control whether shadows fade out when the light source is close to the horizon. [#9565](https://github.com/CesiumGS/cesium/pull/9565) ### 1.82 - 2021-06-01