Skip to content

Commit

Permalink
Merge pull request #5160 from AnalyticalGraphicsInc/depth-fail
Browse files Browse the repository at this point in the history
Separate Appearance on z-fail
  • Loading branch information
lilleyse committed Apr 12, 2017
2 parents dbd04ed + 8a29014 commit 9309df8
Show file tree
Hide file tree
Showing 12 changed files with 890 additions and 93 deletions.
47 changes: 47 additions & 0 deletions Apps/Sandcastle/gallery/Ground Clamping.html
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,53 @@

viewer.trackedEntity = e;
}
}, {
text : 'Sample line positions and draw with depth test disabled',
onselect : function() {
var length = 1000;

var startLon = Cesium.Math.toRadians(86.953793);
var endLon = Cesium.Math.toRadians(86.896497);

var lat = Cesium.Math.toRadians(27.988257);

var terrainSamplePositions = [];
for (var i = 0; i < length; ++i) {
var lon = Cesium.Math.lerp(endLon, startLon, i / (length - 1));
var position = new Cesium.Cartographic(lon, lat);
terrainSamplePositions.push(position);
}

Cesium.when(Cesium.sampleTerrainMostDetailed(viewer.terrainProvider, terrainSamplePositions), function(samples) {
var offset = 10.0;
for (var i = 0; i < samples.length; ++i) {
samples[i].height += offset;
}

viewer.entities.add({
polyline : {
positions : Cesium.Ellipsoid.WGS84.cartographicArrayToCartesianArray(samples),
followSurface : false,
width : 5,
material : new Cesium.PolylineOutlineMaterialProperty({
color : Cesium.Color.ORANGE,
outlineWidth : 2,
outlineColor : Cesium.Color.BLACK
}),
depthFailMaterial : new Cesium.PolylineOutlineMaterialProperty({
color : Cesium.Color.RED,
outlineWidth : 2,
outlineColor : Cesium.Color.BLACK
})
}
});

var target = new Cesium.Cartesian3(300770.50872389384, 5634912.131394585, 2978152.2865545116);
offset = new Cesium.Cartesian3(6344.974098678562, -793.3419798081741, 2499.9508860763162);
viewer.camera.lookAt(target, offset);
viewer.camera.lookAtTransform(Cesium.Matrix4.IDENTITY);
});
}
}], 'zoomButtons');

