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

Materials on Ground Primitives #6393

Merged
merged 44 commits into from
May 15, 2018
Merged
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
bdf302e
able to get world coordinates from depth tex
likangning93 Feb 13, 2018
4fe0397
texcoords from naive inverse trig
likangning93 Feb 20, 2018
956df6c
using cg ref approx to compute spherical coordinates on CPU and GPU
likangning93 Mar 2, 2018
529b5ab
add separate shader for shadow volume final pass, use a cubic instead…
likangning93 Mar 4, 2018
7af7d47
merged in master
likangning93 Mar 8, 2018
3e5c724
WIP material support for ground primitives w/normals from depth tex
likangning93 Mar 20, 2018
0433738
change ground primitive normal computation to EC for less noise
likangning93 Mar 21, 2018
2b47810
reduce multifrustum artifacts for EC normals from depth
likangning93 Mar 21, 2018
693f7e2
bespoke shadow volume appearance shaders
likangning93 Mar 22, 2018
f9ca260
switch spherical coordinates computation to atan
likangning93 Mar 23, 2018
d02346b
simplified spherical coordinates via atan
likangning93 Mar 26, 2018
71b6095
merged in master
likangning93 Mar 28, 2018
e7c4679
added plane-based texcoords, still has precision artifacts
likangning93 Mar 28, 2018
23d6dfb
changed texcoord planes to use a model matrix attribute, less inaccur…
likangning93 Mar 29, 2018
62ab0ba
using double-precision points for planes, added switching between pla…
likangning93 Mar 29, 2018
2cb5132
add batching for ground primitives
likangning93 Mar 29, 2018
9212796
PR feedback
likangning93 Apr 5, 2018
8e59e2d
add texture coordinate rotation for materials on GroundPrimitives
likangning93 Apr 11, 2018
5ee2f07
added GroundPrimitives material support for 2D/CV [ci skip]
likangning93 Apr 12, 2018
849c8a6
reduce batch table use for 2D texcoords on GroundPrimitives [ci skip]
likangning93 Apr 12, 2018
6b43300
add batched drawing for pick [ci skip]
likangning93 Apr 19, 2018
de2268a
cleanup for shadow volume material vertex shaders [ci skip]
likangning93 Apr 20, 2018
1d9cb79
merged in master, issues with log depth [ci skip]
likangning93 Apr 20, 2018
2aba8f0
fix log depth with GroundPrimitive materials [ci skip]
likangning93 Apr 24, 2018
0844b9d
cleanup for materials on GroundPrimitives [ci skip]
likangning93 Apr 24, 2018
d9ed5c5
unit tests
likangning93 Apr 27, 2018
5e4f46c
updates for planar texcoords in 3D
likangning93 Apr 27, 2018
4a00da4
factor height into GroundPrimitive texcoord planes
likangning93 Apr 29, 2018
d13d97f
PR comments
likangning93 May 2, 2018
5b0c259
add fallback for IE
likangning93 May 3, 2018
e35db9d
merged in master
likangning93 May 3, 2018
6061880
added development Sandcastles, fixed dynamic Entities, updated CHANGE…
likangning93 May 3, 2018
5300fda
fix headers in new development Sandcastle examples
likangning93 May 4, 2018
892b7db
add support for materials on dynamic terrain entities, fix texture co…
likangning93 May 7, 2018
ac71c04
compute tight rectangles for rotated texture coordinates [ci skip]
likangning93 May 9, 2018
41236c4
add specs for tight oriented rectangles for texture coordinates
likangning93 May 9, 2018
921a3db
fix fallback picking
likangning93 May 9, 2018
75dcb60
fix test failures with webgl stub for StaticGroundGeometryPerMaterial…
likangning93 May 10, 2018
fe8d1f7
compute texture coordinate rotation parameters in local ENU for Ellip…
likangning93 May 11, 2018
9643b2c
doc tweaks
likangning93 May 11, 2018
2aaf979
PR feedback and cleanup
likangning93 May 11, 2018
16c7305
handle ClassificationType BOTH and CESIUM_3D_TILE with materials on G…
likangning93 May 15, 2018
fbf05c8
format CHANGES.md entry with bullets
likangning93 May 15, 2018
4f580be
add textured terrain entity example to Ground Clamping Sandcastle
likangning93 May 15, 2018
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
68 changes: 64 additions & 4 deletions LICENSE.md
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,52 @@ OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
THIS SOFTWARE.

