Skip to content

Commit

Permalink
Merge pull request #7399 from geoscan/point-cloud-scale-fixes
Browse files Browse the repository at this point in the history
Option to turn off normal shading
  • Loading branch information
lilleyse committed Mar 14, 2019
2 parents 8c05d3a + 5045510 commit 5cbb5e5
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 17 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Change Log

##### Additions :tada:
* `Resource.fetchImage` now has a `flipY` option to vertically flip an image during fetch & decode. It is only valid when `ImageBitmapOptions` is supported by the browser. [#7579](https://github.com/AnalyticalGraphicsInc/cesium/pull/7579)
* Added `backFaceCulling` and `normalShading` options to `PointCloudShading`. Both options are only applicable for point clouds containing normals. [#7399](https://github.com/AnalyticalGraphicsInc/cesium/pull/7399)

##### Fixes :wrench:
* Fixed the value for `BlendFunction.ONE_MINUS_CONSTANT_COLOR`. [#7624](https://github.com/AnalyticalGraphicsInc/cesium/pull/7624)
Expand Down
6 changes: 3 additions & 3 deletions Source/Scene/PointCloud.js
Original file line number Diff line number Diff line change
Expand Up @@ -1137,6 +1137,7 @@ define([
} else {
vs += ' vec3 normal = a_normal; \n';
}
vs += ' vec3 normalEC = czm_normal * normal; \n';
} else {
vs += ' vec3 normal = vec3(1.0); \n';
}
Expand All @@ -1163,8 +1164,7 @@ define([
vs += ' color = color * u_highlightColor; \n';

if (usesNormals && normalShading) {
vs += ' normal = czm_normal * normal; \n' +
' float diffuseStrength = czm_getLambertDiffuse(czm_sunDirectionEC, normal); \n' +
vs += ' float diffuseStrength = czm_getLambertDiffuse(czm_sunDirectionEC, normalEC); \n' +
' diffuseStrength = max(diffuseStrength, 0.4); \n' + // Apply some ambient lighting
' color.xyz *= diffuseStrength; \n';
}
Expand All @@ -1173,7 +1173,7 @@ define([
' gl_Position = czm_modelViewProjection * vec4(position, 1.0); \n';

if (usesNormals && backFaceCulling) {
vs += ' float visible = step(-normal.z, 0.0); \n' +
vs += ' float visible = step(-normalEC.z, 0.0); \n' +
' gl_Position *= visible; \n' +
' gl_PointSize *= visible; \n';
}
Expand Down
13 changes: 9 additions & 4 deletions Source/Scene/PointCloud3DTileContent.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ define([
'./Cesium3DTileFeature',
'./Cesium3DTileRefine',
'./PointCloud',
'./PointCloudShading',
'./SceneMode'
], function(
Color,
Expand All @@ -31,6 +32,7 @@ define([
Cesium3DTileFeature,
Cesium3DTileRefine,
PointCloud,
PointCloudShading,
SceneMode) {
'use strict';

Expand Down Expand Up @@ -270,9 +272,11 @@ define([
}
};

var defaultShading = new PointCloudShading();

PointCloud3DTileContent.prototype.update = function(tileset, frameState) {
var pointCloud = this._pointCloud;
var pointCloudShading = tileset.pointCloudShading;
var pointCloudShading = defaultValue(tileset.pointCloudShading, defaultShading);
var tile = this._tile;
var batchTable = this._batchTable;
var mode = frameState.mode;
Expand Down Expand Up @@ -300,7 +304,6 @@ define([
this._styleDirty = false;

pointCloud.clippingPlanesOriginMatrix = tileset.clippingPlanesOriginMatrix;

pointCloud.style = defined(batchTable) ? undefined : tileset.style;
pointCloud.styleDirty = styleDirty;
pointCloud.modelMatrix = tile.computedTransform;
Expand All @@ -310,9 +313,11 @@ define([
pointCloud.clippingPlanes = clippingPlanes;
pointCloud.isClipped = defined(clippingPlanes) && clippingPlanes.enabled && tile._isClipped;
pointCloud.clippingPlanesDirty = tile.clippingPlanesDirty;
pointCloud.attenuation = defined(pointCloudShading) ? pointCloudShading.attenuation : false;
pointCloud.attenuation = pointCloudShading.attenuation;
pointCloud.backFaceCulling = pointCloudShading.backFaceCulling;
pointCloud.normalShading = pointCloudShading.normalShading;
pointCloud.geometricError = getGeometricError(this);
pointCloud.geometricErrorScale = defined(pointCloudShading) ? pointCloudShading.geometricErrorScale : 1.0;
pointCloud.geometricErrorScale = pointCloudShading.geometricErrorScale;
if (defined(pointCloudShading) && defined(pointCloudShading.maximumAttenuation)) {
pointCloud.maximumAttenuation = pointCloudShading.maximumAttenuation;
} else if (tile.refine === Cesium3DTileRefine.ADD) {
Expand Down
19 changes: 19 additions & 0 deletions Source/Scene/PointCloudShading.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ define([
* @param {Boolean} [options.eyeDomeLighting=true] When true, use eye dome lighting when drawing with point attenuation.
* @param {Number} [options.eyeDomeLightingStrength=1.0] Increasing this value increases contrast on slopes and edges.
* @param {Number} [options.eyeDomeLightingRadius=1.0] Increase the thickness of contours from eye dome lighting.
* @param {Boolean} [options.backFaceCulling=false] Determines whether back-facing points are hidden. This option works only if data has normals included.
* @param {Boolean} [options.normalShading=true] Determines whether a point cloud that contains normals is shaded based on the sun direction.
*
* @alias PointCloudShading
* @constructor
Expand Down Expand Up @@ -76,6 +78,23 @@ define([
* @default 1.0
*/
this.eyeDomeLightingRadius = defaultValue(pointCloudShading.eyeDomeLightingRadius, 1.0);

/**
* Determines whether back-facing points are hidden.
* This option works only if data has normals included.
*
* @type {Boolean}
* @default false
*/
this.backFaceCulling = defaultValue(pointCloudShading.backFaceCulling, false);

/**
* Determines whether a point cloud that contains normals is shaded based on the sun direction.
*
* @type {Boolean}
* @default true
*/
this.normalShading = defaultValue(pointCloudShading.normalShading, true);
}

/**
Expand Down
16 changes: 9 additions & 7 deletions Source/Scene/TimeDynamicPointCloud.js
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,10 @@ define([
return 10.0;
}

var defaultShading = new PointCloudShading();

function renderFrame(that, frame, updateState, frameState) {
var shading = defaultValue(that.shading, defaultShading);
var pointCloud = frame.pointCloud;
var transform = defaultValue(frame.transform, Matrix4.IDENTITY);
pointCloud.modelMatrix = Matrix4.multiplyTransformation(that.modelMatrix, transform, scratchModelMatrix);
Expand All @@ -499,14 +502,13 @@ define([
pointCloud.shadows = that.shadows;
pointCloud.clippingPlanes = that._clippingPlanes;
pointCloud.isClipped = updateState.isClipped;
pointCloud.attenuation = shading.attenuation;
pointCloud.backFaceCulling = shading.backFaceCulling;
pointCloud.normalShading = shading.normalShading;
pointCloud.geometricError = getGeometricError(that, pointCloud);
pointCloud.geometricErrorScale = shading.geometricErrorScale;
pointCloud.maximumAttenuation = getMaximumAttenuation(that);

var shading = that.shading;
if (defined(shading)) {
pointCloud.attenuation = shading.attenuation;
pointCloud.geometricError = getGeometricError(that, pointCloud);
pointCloud.geometricErrorScale = shading.geometricErrorScale;
pointCloud.maximumAttenuation = getMaximumAttenuation(that);
}
pointCloud.update(frameState);
frame.touchedFrameNumber = frameState.frameNumber;
}
Expand Down
4 changes: 2 additions & 2 deletions Specs/Scene/PointCloud3DTileContentSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ defineSuite([

expect(scene).toPickAndCall(function(result) {
// Set culling to true
content._pointCloud.backFaceCulling = true;
tileset.pointCloudShading.backFaceCulling = true;

expect(scene).toPickAndCall(function(result) {
picked = result;
Expand All @@ -487,7 +487,7 @@ defineSuite([
}

// Set culling to false
content._pointCloud.backFaceCulling = false;
tileset.pointCloudShading.backFaceCulling = false;

expect(scene).toPickAndCall(function(result) {
picked = result;
Expand Down
8 changes: 7 additions & 1 deletion Specs/Scene/PointCloudShadingSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,17 @@ defineSuite([
expect(pointCloudShading.eyeDomeLighting).toEqual(true);
expect(pointCloudShading.eyeDomeLightingStrength).toEqual(1.0);
expect(pointCloudShading.eyeDomeLightingRadius).toEqual(1.0);
expect(pointCloudShading.backFaceCulling).toEqual(false);
expect(pointCloudShading.normalShading).toEqual(true);

var options = {
geometricErrorScale : 2.0,
maximumAttenuation : 16,
baseResolution : 0.1,
eyeDomeLightingStrength : 0.1,
eyeDomeLightingRadius : 2.0
eyeDomeLightingRadius : 2.0,
backFaceCulling : true,
normalShading : false
};
pointCloudShading = new PointCloudShading(options);
expect(pointCloudShading.attenuation).toEqual(false);
Expand All @@ -31,6 +35,8 @@ defineSuite([
expect(pointCloudShading.eyeDomeLighting).toEqual(true);
expect(pointCloudShading.eyeDomeLightingStrength).toEqual(options.eyeDomeLightingStrength);
expect(pointCloudShading.eyeDomeLightingRadius).toEqual(options.eyeDomeLightingRadius);
expect(pointCloudShading.backFaceCulling).toEqual(options.backFaceCulling);
expect(pointCloudShading.normalShading).toEqual(options.normalShading);
});

it('provides a method for checking if point cloud shading is supported', function() {
Expand Down

0 comments on commit 5cbb5e5

Please sign in to comment.