Sandcastle.reset = function () {
Expand Down
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Change Log

* Added `disableDepthTestDistance` to billboards, points and labels. This sets the distance to the camera where the depth test will be disabled. Setting it to zero (the default) will alwasy enable the depth test. Setting it to `Number.POSITVE_INFINITY` will never enabled the depth test. Also added `scene.minimumDisableDepthTestDistance` to change the default value from zero. [#5166](https://github.com/AnalyticalGraphicsInc/cesium/pull/5166)
* Fixed issue with displaying `MapboxImageryProvider` default token error message [#5191](https://github.com/AnalyticalGraphicsInc/cesium/pull/5191)
* Added a `depthFailMaterial` property to line entities, which is the material used to render the line when it fails the depth test. [#5160](https://github.com/AnalyticalGraphicsInc/cesium/pull/5160)

### 1.32 - 2017-04-03

Expand Down
45 changes: 33 additions & 12 deletions Source/DataSources/GeometryVisualizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,21 +95,31 @@ define([
that._outlineBatches[shadows].add(time, updater);
}

var multiplier = 0;
if (defined(updater.depthFailMaterialProperty)) {
multiplier = updater.depthFailMaterialProperty instanceof ColorMaterialProperty ? 1 : 2;
}

var index;
if (defined(shadows)) {
index = shadows + multiplier * ShadowMode.NUMBER_OF_SHADOW_MODES;
}

if (updater.fillEnabled) {
if (updater.onTerrain) {
that._groundColorBatch.add(time, updater);
} else {
if (updater.isClosed) {
if (updater.fillMaterialProperty instanceof ColorMaterialProperty) {
that._closedColorBatches[shadows].add(time, updater);
that._closedColorBatches[index].add(time, updater);
} else {
that._closedMaterialBatches[shadows].add(time, updater);
that._closedMaterialBatches[index].add(time, updater);
}
} else {
if (updater.fillMaterialProperty instanceof ColorMaterialProperty) {
that._openColorBatches[shadows].add(time, updater);
that._openColorBatches[index].add(time, updater);
} else {
that._openMaterialBatches[shadows].add(time, updater);
that._openMaterialBatches[index].add(time, updater);
}
}
}
Expand Down Expand Up @@ -152,17 +162,28 @@ define([

var numberOfShadowModes = ShadowMode.NUMBER_OF_SHADOW_MODES;
this._outlineBatches = new Array(numberOfShadowModes);
this._closedColorBatches = new Array(numberOfShadowModes);
this._closedMaterialBatches = new Array(numberOfShadowModes);
this._openColorBatches = new Array(numberOfShadowModes);
this._openMaterialBatches = new Array(numberOfShadowModes);
this._closedColorBatches = new Array(numberOfShadowModes * 3);
this._closedMaterialBatches = new Array(numberOfShadowModes * 3);
this._openColorBatches = new Array(numberOfShadowModes * 3);
this._openMaterialBatches = new Array(numberOfShadowModes * 3);

for (var i = 0; i < numberOfShadowModes; ++i) {
this._outlineBatches[i] = new StaticOutlineGeometryBatch(primitives, scene, i);
this._closedColorBatches[i] = new StaticGeometryColorBatch(primitives, type.perInstanceColorAppearanceType, true, i);
this._closedMaterialBatches[i] = new StaticGeometryPerMaterialBatch(primitives, type.materialAppearanceType, true, i);
this._openColorBatches[i] = new StaticGeometryColorBatch(primitives, type.perInstanceColorAppearanceType, false, i);
this._openMaterialBatches[i] = new StaticGeometryPerMaterialBatch(primitives, type.materialAppearanceType, false, i);

this._closedColorBatches[i] = new StaticGeometryColorBatch(primitives, type.perInstanceColorAppearanceType, undefined, true, i);
this._closedMaterialBatches[i] = new StaticGeometryPerMaterialBatch(primitives, type.materialAppearanceType, undefined, true, i);
this._openColorBatches[i] = new StaticGeometryColorBatch(primitives, type.perInstanceColorAppearanceType, undefined, false, i);
this._openMaterialBatches[i] = new StaticGeometryPerMaterialBatch(primitives, type.materialAppearanceType, undefined, false, i);

this._closedColorBatches[i + numberOfShadowModes] = new StaticGeometryColorBatch(primitives, type.perInstanceColorAppearanceType, type.perInstanceColorAppearanceType, true, i);
this._closedMaterialBatches[i + numberOfShadowModes] = new StaticGeometryPerMaterialBatch(primitives, type.materialAppearanceType, type.perInstanceColorAppearanceType, true, i);
this._openColorBatches[i + numberOfShadowModes] = new StaticGeometryColorBatch(primitives, type.perInstanceColorAppearanceType, type.perInstanceColorAppearanceType, false, i);
this._openMaterialBatches[i + numberOfShadowModes] = new StaticGeometryPerMaterialBatch(primitives, type.materialAppearanceType, type.perInstanceColorAppearanceType, false, i);

this._closedColorBatches[i + numberOfShadowModes * 2] = new StaticGeometryColorBatch(primitives, type.perInstanceColorAppearanceType, type.materialAppearanceType, true, i);
this._closedMaterialBatches[i + numberOfShadowModes * 2] = new StaticGeometryPerMaterialBatch(primitives, type.materialAppearanceType, type.materialAppearanceType, true, i);
this._openColorBatches[i + numberOfShadowModes * 2] = new StaticGeometryColorBatch(primitives, type.perInstanceColorAppearanceType, type.materialAppearanceType, false, i);
this._openMaterialBatches[i + numberOfShadowModes * 2] = new StaticGeometryPerMaterialBatch(primitives, type.materialAppearanceType, type.materialAppearanceType, false, i);
}

this._groundColorBatch = new StaticGroundGeometryColorBatch(groundPrimitives);
Expand Down
55 changes: 39 additions & 16 deletions Source/DataSources/PolylineGeometryUpdater.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ define([
this._materialProperty = undefined;
this._shadowsProperty = undefined;
this._distanceDisplayConditionProperty = undefined;
this._depthFailMaterialProperty = undefined;
this._options = new GeometryOptions(entity);
this._onEntityPropertyChanged(entity, 'polyline', entity.polyline, undefined);
}
Expand Down Expand Up @@ -171,6 +172,18 @@ define([
return this._materialProperty;
}
},
/**
* Gets the material property used to fill the geometry when it fails the depth test.
* @memberof PolylineGeometryUpdater.prototype
*
* @type {MaterialProperty}
* @readonly
*/
depthFailMaterialProperty : {
get : function() {
return this._depthFailMaterialProperty;
}
},
/**
* Gets a value indicating if the geometry has an outline component.
* @memberof PolylineGeometryUpdater.prototype
Expand Down Expand Up @@ -205,7 +218,7 @@ define([
* Gets the property specifying whether the geometry
* casts or receives shadows from each light source.
* @memberof PolylineGeometryUpdater.prototype
*
*
* @type {Property}
* @readonly
*/
Expand Down Expand Up @@ -306,30 +319,32 @@ define([
}
//>>includeEnd('debug');

var color;
var attributes;
var entity = this._entity;
var isAvailable = entity.isAvailable(time);
var show = new ShowGeometryInstanceAttribute(isAvailable && entity.isShowing && this._showProperty.getValue(time));
var distanceDisplayCondition = this._distanceDisplayConditionProperty.getValue(time);
var distanceDisplayConditionAttribute = DistanceDisplayConditionGeometryInstanceAttribute.fromDistanceDisplayCondition(distanceDisplayCondition);

var attributes = {
show : show,
distanceDisplayCondition : distanceDisplayConditionAttribute
};

var currentColor;
if (this._materialProperty instanceof ColorMaterialProperty) {
var currentColor = Color.WHITE;
currentColor = Color.WHITE;
if (defined(this._materialProperty.color) && (this._materialProperty.color.isConstant || isAvailable)) {
currentColor = this._materialProperty.color.getValue(time);
}
color = ColorGeometryInstanceAttribute.fromColor(currentColor);
attributes = {
show : show,
distanceDisplayCondition : distanceDisplayConditionAttribute,
color : color
};
} else {
attributes = {
show : show,
distanceDisplayCondition : distanceDisplayConditionAttribute
};
attributes.color = ColorGeometryInstanceAttribute.fromColor(currentColor);
}

if (defined(this._depthFailMaterialProperty) && this._depthFailMaterialProperty instanceof ColorMaterialProperty) {
currentColor = Color.WHITE;
if (defined(this._depthFailMaterialProperty.color) && (this._depthFailMaterialProperty.color.isConstant || isAvailable)) {
currentColor = this._depthFailMaterialProperty.color.getValue(time);
}
attributes.depthFailColor = ColorGeometryInstanceAttribute.fromColor(currentColor);
}

return new GeometryInstance({
Expand Down Expand Up @@ -402,6 +417,7 @@ define([
var material = defaultValue(polyline.material, defaultMaterial);
var isColorMaterial = material instanceof ColorMaterialProperty;
this._materialProperty = material;
this._depthFailMaterialProperty = polyline.depthFailMaterial;
this._showProperty = defaultValue(show, defaultShow);
this._shadowsProperty = defaultValue(polyline.shadows, defaultShadows);
this._distanceDisplayConditionProperty = defaultValue(polyline.distanceDisplayCondition, defaultDistanceDisplayCondition);
Expand Down Expand Up @@ -431,7 +447,14 @@ define([
return;
}

options.vertexFormat = isColorMaterial ? PolylineColorAppearance.VERTEX_FORMAT : PolylineMaterialAppearance.VERTEX_FORMAT;
var vertexFormat;
if (isColorMaterial && (!defined(this._depthFailMaterialProperty) || this._depthFailMaterialProperty instanceof ColorMaterialProperty)) {
vertexFormat = PolylineColorAppearance.VERTEX_FORMAT;
} else {
vertexFormat = PolylineMaterialAppearance.VERTEX_FORMAT;
}

options.vertexFormat = vertexFormat;
options.positions = positions;
options.width = defined(width) ? width.getValue(Iso8601.MINIMUM_VALUE) : undefined;
options.followSurface = defined(followSurface) ? followSurface.getValue(Iso8601.MINIMUM_VALUE) : undefined;
Expand Down
17 changes: 16 additions & 1 deletion Source/DataSources/PolylineGraphics.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ define([
this._showSubscription = undefined;
this._material = undefined;
this._materialSubscription = undefined;
this._depthFailMaterial = undefined;
this._depthFailMaterialSubscription = undefined;
this._positions = undefined;
this._positionsSubscription = undefined;
this._followSurface = undefined;
Expand Down Expand Up @@ -91,6 +93,17 @@ define([
*/
material : createMaterialPropertyDescriptor('material'),

/**
* Gets or sets the Property specifying the material used to draw the polyline when it fails the depth test.
* <p>
* Requires the EXT_frag_depth WebGL extension to render properly. If the extension is not supported,
* there may be artifacts.
* </p>
* @type {MaterialProperty}
* @default undefined
*/
depthFailMaterial : createMaterialPropertyDescriptor('depthFailMaterial'),

/**
* Gets or sets the Property specifying the array of {@link Cartesian3}
* positions that define the line strip.
Expand Down Expand Up @@ -123,7 +136,7 @@ define([
* @default Cesium.Math.RADIANS_PER_DEGREE
*/
granularity : createPropertyDescriptor('granularity'),

/**
* Get or sets the enum Property specifying whether the polyline
* casts or receives shadows from each light source.
Expand Down Expand Up @@ -153,6 +166,7 @@ define([
}
result.show = this.show;
result.material = this.material;
result.depthFailMaterial = this.depthFailMaterial;
result.positions = this.positions;
result.width = this.width;
result.followSurface = this.followSurface;
Expand All @@ -177,6 +191,7 @@ define([

this.show = defaultValue(this.show, source.show);
this.material = defaultValue(this.material, source.material);
this.depthFailMaterial = defaultValue(this.depthFailMaterial, source.depthFailMaterial);
this.positions = defaultValue(this.positions, source.positions);
this.width = defaultValue(this.width, source.width);
this.followSurface = defaultValue(this.followSurface, source.followSurface);
Expand Down
Loading

0 comments on commit 9309df8

Please sign in to comment.