### rbush

https://github.com/mourner/rbush

> MIT License

> Copyright (c) 2016 Vladimir Agafonkin

>Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
>
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
>
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

### quickselect

https://github.com/mourner/quickselect

> ISC License

> Copyright (c) 2018, Vladimir Agafonkin

>Permission to use, copy, modify, and/or distribute this software for any purpose
with or without fee is hereby granted, provided that the above copyright notice
and this permission notice appear in all copies.
>
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
THIS SOFTWARE.

### crunch

https://github.com/BinomialLLC/crunch
Expand Down Expand Up @@ -670,6 +716,20 @@ https://github.com/KhronosGroup/glTF-WebGL-PBR
>CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
>OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

### ShaderFastLibs

https://github.com/michaldrobot/ShaderFastLibs

> The MIT License (MIT)
>
> Copyright (c) <2014> <Michal Drobot>
>
> Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

> The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

### Draco

https://github.com/google/draco
Expand All @@ -692,20 +752,20 @@ https://github.com/leizongmin/js-xss

> Copyright (c) 2012-2017 Zongmin Lei(雷宗民) <[email protected]>
> http://ucdok.com
>
>
> The MIT License
>
>
> Permission is hereby granted, free of charge, to any person obtaining
> a copy of this software and associated documentation files (the
> "Software"), to deal in the Software without restriction, including
> without limitation the rights to use, copy, modify, merge, publish,
> distribute, sublicense, and/or sell copies of the Software, and to
> permit persons to whom the Software is furnished to do so, subject to
> the following conditions:
>
>
> The above copyright notice and this permission notice shall be
> included in all copies or substantial portions of the Software.
>
>
> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
> EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
> MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
Expand Down
53 changes: 53 additions & 0 deletions Source/Core/Math.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
define([
'../ThirdParty/mersenne-twister',
'./Check',
'./defaultValue',
'./defined',
'./DeveloperError'
], function(
MersenneTwister,
Check,
defaultValue,
defined,
DeveloperError) {
Expand Down Expand Up @@ -857,5 +859,56 @@ define([
return 1.0 - Math.exp(-(scalar * scalar));
};

/**
* Computes a fast approximation of Atan for input in the range [-1, 1].
*
* Based on Michal Drobot's approximation from ShaderFastLibs,
* which in turn is based on "Efficient approximations for the arctangent function,"
* Rajan, S. Sichun Wang Inkol, R. Joyal, A., May 2006.
* Adapted from ShaderFastLibs under MIT License.
*
* @param {Number} x An input number in the range [-1, 1]
* @returns {Number} An approximation of atan(x)
*/
CesiumMath.fastApproximateAtan = function(x) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Here and below could be public IMO like much of the rest of this class already is.

//>>includeStart('debug', pragmas.debug);
Check.typeOf.number('x', x);
//>>includeEnd('debug');

return x * (-0.1784 * Math.abs(x) - 0.0663 * x * x + 1.0301);
};

/**
* Computes a fast approximation of Atan2(x, y) for arbitrary input scalars.
*
* Range reduction math based on nvidia's cg reference implementation: http://developer.download.nvidia.com/cg/atan2.html
*
* @param {Number} x An input number that isn't zero if y is zero.
* @param {Number} y An input number that isn't zero if x is zero.
* @returns {Number} An approximation of atan2(x, y)
*/
CesiumMath.fastApproximateAtan2 = function(x, y) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Here and below, are x and y required? If so this should throw, but it looks like most/all of this file marches to the beat of its own drum for parameter checking so perhaps just submit an issue to evaluate and we'll update throughout if needed.

//>>includeStart('debug', pragmas.debug);
Check.typeOf.number('x', x);
Check.typeOf.number('y', y);
//>>includeEnd('debug');

// atan approximations are usually only reliable over [-1, 1]
// So reduce the range by flipping whether x or y is on top.
var opposite, adjacent, t; // t used as swap and atan result.
Copy link
Contributor

Choose a reason for hiding this comment

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

These should all be declared on separate lines.

t = Math.abs(x);
opposite = Math.abs(y);
adjacent = Math.max(t, opposite);
opposite = Math.min(t, opposite);

t = CesiumMath.fastApproximateAtan(opposite / adjacent);
Copy link
Contributor

Choose a reason for hiding this comment

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

adjacent should never be zero unless both x and y are zero. You should check if both are zero or maybe if opposite / adjacent is NaN.


// Undo range reduction
t = Math.abs(y) > Math.abs(x) ? CesiumMath.PI_OVER_TWO - t : t;
t = x < 0.0 ? CesiumMath.PI - t : t;
t = y < 0.0 ? -t : t;
return t;
};

return CesiumMath;
});
90 changes: 90 additions & 0 deletions Source/Core/RectangleCollisionChecker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
define([
'../ThirdParty/rbush',
'./Check'
], function(
rbush,
Check) {
'use strict';

/**
* Wrapper around rbush for use with Rectangle types.
* @private
*/
function RectangleCollisionChecker() {
this._tree = rbush();
}

function RectangleWithId() {
this.minX = 0.0;
this.minY = 0.0;
this.maxX = 0.0;
this.maxY = 0.0;
this.id = '';
}

RectangleWithId.fromRectangleAndId = function(id, rectangle, result) {
result.minX = rectangle.west;
result.minY = rectangle.south;
result.maxX = rectangle.east;
result.maxY = rectangle.north;
result.id = id;
return result;
};

/**
* Insert a rectangle into the collision checker.
*
* @param {String} id Unique string ID for the rectangle being inserted.
* @param {Rectangle} rectangle A Rectangle
* @private
*/
RectangleCollisionChecker.prototype.insert = function(id, rectangle) {
//>>includeStart('debug', pragmas.debug);
Check.typeOf.string('id', id);
Check.typeOf.object('rectangle', rectangle);
//>>includeEnd('debug');

var withId = RectangleWithId.fromRectangleAndId(id, rectangle, new RectangleWithId());
this._tree.insert(withId);
};

function idCompare(a, b) {
return a.id === b.id;
}

var removalScratch = new RectangleWithId();
/**
* Remove a rectangle from the collision checker.
*
* @param {String} id Unique string ID for the rectangle being removed.
* @param {Rectangle} rectangle A Rectangle
* @private
*/
RectangleCollisionChecker.prototype.remove = function(id, rectangle) {
//>>includeStart('debug', pragmas.debug);
Check.typeOf.string('id', id);
Check.typeOf.object('rectangle', rectangle);
//>>includeEnd('debug');

var withId = RectangleWithId.fromRectangleAndId(id, rectangle, removalScratch);
this._tree.remove(withId, idCompare);
};

var collisionScratch = new RectangleWithId();
/**
* Checks if a given rectangle collides with any of the rectangles in the collection.
*
* @param {Rectangle} rectangle A Rectangle that should be checked against the rectangles in the collision checker.
* @returns {Boolean} Whether the rectangle collides with any of the rectangles in the collision checker.
*/
RectangleCollisionChecker.prototype.collides = function(rectangle) {
//>>includeStart('debug', pragmas.debug);
Check.typeOf.object('rectangle', rectangle);
//>>includeEnd('debug');

var withId = RectangleWithId.fromRectangleAndId('', rectangle, collisionScratch);
return this._tree.collides(withId);
};

return RectangleCollisionChecker;
});
4 changes: 1 addition & 3 deletions Source/DataSources/CorridorGeometryUpdater.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,8 @@ define([
};

CorridorGeometryUpdater.prototype._isOnTerrain = function(entity, corridor) {
var isColorMaterial = this._materialProperty instanceof ColorMaterialProperty;

return this._fillEnabled && !defined(corridor.height) && !defined(corridor.extrudedHeight) &&
isColorMaterial && GroundPrimitive.isSupported(this._scene);
GroundPrimitive.isSupported(this._scene);
};

CorridorGeometryUpdater.prototype._getIsClosed = function(options) {
Expand Down
4 changes: 1 addition & 3 deletions Source/DataSources/EllipseGeometryUpdater.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,7 @@ define([
};

EllipseGeometryUpdater.prototype._isOnTerrain = function(entity, ellipse) {
var isColorMaterial = this._materialProperty instanceof ColorMaterialProperty;

return this._fillEnabled && !defined(ellipse.height) && !defined(ellipse.extrudedHeight) && isColorMaterial && GroundPrimitive.isSupported(this._scene);
return this._fillEnabled && !defined(ellipse.height) && !defined(ellipse.extrudedHeight) && GroundPrimitive.isSupported(this._scene);
};

EllipseGeometryUpdater.prototype._isDynamic = function(entity, ellipse) {
Expand Down
16 changes: 11 additions & 5 deletions Source/DataSources/GeometryVisualizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ define([
'./RectangleGeometryUpdater',
'./StaticGeometryColorBatch',
'./StaticGeometryPerMaterialBatch',
'./StaticGroundGeometryColorBatch',
'./StaticGroundGeometryPerMaterialBatch',
'./StaticOutlineGeometryBatch',
'./WallGeometryUpdater'
], function(
Expand Down Expand Up @@ -55,7 +55,7 @@ define([
RectangleGeometryUpdater,
StaticGeometryColorBatch,
StaticGeometryPerMaterialBatch,
StaticGroundGeometryColorBatch,
StaticGroundGeometryPerMaterialBatch,
StaticOutlineGeometryBatch,
WallGeometryUpdater) {
'use strict';
Expand Down Expand Up @@ -156,14 +156,16 @@ define([

var numberOfClassificationTypes = ClassificationType.NUMBER_OF_CLASSIFICATION_TYPES;
this._groundColorBatches = new Array(numberOfClassificationTypes);
this._groundMaterialBatches = new Array(numberOfClassificationTypes);

for (i = 0; i < numberOfClassificationTypes; ++i) {
this._groundColorBatches[i] = new StaticGroundGeometryColorBatch(groundPrimitives, i);
this._groundColorBatches[i] = new StaticGroundGeometryPerMaterialBatch(groundPrimitives, PerInstanceColorAppearance, i);
this._groundMaterialBatches[i] = new StaticGroundGeometryPerMaterialBatch(groundPrimitives, MaterialAppearance, i);
}

this._dynamicBatch = new DynamicGeometryBatch(primitives, groundPrimitives);

this._batches = this._outlineBatches.concat(this._closedColorBatches, this._closedMaterialBatches, this._openColorBatches, this._openMaterialBatches, this._groundColorBatches, this._dynamicBatch);
this._batches = this._outlineBatches.concat(this._closedColorBatches, this._closedMaterialBatches, this._openColorBatches, this._openMaterialBatches, this._groundColorBatches, this._groundMaterialBatches, this._dynamicBatch);

this._subscriptions = new AssociativeArray();
this._updaterSets = new AssociativeArray();
Expand Down Expand Up @@ -375,7 +377,11 @@ define([
if (updater.fillEnabled) {
if (updater.onTerrain) {
var classificationType = updater.classificationTypeProperty.getValue(time);
this._groundColorBatches[classificationType].add(time, updater);
if (updater.fillMaterialProperty instanceof ColorMaterialProperty) {
this._groundColorBatches[classificationType].add(time, updater);
} else {
this._groundMaterialBatches[classificationType].add(time, updater);
}
} else if (updater.isClosed) {
if (updater.fillMaterialProperty instanceof ColorMaterialProperty) {
this._closedColorBatches[shadows].add(time, updater);
Expand Down
3 changes: 1 addition & 2 deletions Source/DataSources/PolygonGeometryUpdater.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,9 @@ define([
};

PolygonGeometryUpdater.prototype._isOnTerrain = function(entity, polygon) {
var isColorMaterial = this._materialProperty instanceof ColorMaterialProperty;
var perPositionHeightProperty = polygon.perPositionHeight;
var perPositionHeightEnabled = defined(perPositionHeightProperty) && (perPositionHeightProperty.isConstant ? perPositionHeightProperty.getValue(Iso8601.MINIMUM_VALUE) : true);
return this._fillEnabled && !defined(polygon.height) && !defined(polygon.extrudedHeight) && isColorMaterial &&
return this._fillEnabled && !defined(polygon.height) && !defined(polygon.extrudedHeight) &&
!perPositionHeightEnabled && GroundPrimitive.isSupported(this._scene);
};

Expand Down
4 changes: 1 addition & 3 deletions Source/DataSources/RectangleGeometryUpdater.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,7 @@ define([
};

RectangleGeometryUpdater.prototype._isOnTerrain = function(entity, rectangle) {
var isColorMaterial = this._materialProperty instanceof ColorMaterialProperty;

return this._fillEnabled && !defined(rectangle.height) && !defined(rectangle.extrudedHeight) && isColorMaterial && GroundPrimitive.isSupported(this._scene);
return this._fillEnabled && !defined(rectangle.height) && !defined(rectangle.extrudedHeight) && GroundPrimitive.isSupported(this._scene);
};

RectangleGeometryUpdater.prototype._isDynamic = function(entity, rectangle) {
Expand Down
Loading