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

Separate Appearance on z-fail #5160

Merged
merged 15 commits into from
Apr 12, 2017
Merged
130 changes: 130 additions & 0 deletions Apps/Sandcastle/gallery/Hello World.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,136 @@
'use strict';
//Sandcastle_Begin
var viewer = new Cesium.Viewer('cesiumContainer');
viewer.terrainProvider = new Cesium.CesiumTerrainProvider({
url : 'https://assets.agi.com/stk-terrain/world',
requestWaterMask : true,
requestVertexNormals : true
});

var scene = viewer.scene;
scene.globe.depthTestAgainstTerrain = true;

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

function createPositions() {
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);
}
return terrainSamplePositions;
}

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

var cartesianSamples = Cesium.Ellipsoid.WGS84.cartographicArrayToCartesianArray(samples);

/*
viewer.entities.add({
polyline : {
positions : cartesianSamples,
followSurface : false,
width : 5,
material : Cesium.Color.RED,
depthFailMaterial : Cesium.Color.BLUE
}
});
*/

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

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

viewer.entities.add({
polyline : {
positions : cartesianSamples,
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 dimension = 500.0;
var positionCart = new Cesium.Cartographic(1.51728, 0.488037, 8407.4);
var position = Cesium.Ellipsoid.WGS84.cartographicToCartesian(positionCart);

scene.primitives.add(new Cesium.Primitive({
geometryInstances : new Cesium.GeometryInstance({
geometry : Cesium.BoxGeometry.fromDimensions({
vertexFormat : Cesium.PerInstanceColorAppearance.VERTEX_FORMAT,
dimensions : new Cesium.Cartesian3(dimension, dimension, dimension)
}),
modelMatrix : Cesium.Transforms.eastNorthUpToFixedFrame(position),
attributes : {
color : Cesium.ColorGeometryInstanceAttribute.fromColor(new Cesium.Color(1.0, 0.0, 1.0, 0.5)),
depthFailColor : Cesium.ColorGeometryInstanceAttribute.fromColor(new Cesium.Color(1.0, 0.0, 0.0, 0.5))
}
}),
appearance : new Cesium.PerInstanceColorAppearance({
closed: true
}),
depthFailAppearance : new Cesium.PerInstanceColorAppearance({
closed: true
})
}));
*/

//Sandcastle_End
Sandcastle.finishedLoading();
}
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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like this batching is starting to get out of hand (even when it was just shadows), but probably worth addressing later.


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
48 changes: 32 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,11 @@ define([
return this._materialProperty;
}
},
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 +211,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 +312,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 +410,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 +440,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
6 changes: 6 additions & 0 deletions 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,8 @@ define([
*/
material : createMaterialPropertyDescriptor('material'),

depthFailMaterial : createMaterialPropertyDescriptor('depthFailMaterial'),

/**
* Gets or sets the Property specifying the array of {@link Cartesian3}
* positions that define the line strip.
Expand Down Expand Up @@ -153,6 +157,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 +182,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