Skip to content

Commit 356b295

Browse files
authored
Merge pull request #4890 from rahwang/make-shadowMap-constructor-private
Making ShadowMap constructor private
2 parents 6d5376a + a143d82 commit 356b295

File tree

6 files changed

+63
-25
lines changed

6 files changed

+63
-25
lines changed

Apps/Sandcastle/gallery/development/Multiple Shadows.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
camera.lookAtTransform(Cesium.Matrix4.IDENTITY);
6565

6666
var shadowMap = new Cesium.ShadowMap({
67-
context : scene.context,
67+
scene : scene,
6868
lightCamera : pointLightCamera,
6969
isPointLight : true,
7070
softShadows : false

Apps/Sandcastle/gallery/development/Shadows.html

+5-5
Original file line numberDiff line numberDiff line change
@@ -410,30 +410,30 @@
410410

411411
if (lightSource === 'Fixed') {
412412
shadowOptions = {
413-
context : context,
413+
scene : scene,
414414
lightCamera : fixedLightCamera,
415415
cascadesEnabled : false
416416
};
417417
} else if (lightSource === 'Point') {
418418
shadowOptions = {
419-
context : context,
419+
scene : scene,
420420
lightCamera : pointLightCamera,
421421
isPointLight : true
422422
};
423423
} else if (lightSource === 'Spot') {
424424
shadowOptions = {
425-
context : context,
425+
scene : scene,
426426
lightCamera : spotLightCamera,
427427
cascadesEnabled : false
428428
};
429429
} else if (cascades === 4) {
430430
shadowOptions = {
431-
context : context,
431+
scene : scene,
432432
lightCamera : lightCamera
433433
};
434434
} else if (cascades === 1) {
435435
shadowOptions = {
436-
context : context,
436+
scene : scene,
437437
lightCamera : lightCamera,
438438
numberOfCascades : 1
439439
};

CHANGES.md

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Change Log
1010
* Removed separate `heading`, `pitch`, `roll` parameters from `Transform.headingPitchRollToFixedFrame` and `Transform.headingPitchRollQuaternion`. Pass a `headingPitchRoll` object instead. [#4843](https://github.com/AnalyticalGraphicsInc/cesium/pull/4843)
1111
* The property `binornmal` has been renamed to `bitangent` for `Geometry` and `VertexFormat`. [#4856](https://github.com/AnalyticalGraphicsInc/cesium/pull/4856)
1212
* A handful of `CesiumInspectorViewModel` properties were removed or changed from variables to functions. See [#4857](https://github.com/AnalyticalGraphicsInc/cesium/pull/4857)
13+
* The `ShadowMap` constructor has been made private. See [#4010](https://github.com/AnalyticalGraphicsInc/cesium/issues/4010)
1314
* Added support for custom geocoder services and autocomplete [#4723](https://github.com/AnalyticalGraphicsInc/cesium/pull/4723).
1415
* Added [Custom Geocoder Sandcastle example](http://localhost:8080/Apps/Sandcastle/index.html?src=Custom%20Geocoder.html)
1516
* Added `GeocoderService`, an interface for geocoders.

Source/Scene/Scene.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,7 @@ define([
563563
* @type {ShadowMap}
564564
*/
565565
this.shadowMap = new ShadowMap({
566-
context : context,
566+
scene : this,
567567
lightCamera : this._sunCamera,
568568
enabled : defaultValue(options.shadows, false)
569569
});

Source/Scene/ShadowMap.js

+33-7
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,15 @@ define([
107107

108108
/**
109109
* Creates a shadow map from the provided light camera.
110+
* <p>
111+
* Use {@link Viewer#shadowMap} to get the scene's shadow map originating from the sun. In general do not construct directly.
112+
* </p>
110113
*
111114
* The normalOffset bias pushes the shadows forward slightly, and may be disabled
112115
* for applications that require ultra precise shadows.
113116
*
114117
* @alias ShadowMap
115-
* @constructor
118+
* @internalConstructor
116119
*
117120
* @param {Object} options An object containing the following properties:
118121
* @param {Context} options.context The context in which to create the shadow map.
@@ -126,18 +129,19 @@ define([
126129
* @param {Number} [options.size=2048] The width and height, in pixels, of each shadow map.
127130
* @param {Boolean} [options.softShadows=false] Whether percentage-closer-filtering is enabled for producing softer shadows.
128131
* @param {Number} [options.darkness=0.3] The shadow darkness.
132+
* @param {Boolean} [options.normalOffset=true] Whether a normal bias is applied to shadows.
129133
*
130134
* @exception {DeveloperError} Only one or four cascades are supported.
131135
*
132136
* @demo {@link http://cesiumjs.org/Cesium/Apps/Sandcastle/index.html?src=Shadows.html|Cesium Sandcastle Shadows Demo}
133137
*/
134138
function ShadowMap(options) {
135139
options = defaultValue(options, defaultValue.EMPTY_OBJECT);
136-
var context = options.context;
140+
var scene = options.scene;
137141

138142
//>>includeStart('debug', pragmas.debug);
139-
if (!defined(context)) {
140-
throw new DeveloperError('context is required.');
143+
if (!defined(scene)) {
144+
throw new DeveloperError('scene is required.');
141145
}
142146
if (!defined(options.lightCamera)) {
143147
throw new DeveloperError('lightCamera is required.');
@@ -149,6 +153,7 @@ define([
149153

150154
this._enabled = defaultValue(options.enabled, true);
151155
this._softShadows = defaultValue(options.softShadows, false);
156+
this._normalOffset = defaultValue(options.normalOffset, true);
152157
this.dirty = true;
153158

154159
/**
@@ -183,6 +188,7 @@ define([
183188
// In IE11 and Edge polygon offset is not functional.
184189
// TODO : Also disabled for instances of Firefox and Chrome running ANGLE that do not support depth textures.
185190
// Re-enable once https://github.com/AnalyticalGraphicsInc/cesium/issues/4560 is resolved.
191+
var context = scene._context;
186192
var polygonOffsetSupported = true;
187193
if (FeatureDetection.isInternetExplorer() || FeatureDetection.isEdge() || ((FeatureDetection.isChrome() || FeatureDetection.isFirefox()) && FeatureDetection.isWindows() && !context.depthTexture)) {
188194
polygonOffsetSupported = false;
@@ -193,7 +199,7 @@ define([
193199
polygonOffset : polygonOffsetSupported,
194200
polygonOffsetFactor : 1.1,
195201
polygonOffsetUnits : 4.0,
196-
normalOffset : true,
202+
normalOffset : this._normalOffset,
197203
normalOffsetScale : 0.5,
198204
normalShading : true,
199205
normalShadingSmooth : 0.3,
@@ -204,7 +210,7 @@ define([
204210
polygonOffset : polygonOffsetSupported,
205211
polygonOffsetFactor : 1.1,
206212
polygonOffsetUnits : 4.0,
207-
normalOffset : true,
213+
normalOffset : this._normalOffset,
208214
normalOffsetScale : 0.1,
209215
normalShading : true,
210216
normalShadingSmooth : 0.05,
@@ -215,7 +221,7 @@ define([
215221
polygonOffset : false,
216222
polygonOffsetFactor : 1.1,
217223
polygonOffsetUnits : 4.0,
218-
normalOffset : false,
224+
normalOffset : this._normalOffset,
219225
normalOffsetScale : 0.0,
220226
normalShading : true,
221227
normalShadingSmooth : 0.1,
@@ -384,6 +390,26 @@ define([
384390
}
385391
},
386392

393+
/**
394+
* Determines if a normal bias will be applied to shadows.
395+
*
396+
* @memberof ShadowMap.prototype
397+
* @type {Boolean}
398+
* @default true
399+
*/
400+
normalOffset : {
401+
get : function() {
402+
return this._normalOffset;
403+
},
404+
set : function(value) {
405+
this.dirty = this._normalOffset !== value;
406+
this._normalOffset = value;
407+
this._terrainBias.normalOffset = value;
408+
this._primitiveBias.normalOffset = value;
409+
this._pointBias.normalOffset = value;
410+
}
411+
},
412+
387413
/**
388414
* Determines if soft shadows are enabled. Uses pcf filtering which requires more texture reads and may hurt performance.
389415
*

Specs/Scene/ShadowMapSpec.js

+22-11
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ defineSuite([
275275
lightCamera.lookAt(center, new Cartesian3(0.0, 0.0, 1.0));
276276

277277
scene.shadowMap = new ShadowMap({
278-
context : scene.context,
278+
scene : scene,
279279
lightCamera : lightCamera
280280
});
281281
}
@@ -289,7 +289,7 @@ defineSuite([
289289
lightCamera.lookAt(center, new Cartesian3(0.0, 0.0, 1.0));
290290

291291
scene.shadowMap = new ShadowMap({
292-
context : scene.context,
292+
scene : scene,
293293
lightCamera : lightCamera,
294294
numberOfCascades : 1
295295
});
@@ -313,7 +313,7 @@ defineSuite([
313313
lightCamera.lookAt(center, new Cartesian3(0.0, 0.0, 20.0));
314314

315315
scene.shadowMap = new ShadowMap({
316-
context : scene.context,
316+
scene : scene,
317317
lightCamera : lightCamera,
318318
cascadesEnabled : false
319319
});
@@ -331,7 +331,7 @@ defineSuite([
331331
lightCamera.lookAt(center, new Cartesian3(0.0, 0.0, 20.0));
332332

333333
scene.shadowMap = new ShadowMap({
334-
context : scene.context,
334+
scene : scene,
335335
lightCamera : lightCamera,
336336
cascadesEnabled : false
337337
});
@@ -345,7 +345,7 @@ defineSuite([
345345
lightCamera.position = center;
346346

347347
scene.shadowMap = new ShadowMap({
348-
context : scene.context,
348+
scene : scene,
349349
lightCamera : lightCamera,
350350
isPointLight : true
351351
});
@@ -390,7 +390,7 @@ defineSuite([
390390

391391
it('sets default shadow map properties', function() {
392392
scene.shadowMap = new ShadowMap({
393-
context : scene.context,
393+
scene : scene,
394394
lightCamera : new Camera(scene)
395395
});
396396

@@ -400,6 +400,7 @@ defineSuite([
400400
expect(scene.shadowMap._isSpotLight).toBe(false);
401401
expect(scene.shadowMap._cascadesEnabled).toBe(true);
402402
expect(scene.shadowMap._numberOfCascades).toBe(4);
403+
expect(scene.shadowMap._normalOffset).toBe(true);
403404
});
404405

405406
it('throws without options.context', function() {
@@ -413,15 +414,15 @@ defineSuite([
413414
it('throws without options.lightCamera', function() {
414415
expect(function() {
415416
scene.shadowMap = new ShadowMap({
416-
context : scene.context
417+
scene : scene
417418
});
418419
}).toThrowDeveloperError();
419420
});
420421

421422
it('throws when options.numberOfCascades is not one or four', function() {
422423
expect(function() {
423424
scene.shadowMap = new ShadowMap({
424-
context : scene.context,
425+
scene : scene,
425426
lightCamera : new Camera(scene),
426427
numberOfCascades : 3
427428
});
@@ -511,7 +512,7 @@ defineSuite([
511512
lightCamera.lookAt(center, new Cartesian3(1.0, 0.0, 0.1));
512513

513514
scene.shadowMap = new ShadowMap({
514-
context : scene.context,
515+
scene : scene,
515516
lightCamera : lightCamera
516517
});
517518

@@ -564,7 +565,7 @@ defineSuite([
564565
lightCamera.lookAt(center, new Cartesian3(0.0, 0.0, 1.0));
565566

566567
scene.shadowMap = new ShadowMap({
567-
context : scene.context,
568+
scene : scene,
568569
lightCamera : lightCamera
569570
});
570571

@@ -848,7 +849,7 @@ defineSuite([
848849
lightCamera.lookAt(center, new Cartesian3(0.0, 0.0, 1.0));
849850

850851
scene.shadowMap = new ShadowMap({
851-
context : scene.context,
852+
scene : scene,
852853
lightCamera : lightCamera
853854
});
854855

@@ -920,6 +921,16 @@ defineSuite([
920921
expect(shadowFar).toBeGreaterThan(shadowFarFit);
921922
});
922923

924+
it('set normalOffset', function() {
925+
createCascadedShadowMap();
926+
scene.shadowMap.normalOffset = false;
927+
928+
expect(scene.shadowMap._normalOffset, false);
929+
expect(scene.shadowMap._terrainBias, false);
930+
expect(scene.shadowMap._primitiveBias, false);
931+
expect(scene.shadowMap._pointBias, false);
932+
});
933+
923934
it('set maximumDistance', function() {
924935
box.show = true;
925936
floor.show = true;

0 commit comments

Comments
 (0)