From fe666ce2bd66d5cebe41fc192f51464cc2c0eb0b Mon Sep 17 00:00:00 2001 From: George Vinokhodov Date: Fri, 7 Dec 2018 19:43:56 +0300 Subject: [PATCH 01/10] refs #5152 option to switch normal shading --- Source/Scene/Cesium3DTileset.js | 20 ++++++++++++++++++++ Source/Scene/PointCloud.js | 20 ++++++++++++++++++-- Source/Scene/PointCloud3DTileContent.js | 4 +++- 3 files changed, 41 insertions(+), 3 deletions(-) diff --git a/Source/Scene/Cesium3DTileset.js b/Source/Scene/Cesium3DTileset.js index 8b394390f0b6..10780186ec38 100644 --- a/Source/Scene/Cesium3DTileset.js +++ b/Source/Scene/Cesium3DTileset.js @@ -20,6 +20,7 @@ define([ '../Core/Resource', '../Core/RuntimeError', '../Core/Transforms', + '../DataSources/ConstantProperty', '../Renderer/ClearCommand', '../Renderer/Pass', '../ThirdParty/when', @@ -65,6 +66,7 @@ define([ Resource, RuntimeError, Transforms, + ConstantProperty, ClearCommand, Pass, when, @@ -293,6 +295,24 @@ define([ */ this.shadows = defaultValue(options.shadows, ShadowMode.ENABLED); + /** + * Determines whether backfaces of points / mesh are hidden + * + * @type {boolean} + * @default false + */ + var backFaceCulling = defaultValue(options.backFaceCulling, false); + this.backFaceCulling = new ConstantProperty(backFaceCulling); + + /** + * Determines whether the tileset is lighted by the sun + * + * @type {boolean} + * @default true + */ + var normalShading = defaultValue(options.normalShading, true); + this.normalShading = new ConstantProperty(normalShading); + /** * Determines if the tileset will be shown. * diff --git a/Source/Scene/PointCloud.js b/Source/Scene/PointCloud.js index 252764a23f4e..2bfc0b7ef869 100644 --- a/Source/Scene/PointCloud.js +++ b/Source/Scene/PointCloud.js @@ -21,6 +21,7 @@ define([ '../Core/PrimitiveType', '../Core/RuntimeError', '../Core/Transforms', + '../DataSources/ConstantProperty', '../Renderer/Buffer', '../Renderer/BufferUsage', '../Renderer/DrawCommand', @@ -62,6 +63,7 @@ define([ PrimitiveType, RuntimeError, Transforms, + ConstantProperty, Buffer, BufferUsage, DrawCommand, @@ -114,6 +116,8 @@ define([ Check.typeOf.object('options.arrayBuffer', options.arrayBuffer); //>>includeEnd('debug'); + var that = this; + // Hold onto the payload until the render resources are created this._parsedContent = undefined; @@ -147,11 +151,13 @@ define([ // Use per-point normals to hide back-facing points. this.backFaceCulling = false; - this._backFaceCulling = false; + bindProperty(this, "backFaceCulling", options.backFaceCulling); + this._backFaceCulling = this.backFaceCulling; // Whether to enable normal shading this.normalShading = true; - this._normalShading = true; + bindProperty(this, "normalShading", options.normalShading); + this._normalShading = this.normalShading; this._opaqueRenderState = undefined; this._translucentRenderState = undefined; @@ -249,6 +255,16 @@ define([ var sizeOfUint32 = Uint32Array.BYTES_PER_ELEMENT; + function bindProperty(object, field, property) { + if (property) { + var val = property.getValue(); + object[field] = val; + property.definitionChanged.addEventListener(function(newValue) { + object[field] = newValue.getValue(); + }); + } + } + function initialize(pointCloud, options) { var arrayBuffer = options.arrayBuffer; var byteOffset = defaultValue(options.byteOffset, 0); diff --git a/Source/Scene/PointCloud3DTileContent.js b/Source/Scene/PointCloud3DTileContent.js index f9cb8caa9855..740627fcdaf4 100644 --- a/Source/Scene/PointCloud3DTileContent.js +++ b/Source/Scene/PointCloud3DTileContent.js @@ -70,7 +70,9 @@ define([ fragmentShaderLoaded : getFragmentShaderLoaded(this), uniformMapLoaded : getUniformMapLoaded(this), batchTableLoaded : getBatchTableLoaded(this), - pickIdLoaded : getPickIdLoaded(this) + pickIdLoaded : getPickIdLoaded(this), + normalShading : tileset.normalShading, + backfaceCulling : tileset.backfaceCulling }); } From a563bda5cab29a3ac32f26bef6fc488a240b4ea1 Mon Sep 17 00:00:00 2001 From: George Vinokhodov Date: Thu, 13 Dec 2018 19:35:54 +0300 Subject: [PATCH 02/10] codestyle fixes --- Source/Scene/PointCloud.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/Source/Scene/PointCloud.js b/Source/Scene/PointCloud.js index 2bfc0b7ef869..904e1c61bef5 100644 --- a/Source/Scene/PointCloud.js +++ b/Source/Scene/PointCloud.js @@ -116,8 +116,6 @@ define([ Check.typeOf.object('options.arrayBuffer', options.arrayBuffer); //>>includeEnd('debug'); - var that = this; - // Hold onto the payload until the render resources are created this._parsedContent = undefined; @@ -151,12 +149,12 @@ define([ // Use per-point normals to hide back-facing points. this.backFaceCulling = false; - bindProperty(this, "backFaceCulling", options.backFaceCulling); + bindProperty(this, 'backFaceCulling', options.backFaceCulling); this._backFaceCulling = this.backFaceCulling; // Whether to enable normal shading this.normalShading = true; - bindProperty(this, "normalShading", options.normalShading); + bindProperty(this, 'normalShading', options.normalShading); this._normalShading = this.normalShading; this._opaqueRenderState = undefined; From 39ade84b2b35d870dff588cdca1e21eb288fe2e4 Mon Sep 17 00:00:00 2001 From: George Vinokhodov Date: Fri, 28 Dec 2018 18:43:40 +0300 Subject: [PATCH 03/10] refs #5152 moved properties to pointCloudShading --- Source/Scene/Cesium3DTileset.js | 18 ------------ Source/Scene/PointCloud.js | 37 +++++++++++++------------ Source/Scene/PointCloud3DTileContent.js | 3 +- Source/Scene/PointCloudShading.js | 16 +++++++++++ Source/Scene/TimeDynamicPointCloud.js | 6 +++- 5 files changed, 42 insertions(+), 38 deletions(-) diff --git a/Source/Scene/Cesium3DTileset.js b/Source/Scene/Cesium3DTileset.js index 10780186ec38..bf211d7dc215 100644 --- a/Source/Scene/Cesium3DTileset.js +++ b/Source/Scene/Cesium3DTileset.js @@ -295,24 +295,6 @@ define([ */ this.shadows = defaultValue(options.shadows, ShadowMode.ENABLED); - /** - * Determines whether backfaces of points / mesh are hidden - * - * @type {boolean} - * @default false - */ - var backFaceCulling = defaultValue(options.backFaceCulling, false); - this.backFaceCulling = new ConstantProperty(backFaceCulling); - - /** - * Determines whether the tileset is lighted by the sun - * - * @type {boolean} - * @default true - */ - var normalShading = defaultValue(options.normalShading, true); - this.normalShading = new ConstantProperty(normalShading); - /** * Determines if the tileset will be shown. * diff --git a/Source/Scene/PointCloud.js b/Source/Scene/PointCloud.js index 904e1c61bef5..4a443fbcf911 100644 --- a/Source/Scene/PointCloud.js +++ b/Source/Scene/PointCloud.js @@ -147,14 +147,15 @@ define([ this._quantizedRange = 0.0; this._octEncodedRange = 0.0; + this._pointCloudShading = defaultValue(options.shading, { + backFaceCulling : false, + normalShading : true + }); + // Use per-point normals to hide back-facing points. - this.backFaceCulling = false; - bindProperty(this, 'backFaceCulling', options.backFaceCulling); this._backFaceCulling = this.backFaceCulling; // Whether to enable normal shading - this.normalShading = true; - bindProperty(this, 'normalShading', options.normalShading); this._normalShading = this.normalShading; this._opaqueRenderState = undefined; @@ -248,21 +249,23 @@ define([ set : function(value) { this._boundingSphere = BoundingSphere.clone(value); } + }, + + backFaceCulling : { + get : function() { + return this._pointCloudShading.backFaceCulling; + } + }, + + normalShading : { + get : function() { + return this._pointCloudShading.normalShading; + } } }); var sizeOfUint32 = Uint32Array.BYTES_PER_ELEMENT; - function bindProperty(object, field, property) { - if (property) { - var val = property.getValue(); - object[field] = val; - property.definitionChanged.addEventListener(function(newValue) { - object[field] = newValue.getValue(); - }); - } - } - function initialize(pointCloud, options) { var arrayBuffer = options.arrayBuffer; var byteOffset = defaultValue(options.byteOffset, 0); @@ -1142,6 +1145,7 @@ define([ } else { vs += ' vec3 normal = a_normal; \n'; } + vs += ' vec3 view_normal = czm_normal * normal; \n'; } else { vs += ' vec3 normal = vec3(1.0); \n'; } @@ -1168,8 +1172,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, view_normal); \n' + ' diffuseStrength = max(diffuseStrength, 0.4); \n' + // Apply some ambient lighting ' color.xyz *= diffuseStrength; \n'; } @@ -1178,7 +1181,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(-view_normal.z, 0.0); \n' + ' gl_Position *= visible; \n' + ' gl_PointSize *= visible; \n'; } diff --git a/Source/Scene/PointCloud3DTileContent.js b/Source/Scene/PointCloud3DTileContent.js index 740627fcdaf4..875ccf1471c4 100644 --- a/Source/Scene/PointCloud3DTileContent.js +++ b/Source/Scene/PointCloud3DTileContent.js @@ -71,8 +71,7 @@ define([ uniformMapLoaded : getUniformMapLoaded(this), batchTableLoaded : getBatchTableLoaded(this), pickIdLoaded : getPickIdLoaded(this), - normalShading : tileset.normalShading, - backfaceCulling : tileset.backfaceCulling + shading : tileset.pointCloudShading }); } diff --git a/Source/Scene/PointCloudShading.js b/Source/Scene/PointCloudShading.js index f466c038ad8b..49a7bfd6d15f 100644 --- a/Source/Scene/PointCloudShading.js +++ b/Source/Scene/PointCloudShading.js @@ -76,6 +76,22 @@ define([ * @default 1.0 */ this.eyeDomeLightingRadius = defaultValue(pointCloudShading.eyeDomeLightingRadius, 1.0); + + /** + * Determines whether backfaces of points / mesh are hidden + * + * @type {boolean} + * @default false + */ + this.backFaceCulling = defaultValue(pointCloudShading.backFaceCulling, false); + + /** + * Determines whether the tileset is lighted by the sun + * + * @type {boolean} + * @default true + */ + this.normalShading = defaultValue(pointCloudShading.normalShading, true); } /** diff --git a/Source/Scene/TimeDynamicPointCloud.js b/Source/Scene/TimeDynamicPointCloud.js index 5ee29f81670f..d385c4519573 100644 --- a/Source/Scene/TimeDynamicPointCloud.js +++ b/Source/Scene/TimeDynamicPointCloud.js @@ -151,6 +151,9 @@ define([ */ this.style = options.style; + this.normalShading = options.normalShading; + this.backFaceCulling = options.backFaceCulling; + /** * The event fired to indicate that a frame failed to load. A frame may fail to load if the * request for its uri fails or processing fails due to invalid content. @@ -420,7 +423,8 @@ define([ cull : true, fragmentShaderLoaded : getFragmentShaderLoaded, uniformMapLoaded : getUniformMapLoaded(that), - pickIdLoaded : getPickIdLoaded + pickIdLoaded : getPickIdLoaded, + shading : that.shading }); return frame.pointCloud.readyPromise; }).otherwise(handleFrameFailure(that, uri)); From 40c5a124a1c4ab32ad58eedaeb907709e185e7f5 Mon Sep 17 00:00:00 2001 From: George Vinokhodov Date: Fri, 28 Dec 2018 18:49:59 +0300 Subject: [PATCH 04/10] refs #5152 cleaning --- Source/Scene/Cesium3DTileset.js | 2 -- Source/Scene/PointCloud.js | 2 -- Source/Scene/TimeDynamicPointCloud.js | 3 --- 3 files changed, 7 deletions(-) diff --git a/Source/Scene/Cesium3DTileset.js b/Source/Scene/Cesium3DTileset.js index bf211d7dc215..8b394390f0b6 100644 --- a/Source/Scene/Cesium3DTileset.js +++ b/Source/Scene/Cesium3DTileset.js @@ -20,7 +20,6 @@ define([ '../Core/Resource', '../Core/RuntimeError', '../Core/Transforms', - '../DataSources/ConstantProperty', '../Renderer/ClearCommand', '../Renderer/Pass', '../ThirdParty/when', @@ -66,7 +65,6 @@ define([ Resource, RuntimeError, Transforms, - ConstantProperty, ClearCommand, Pass, when, diff --git a/Source/Scene/PointCloud.js b/Source/Scene/PointCloud.js index 4a443fbcf911..700734f2b33c 100644 --- a/Source/Scene/PointCloud.js +++ b/Source/Scene/PointCloud.js @@ -21,7 +21,6 @@ define([ '../Core/PrimitiveType', '../Core/RuntimeError', '../Core/Transforms', - '../DataSources/ConstantProperty', '../Renderer/Buffer', '../Renderer/BufferUsage', '../Renderer/DrawCommand', @@ -63,7 +62,6 @@ define([ PrimitiveType, RuntimeError, Transforms, - ConstantProperty, Buffer, BufferUsage, DrawCommand, diff --git a/Source/Scene/TimeDynamicPointCloud.js b/Source/Scene/TimeDynamicPointCloud.js index d385c4519573..e3f74eeb4c40 100644 --- a/Source/Scene/TimeDynamicPointCloud.js +++ b/Source/Scene/TimeDynamicPointCloud.js @@ -151,9 +151,6 @@ define([ */ this.style = options.style; - this.normalShading = options.normalShading; - this.backFaceCulling = options.backFaceCulling; - /** * The event fired to indicate that a frame failed to load. A frame may fail to load if the * request for its uri fails or processing fails due to invalid content. From 98fae384414e1f1a46ec8069f1ae03544093768e Mon Sep 17 00:00:00 2001 From: George Vinokhodov Date: Thu, 7 Feb 2019 19:22:22 +0300 Subject: [PATCH 05/10] Changed default shading from raw object to PointCloudShading Also some variables renamed, description changed --- Source/Scene/PointCloud.js | 11 ++++------- Source/Scene/PointCloudShading.js | 9 +++++---- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/Source/Scene/PointCloud.js b/Source/Scene/PointCloud.js index 700734f2b33c..3c5916d46b39 100644 --- a/Source/Scene/PointCloud.js +++ b/Source/Scene/PointCloud.js @@ -145,10 +145,7 @@ define([ this._quantizedRange = 0.0; this._octEncodedRange = 0.0; - this._pointCloudShading = defaultValue(options.shading, { - backFaceCulling : false, - normalShading : true - }); + this._pointCloudShading = defined(options.shading) ? options.shading : new PointCloudShading(); // Use per-point normals to hide back-facing points. this._backFaceCulling = this.backFaceCulling; @@ -1143,7 +1140,7 @@ define([ } else { vs += ' vec3 normal = a_normal; \n'; } - vs += ' vec3 view_normal = czm_normal * normal; \n'; + vs += ' vec3 normalEC = czm_normal * normal; \n'; } else { vs += ' vec3 normal = vec3(1.0); \n'; } @@ -1170,7 +1167,7 @@ define([ vs += ' color = color * u_highlightColor; \n'; if (usesNormals && normalShading) { - vs += ' float diffuseStrength = czm_getLambertDiffuse(czm_sunDirectionEC, view_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'; } @@ -1179,7 +1176,7 @@ define([ ' gl_Position = czm_modelViewProjection * vec4(position, 1.0); \n'; if (usesNormals && backFaceCulling) { - vs += ' float visible = step(-view_normal.z, 0.0); \n' + + vs += ' float visible = step(-normalEC.z, 0.0); \n' + ' gl_Position *= visible; \n' + ' gl_PointSize *= visible; \n'; } diff --git a/Source/Scene/PointCloudShading.js b/Source/Scene/PointCloudShading.js index 49a7bfd6d15f..6ee38183021c 100644 --- a/Source/Scene/PointCloudShading.js +++ b/Source/Scene/PointCloudShading.js @@ -78,17 +78,18 @@ define([ this.eyeDomeLightingRadius = defaultValue(pointCloudShading.eyeDomeLightingRadius, 1.0); /** - * Determines whether backfaces of points / mesh are hidden + * Determines whether backfaces of points / mesh are hidden. + * For point cloud this option works only, if data has normals. * - * @type {boolean} + * @type {Boolean} * @default false */ this.backFaceCulling = defaultValue(pointCloudShading.backFaceCulling, false); /** - * Determines whether the tileset is lighted by the sun + * Determines whether a point cloud that contains normals is shaded based on the sun direction. * - * @type {boolean} + * @type {Boolean} * @default true */ this.normalShading = defaultValue(pointCloudShading.normalShading, true); From acf191f7807cc3cbc2d0e5573a10402c914d06af Mon Sep 17 00:00:00 2001 From: George Vinokhodov Date: Thu, 7 Feb 2019 19:32:46 +0300 Subject: [PATCH 06/10] small description fix --- Source/Scene/PointCloudShading.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/Scene/PointCloudShading.js b/Source/Scene/PointCloudShading.js index 6ee38183021c..906a9ee8fe29 100644 --- a/Source/Scene/PointCloudShading.js +++ b/Source/Scene/PointCloudShading.js @@ -78,8 +78,8 @@ define([ this.eyeDomeLightingRadius = defaultValue(pointCloudShading.eyeDomeLightingRadius, 1.0); /** - * Determines whether backfaces of points / mesh are hidden. - * For point cloud this option works only, if data has normals. + * Determines whether backfaces of points are hidden. + * This option works only if data has normals included. * * @type {Boolean} * @default false From 2570c8c5a1a7c509d01ce35a0464ebc442177101 Mon Sep 17 00:00:00 2001 From: Sean Lilley Date: Thu, 14 Mar 2019 13:30:30 -0400 Subject: [PATCH 07/10] Added options to doc --- Source/Scene/PointCloudShading.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Source/Scene/PointCloudShading.js b/Source/Scene/PointCloudShading.js index 906a9ee8fe29..ba5baf55c2be 100644 --- a/Source/Scene/PointCloudShading.js +++ b/Source/Scene/PointCloudShading.js @@ -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 @@ -78,7 +80,7 @@ define([ this.eyeDomeLightingRadius = defaultValue(pointCloudShading.eyeDomeLightingRadius, 1.0); /** - * Determines whether backfaces of points are hidden. + * Determines whether back-facing points are hidden. * This option works only if data has normals included. * * @type {Boolean} From c3076a12df391118a994ddd7de94a960c1284a18 Mon Sep 17 00:00:00 2001 From: Sean Lilley Date: Thu, 14 Mar 2019 13:33:33 -0400 Subject: [PATCH 08/10] Updated CHANGES.md --- CHANGES.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES.md b/CHANGES.md index 9115b1783f55..a328b9eabd67 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -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) From 667fa58c6697ed46fa96c4ecb9add36ab10a167c Mon Sep 17 00:00:00 2001 From: Sean Lilley Date: Thu, 14 Mar 2019 14:18:16 -0400 Subject: [PATCH 09/10] Some changes --- Source/Scene/PointCloud.js | 20 ++++---------------- Source/Scene/PointCloud3DTileContent.js | 16 ++++++++++------ Source/Scene/TimeDynamicPointCloud.js | 19 ++++++++++--------- Specs/Scene/PointCloudShadingSpec.js | 8 +++++++- 4 files changed, 31 insertions(+), 32 deletions(-) diff --git a/Source/Scene/PointCloud.js b/Source/Scene/PointCloud.js index 64c2c295d068..490605e6b775 100644 --- a/Source/Scene/PointCloud.js +++ b/Source/Scene/PointCloud.js @@ -147,13 +147,13 @@ define([ this._quantizedRange = 0.0; this._octEncodedRange = 0.0; - this._pointCloudShading = defined(options.shading) ? options.shading : new PointCloudShading(); - // Use per-point normals to hide back-facing points. - this._backFaceCulling = this.backFaceCulling; + this.backFaceCulling = false; + this._backFaceCulling = false; // Whether to enable normal shading - this._normalShading = this.normalShading; + this.normalShading = true; + this._normalShading = true; this._opaqueRenderState = undefined; this._translucentRenderState = undefined; @@ -246,18 +246,6 @@ define([ set : function(value) { this._boundingSphere = BoundingSphere.clone(value); } - }, - - backFaceCulling : { - get : function() { - return this._pointCloudShading.backFaceCulling; - } - }, - - normalShading : { - get : function() { - return this._pointCloudShading.normalShading; - } } }); diff --git a/Source/Scene/PointCloud3DTileContent.js b/Source/Scene/PointCloud3DTileContent.js index 875ccf1471c4..bfd994b978e3 100644 --- a/Source/Scene/PointCloud3DTileContent.js +++ b/Source/Scene/PointCloud3DTileContent.js @@ -14,6 +14,7 @@ define([ './Cesium3DTileFeature', './Cesium3DTileRefine', './PointCloud', + './PointCloudShading', './SceneMode' ], function( Color, @@ -31,6 +32,7 @@ define([ Cesium3DTileFeature, Cesium3DTileRefine, PointCloud, + PointCloudShading, SceneMode) { 'use strict'; @@ -70,8 +72,7 @@ define([ fragmentShaderLoaded : getFragmentShaderLoaded(this), uniformMapLoaded : getUniformMapLoaded(this), batchTableLoaded : getBatchTableLoaded(this), - pickIdLoaded : getPickIdLoaded(this), - shading : tileset.pointCloudShading + pickIdLoaded : getPickIdLoaded(this) }); } @@ -271,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; @@ -301,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; @@ -311,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) { diff --git a/Source/Scene/TimeDynamicPointCloud.js b/Source/Scene/TimeDynamicPointCloud.js index e3f74eeb4c40..3add0294640f 100644 --- a/Source/Scene/TimeDynamicPointCloud.js +++ b/Source/Scene/TimeDynamicPointCloud.js @@ -420,8 +420,7 @@ define([ cull : true, fragmentShaderLoaded : getFragmentShaderLoaded, uniformMapLoaded : getUniformMapLoaded(that), - pickIdLoaded : getPickIdLoaded, - shading : that.shading + pickIdLoaded : getPickIdLoaded }); return frame.pointCloud.readyPromise; }).otherwise(handleFrameFailure(that, uri)); @@ -491,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); @@ -500,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; } diff --git a/Specs/Scene/PointCloudShadingSpec.js b/Specs/Scene/PointCloudShadingSpec.js index a08282804630..ffac43d24946 100644 --- a/Specs/Scene/PointCloudShadingSpec.js +++ b/Specs/Scene/PointCloudShadingSpec.js @@ -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); @@ -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() { From 5045510b347f2cd3b598d2c9bb73e0b3130961a6 Mon Sep 17 00:00:00 2001 From: Sean Lilley Date: Thu, 14 Mar 2019 14:25:06 -0400 Subject: [PATCH 10/10] Fix test --- Specs/Scene/PointCloud3DTileContentSpec.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Specs/Scene/PointCloud3DTileContentSpec.js b/Specs/Scene/PointCloud3DTileContentSpec.js index 4ad043335eea..c41613d0ce8b 100644 --- a/Specs/Scene/PointCloud3DTileContentSpec.js +++ b/Specs/Scene/PointCloud3DTileContentSpec.js @@ -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; @@ -487,7 +487,7 @@ defineSuite([ } // Set culling to false - content._pointCloud.backFaceCulling = false; + tileset.pointCloudShading.backFaceCulling = false; expect(scene).toPickAndCall(function(result) { picked = result;