Skip to content
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

Shadows for Primitive entities #3928

Closed
wants to merge 4 commits into from
Closed
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
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Change Log
### Shadows TODO
* Added shadows
* Added `Viewer.shadows` and `Viewer.terrainShadows`. Both are disabled by default.
* Added `castShadows` and `receiveShadows` properties to the entity API for models, boxes, corridors, cylinders, ellipses, ellipsoids, polygons, polylines, polyline volumes, rectangles, and walls.
* Added `castShadows` and `receiveShadows` properties to `Primitive`, and options to the `Primitive` constructor.
* Added `castShadows` and `receiveShadows` properties to `Model`, and options to the `Model` constructor and `Model.fromGltf`.
* Added `castShadows` and `receiveShadows` properties to `Globe`.
Expand Down
43 changes: 41 additions & 2 deletions Source/DataSources/BoxGeometryUpdater.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ define([
var defaultFill = new ConstantProperty(true);
var defaultOutline = new ConstantProperty(false);
var defaultOutlineColor = new ConstantProperty(Color.BLACK);
var defaultCastShadows = new ConstantProperty(false);
var defaultReceiveShadows = new ConstantProperty(false);
var scratchColor = new Color();

function GeometryOptions(entity) {
Expand Down Expand Up @@ -90,6 +92,8 @@ define([
this._showOutlineProperty = undefined;
this._outlineColorProperty = undefined;
this._outlineWidth = 1.0;
this._castShadowsProperty = undefined;
this._receiveShadowsProperty = undefined;
this._options = new GeometryOptions(entity);
this._onEntityPropertyChanged(entity, 'box', entity.box, undefined);
}
Expand Down Expand Up @@ -217,6 +221,32 @@ define([
return this._outlineWidth;
}
},
/**
* Gets the boolean property specifying whether the geometry
* casts shadows from each light source.
* @memberof BoxGeometryUpdater.prototype
*
* @type {Property}
* @readonly
*/
castShadowsProperty : {
get : function() {
return this._castShadowsProperty;
}
},
/**
* Gets the boolean Property specifying whether the geometry
* receives shadows from shadow casters in the scene.
* @memberof BoxGeometryUpdater.prototype
*
* @type {Property}
* @readonly
*/
receiveShadowsProperty : {
get : function() {
return this._receiveShadowsProperty;
}
},
/**
* Gets a value indicating if the geometry is time-varying.
* If true, all visualization is delegated to the {@link DynamicGeometryUpdater}
Expand Down Expand Up @@ -436,6 +466,8 @@ define([
this._showProperty = defaultValue(show, defaultShow);
this._showOutlineProperty = defaultValue(box.outline, defaultOutline);
this._outlineColorProperty = outlineEnabled ? defaultValue(box.outlineColor, defaultOutlineColor) : undefined;
this._castShadowsProperty = defaultValue(box.castShadows, defaultCastShadows);
this._receiveShadowsProperty = defaultValue(box.receiveShadows, defaultReceiveShadows);

var outlineWidth = box.outlineWidth;

Expand Down Expand Up @@ -521,6 +553,9 @@ define([

options.dimensions = dimensions;

var castShadows = this._geometryUpdater.castShadowsProperty.getValue(time);
var receiveShadows = this._geometryUpdater.receiveShadowsProperty.getValue(time);

if (Property.getValueOrDefault(box.fill, time, true)) {
var material = MaterialProperty.getValue(time, geometryUpdater.fillMaterialProperty, this._material);
this._material = material;
Expand All @@ -539,7 +574,9 @@ define([
modelMatrix : modelMatrix
}),
appearance : appearance,
asynchronous : false
asynchronous : false,
castShadows : castShadows,
receiveShadows : receiveShadows
}));
}

Expand All @@ -566,7 +603,9 @@ define([
lineWidth : geometryUpdater._scene.clampLineWidth(outlineWidth)
}
}),
asynchronous : false
asynchronous : false,
castShadows : castShadows,
receiveShadows : receiveShadows
}));
}
};
Expand Down
30 changes: 29 additions & 1 deletion Source/DataSources/BoxGraphics.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ define([
* @param {Property} [options.outline=false] A boolean Property specifying whether the box is outlined.
* @param {Property} [options.outlineColor=Color.BLACK] A Property specifying the {@link Color} of the outline.
* @param {Property} [options.outlineWidth=1.0] A numeric Property specifying the width of the outline.
* @param {Property} [options.castShadows=false] A boolean Property specifying whether the box casts shadows from each light source.
* @param {Property} [options.receiveShadows=false] A boolean Property specifying whether the box receives shadows from shadow casters in the scene.
*
* @demo {@link http://cesiumjs.org/Cesium/Apps/Sandcastle/index.html?src=Box.html|Cesium Sandcastle Box Demo}
*/
Expand All @@ -49,6 +51,10 @@ define([
this._outlineColorSubscription = undefined;
this._outlineWidth = undefined;
this._outlineWidthSubscription = undefined;
this._castShadows = undefined;
this._castShadowsSubscription = undefined;
this._receiveShadows = undefined;
this._receiveShadowsSubscription = undefined;
this._definitionChanged = new Event();

this.merge(defaultValue(options, defaultValue.EMPTY_OBJECT));
Expand Down Expand Up @@ -120,7 +126,25 @@ define([
* @type {Property}
* @default 1.0
*/
outlineWidth : createPropertyDescriptor('outlineWidth')
outlineWidth : createPropertyDescriptor('outlineWidth'),

/**
* Get or sets the boolean Property specifying whether the box
* casts shadows from each light source.
* @memberof BoxGraphics.prototype
* @type {Property}
* @default false
*/
castShadows : createPropertyDescriptor('castShadows'),

/**
* Get or sets the boolean Property specifying whether the box
* receives shadows from shadow casters in the scene.
* @memberof BoxGraphics.prototype
* @type {Property}
* @default false
*/
receiveShadows : createPropertyDescriptor('receiveShadows')
});

/**
Expand All @@ -140,6 +164,8 @@ define([
result.outline = this.outline;
result.outlineColor = this.outlineColor;
result.outlineWidth = this.outlineWidth;
result.castShadows = this.castShadows;
result.receiveShadows = this.receiveShadows;
return result;
};

Expand All @@ -163,6 +189,8 @@ define([
this.outline = defaultValue(this.outline, source.outline);
this.outlineColor = defaultValue(this.outlineColor, source.outlineColor);
this.outlineWidth = defaultValue(this.outlineWidth, source.outlineWidth);
this.castShadows = defaultValue(this.castShadows, source.castShadows);
this.receiveShadows = defaultValue(this.receiveShadows, source.receiveShadows);
};

return BoxGraphics;
Expand Down
43 changes: 41 additions & 2 deletions Source/DataSources/CorridorGeometryUpdater.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ define([
var defaultFill = new ConstantProperty(true);
var defaultOutline = new ConstantProperty(false);
var defaultOutlineColor = new ConstantProperty(Color.BLACK);
var defaultCastShadows = new ConstantProperty(false);
var defaultReceiveShadows = new ConstantProperty(false);
var scratchColor = new Color();

function GeometryOptions(entity) {
Expand Down Expand Up @@ -96,6 +98,8 @@ define([
this._showOutlineProperty = undefined;
this._outlineColorProperty = undefined;
this._outlineWidth = 1.0;
this._castShadowsProperty = undefined;
this._receiveShadowsProperty = undefined;
this._options = new GeometryOptions(entity);
this._onEntityPropertyChanged(entity, 'corridor', entity.corridor, undefined);
}
Expand Down Expand Up @@ -223,6 +227,32 @@ define([
return this._outlineWidth;
}
},
/**
* Gets the boolean property specifying whether the geometry
* casts shadows from each light source.
* @memberof CorridorGeometryUpdater.prototype
*
* @type {Property}
* @readonly
*/
castShadowsProperty : {
get : function() {
return this._castShadowsProperty;
}
},
/**
* Gets the boolean Property specifying whether the geometry
* receives shadows from shadow casters in the scene.
* @memberof CorridorGeometryUpdater.prototype
*
* @type {Property}
* @readonly
*/
receiveShadowsProperty : {
get : function() {
return this._receiveShadowsProperty;
}
},
/**
* Gets a value indicating if the geometry is time-varying.
* If true, all visualization is delegated to the {@link DynamicGeometryUpdater}
Expand Down Expand Up @@ -442,6 +472,8 @@ define([
this._showProperty = defaultValue(show, defaultShow);
this._showOutlineProperty = defaultValue(corridor.outline, defaultOutline);
this._outlineColorProperty = outlineEnabled ? defaultValue(corridor.outlineColor, defaultOutlineColor) : undefined;
this._castShadowsProperty = defaultValue(corridor.castShadows, defaultCastShadows);
this._receiveShadowsProperty = defaultValue(corridor.receiveShadows, defaultReceiveShadows);

var height = corridor.height;
var extrudedHeight = corridor.extrudedHeight;
Expand Down Expand Up @@ -546,6 +578,9 @@ define([
options.granularity = Property.getValueOrUndefined(corridor.granularity, time);
options.cornerType = Property.getValueOrUndefined(corridor.cornerType, time);

var castShadows = this._geometryUpdater.castShadowsProperty.getValue(time);
var receiveShadows = this._geometryUpdater.receiveShadowsProperty.getValue(time);

if (!defined(corridor.fill) || corridor.fill.getValue(time)) {
var material = MaterialProperty.getValue(time, geometryUpdater.fillMaterialProperty, this._material);
this._material = material;
Expand All @@ -563,7 +598,9 @@ define([
geometry : new CorridorGeometry(options)
}),
appearance : appearance,
asynchronous : false
asynchronous : false,
castShadows : castShadows,
receiveShadows : receiveShadows
}));
}

Expand All @@ -589,7 +626,9 @@ define([
lineWidth : geometryUpdater._scene.clampLineWidth(outlineWidth)
}
}),
asynchronous : false
asynchronous : false,
castShadows : castShadows,
receiveShadows : receiveShadows
}));
}
};
Expand Down
30 changes: 29 additions & 1 deletion Source/DataSources/CorridorGraphics.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ define([
* @param {Property} [options.outlineColor=Color.BLACK] A Property specifying the {@link Color} of the outline.
* @param {Property} [options.outlineWidth=1.0] A numeric Property specifying the width of the outline.
* @param {Property} [options.granularity=Cesium.Math.RADIANS_PER_DEGREE] A numeric Property specifying the distance between each latitude and longitude.
* @param {Property} [options.castShadows=false] A boolean Property specifying whether the corridor casts shadows from each light source.
* @param {Property} [options.receiveShadows=false] A boolean Property specifying whether the corridor receives shadows from shadow casters in the scene.
*
* @see Entity
* @demo {@link http://cesiumjs.org/Cesium/Apps/Sandcastle/index.html?src=Corridor.html|Cesium Sandcastle Corridor Demo}
Expand Down Expand Up @@ -67,6 +69,10 @@ define([
this._outlineColorSubscription = undefined;
this._outlineWidth = undefined;
this._outlineWidthSubscription = undefined;
this._castShadows = undefined;
this._castShadowsSubscription = undefined;
this._receiveShadows = undefined;
this._receiveShadowsSubscription = undefined;
this._definitionChanged = new Event();

this.merge(defaultValue(options, defaultValue.EMPTY_OBJECT));
Expand Down Expand Up @@ -178,7 +184,25 @@ define([
* @type {Property}
* @default CornerType.ROUNDED
*/
cornerType : createPropertyDescriptor('cornerType')
cornerType : createPropertyDescriptor('cornerType'),

/**
* Get or sets the boolean Property specifying whether the corridor
* casts shadows from each light source.
* @memberof CorridorGraphics.prototype
* @type {Property}
* @default false
*/
castShadows : createPropertyDescriptor('castShadows'),

/**
* Get or sets the boolean Property specifying whether the corridor
* receives shadows from shadow casters in the scene.
* @memberof CorridorGraphics.prototype
* @type {Property}
* @default false
*/
receiveShadows : createPropertyDescriptor('receiveShadows')
});

/**
Expand All @@ -203,6 +227,8 @@ define([
result.outlineColor = this.outlineColor;
result.outlineWidth = this.outlineWidth;
result.cornerType = this.cornerType;
result.castShadows = this.castShadows;
result.receiveShadows = this.receiveShadows;
return result;
};

Expand Down Expand Up @@ -231,6 +257,8 @@ define([
this.outlineColor = defaultValue(this.outlineColor, source.outlineColor);
this.outlineWidth = defaultValue(this.outlineWidth, source.outlineWidth);
this.cornerType = defaultValue(this.cornerType, source.cornerType);
this.castShadows = defaultValue(this.castShadows, source.castShadows);
this.receiveShadows = defaultValue(this.receiveShadows, source.receiveShadows);
};

return CorridorGraphics;
Expand Down
Loading