From e610befe33e02abc4d76fe1e8af426133ae01cd5 Mon Sep 17 00:00:00 2001 From: Sean Lilley Date: Wed, 19 Dec 2018 22:15:15 -0500 Subject: [PATCH 01/12] Temp --- Source/Renderer/AutomaticUniforms.js | 5 ++-- Source/Scene/GlobeDepth.js | 35 ++++++++++++++++++++++++++-- 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/Source/Renderer/AutomaticUniforms.js b/Source/Renderer/AutomaticUniforms.js index 988f6dbe5c9e..4fc2ed0d50e1 100644 --- a/Source/Renderer/AutomaticUniforms.js +++ b/Source/Renderer/AutomaticUniforms.js @@ -167,8 +167,9 @@ define([ }), /** - * An automatic GLSL uniform representing the depth after - * only the globe has been rendered and packed into an RGBA texture. + * An automatic GLSL uniform representing the depth of the scene + * after the globe pass and then updated after the 3D Tiles pass. + * The depth is packed into an RGBA texture. * * @private * diff --git a/Source/Scene/GlobeDepth.js b/Source/Scene/GlobeDepth.js index 7076b8ae5f2d..163413c08f47 100644 --- a/Source/Scene/GlobeDepth.js +++ b/Source/Scene/GlobeDepth.js @@ -16,7 +16,10 @@ define([ '../Renderer/TextureMinificationFilter', '../Shaders/PostProcessStages/DepthViewPacked', '../Shaders/PostProcessStages/PassThrough', - '../Shaders/PostProcessStages/PassThroughDepth' + '../Shaders/PostProcessStages/PassThroughDepth', + './StencilConstants', + './StencilFunction', + './StencilOperation' ], function( BoundingRectangle, Color, @@ -35,7 +38,10 @@ define([ TextureMinificationFilter, DepthViewPacked, PassThrough, - PassThroughDepth) { + PassThroughDepth, + StencilConstants, + StencilFunction, + StencilOperation) { 'use strict'; /** @@ -52,6 +58,7 @@ define([ this._clearColorCommand = undefined; this._copyColorCommand = undefined; this._copyDepthCommand = undefined; + this._updateDepthCommand = undefined; this._viewport = new BoundingRectangle(); this._rs = undefined; @@ -223,6 +230,26 @@ define([ }); } + if (!defined(globeDepth._updateDepthCommand)) { + globeDepth._updateDepthCommand = context.createViewportQuadCommand(PassThroughDepth, { + owner : globeDepth, + renderState : RenderState.fromCache({ + stencilTest : { + enabled : true, + frontFunction : StencilFunction.EQUAL, + frontOperation : { + fail : StencilOperation.KEEP, + zFail : StencilOperation.KEEP, + zPass : StencilOperation.KEEP + }, + backFunction : StencilFunction.NEVER, + reference : StencilConstants.CESIUM_3D_TILE_MASK, + mask : StencilConstants.CESIUM_3D_TILE_MASK + } + }) + }); + } + globeDepth._copyDepthCommand.renderState = globeDepth._rs; globeDepth._copyColorCommand.renderState = globeDepth._rs; @@ -259,6 +286,10 @@ define([ } }; + GlobeDepth.prototype.updateDepth = function(context, passState) { + if (defined(this._copyDepthCommand + }; + GlobeDepth.prototype.executeCopyColor = function(context, passState) { if (defined(this._copyColorCommand)) { this._copyColorCommand.execute(context, passState); From bb1e49c7ef53811a9f7c3a7b0a030480e4ba7f4d Mon Sep 17 00:00:00 2001 From: Sean Lilley Date: Thu, 20 Dec 2018 10:38:12 -0500 Subject: [PATCH 02/12] Update GlobeDepth after 3D Tiles pass --- Source/Scene/GlobeDepth.js | 135 +++++++++++++++++++++++++++++-------- Source/Scene/Scene.js | 10 ++- 2 files changed, 117 insertions(+), 28 deletions(-) diff --git a/Source/Scene/GlobeDepth.js b/Source/Scene/GlobeDepth.js index 163413c08f47..188e07450832 100644 --- a/Source/Scene/GlobeDepth.js +++ b/Source/Scene/GlobeDepth.js @@ -51,23 +51,29 @@ define([ this._colorTexture = undefined; this._depthStencilTexture = undefined; this._globeDepthTexture = undefined; + this._tempGlobeDepthTexture = undefined; this.framebuffer = undefined; this._copyDepthFramebuffer = undefined; + this._tempCopyDepthFramebuffer = undefined; + this._updateDepthFramebuffer = undefined; this._clearColorCommand = undefined; this._copyColorCommand = undefined; this._copyDepthCommand = undefined; + this._tempCopyDepthCommand = undefined; this._updateDepthCommand = undefined; this._viewport = new BoundingRectangle(); this._rs = undefined; + this._rsUpdate = undefined; this._useScissorTest = false; this._scissorRectangle = undefined; this._useLogDepth = undefined; this._useHdr = undefined; + this._clearGlobeDepth = false; this._debugGlobeDepthViewportCommand = undefined; } @@ -111,14 +117,17 @@ define([ globeDepth._colorTexture = globeDepth._colorTexture && !globeDepth._colorTexture.isDestroyed() && globeDepth._colorTexture.destroy(); globeDepth._depthStencilTexture = globeDepth._depthStencilTexture && !globeDepth._depthStencilTexture.isDestroyed() && globeDepth._depthStencilTexture.destroy(); globeDepth._globeDepthTexture = globeDepth._globeDepthTexture && !globeDepth._globeDepthTexture.isDestroyed() && globeDepth._globeDepthTexture.destroy(); + globeDepth._tempGlobeDepthTexture = globeDepth._tempGlobeDepthTexture && !globeDepth._tempGlobeDepthTexture.isDestroyed() && globeDepth._tempGlobeDepthTexture.destroy(); } function destroyFramebuffers(globeDepth) { globeDepth.framebuffer = globeDepth.framebuffer && !globeDepth.framebuffer.isDestroyed() && globeDepth.framebuffer.destroy(); globeDepth._copyDepthFramebuffer = globeDepth._copyDepthFramebuffer && !globeDepth._copyDepthFramebuffer.isDestroyed() && globeDepth._copyDepthFramebuffer.destroy(); + globeDepth._tempCopyDepthFramebuffer = globeDepth._tempCopyDepthFramebuffer && !globeDepth._tempCopyDepthFramebuffer.isDestroyed() && globeDepth._tempCopyDepthFramebuffer.destroy(); + globeDepth._updateDepthFramebuffer = globeDepth._updateDepthFramebuffer && !globeDepth._updateDepthFramebuffer.isDestroyed() && globeDepth._updateDepthFramebuffer.destroy(); } - function createTextures(globeDepth, context, width, height, hdr) { + function createTextures(globeDepth, context, width, height, hdr, clearGlobeDepth) { var pixelDatatype = hdr ? (context.halfFloatingPointTexture ? PixelDatatype.HALF_FLOAT : PixelDatatype.FLOAT) : PixelDatatype.UNSIGNED_BYTE; globeDepth._colorTexture = new Texture({ context : context, @@ -155,9 +164,25 @@ define([ magnificationFilter : TextureMagnificationFilter.NEAREST }) }); + + if (clearGlobeDepth) { + globeDepth._tempGlobeDepthTexture = new Texture({ + context : context, + width : width, + height : height, + pixelFormat : PixelFormat.RGBA, + pixelDatatype : PixelDatatype.UNSIGNED_BYTE, + sampler : new Sampler({ + wrapS : TextureWrap.CLAMP_TO_EDGE, + wrapT : TextureWrap.CLAMP_TO_EDGE, + minificationFilter : TextureMinificationFilter.NEAREST, + magnificationFilter : TextureMagnificationFilter.NEAREST + }) + }); + } } - function createFramebuffers(globeDepth, context) { + function createFramebuffers(globeDepth, context, clearGlobeDepth) { globeDepth.framebuffer = new Framebuffer({ context : context, colorTextures : [globeDepth._colorTexture], @@ -170,16 +195,31 @@ define([ colorTextures : [globeDepth._globeDepthTexture], destroyAttachments : false }); + + if (clearGlobeDepth) { + globeDepth._tempCopyDepthFramebuffer = new Framebuffer({ + context : context, + colorTextures : [globeDepth._tempGlobeDepthTexture], + destroyAttachments : false + }); + globeDepth._updateDepthFramebuffer = new Framebuffer({ + context : context, + colorTextures : [globeDepth._globeDepthTexture], + depthStencilTexture : globeDepth._depthStencilTexture, + destroyAttachments : false + }); + } } - function updateFramebuffers(globeDepth, context, width, height, hdr) { + function updateFramebuffers(globeDepth, context, width, height, hdr, clearGlobeDepth) { var colorTexture = globeDepth._colorTexture; var textureChanged = !defined(colorTexture) || colorTexture.width !== width || colorTexture.height !== height || hdr !== globeDepth._useHdr; - if (!defined(globeDepth.framebuffer) || textureChanged) { + var clearGlobeDepthChanged = clearGlobeDepth !== globeDepth._clearGlobeDepth; + if (!defined(globeDepth.framebuffer) || textureChanged || clearGlobeDepthChanged) { destroyTextures(globeDepth); destroyFramebuffers(globeDepth); - createTextures(globeDepth, context, width, height, hdr); - createFramebuffers(globeDepth, context); + createTextures(globeDepth, context, width, height, hdr, clearGlobeDepth); + createFramebuffers(globeDepth, context, clearGlobeDepth); } } @@ -204,6 +244,26 @@ define([ rectangle : globeDepth._scissorRectangle } }); + // Copy packed depth only if the 3D Tiles bit is set + globeDepth._rsUpdate = RenderState.fromCache({ + viewport : globeDepth._viewport, + scissorTest : { + enabled : globeDepth._useScissorTest, + rectangle : globeDepth._scissorRectangle + }, + stencilTest : { + enabled : true, + frontFunction : StencilFunction.EQUAL, + frontOperation : { + fail : StencilOperation.KEEP, + zFail : StencilOperation.KEEP, + zPass : StencilOperation.KEEP + }, + backFunction : StencilFunction.NEVER, + reference : StencilConstants.CESIUM_3D_TILE_MASK, + mask : StencilConstants.CESIUM_3D_TILE_MASK + } + }); } if (!defined(globeDepth._copyDepthCommand)) { @@ -218,6 +278,7 @@ define([ } globeDepth._copyDepthCommand.framebuffer = globeDepth._copyDepthFramebuffer; + globeDepth._copyDepthCommand.renderState = globeDepth._rs; if (!defined(globeDepth._copyColorCommand)) { globeDepth._copyColorCommand = context.createViewportQuadCommand(PassThrough, { @@ -230,28 +291,33 @@ define([ }); } + if (!defined(globeDepth._tempCopyDepthCommand)) { + globeDepth._tempCopyDepthCommand = context.createViewportQuadCommand(PassThroughDepth, { + uniformMap : { + u_depthTexture : function() { + return globeDepth._depthStencilTexture; + } + }, + owner : globeDepth + }); + } + + globeDepth._tempCopyDepthCommand.framebuffer = globeDepth._tempCopyDepthFramebuffer; + globeDepth._tempCopyDepthCommand.renderState = globeDepth._rs; + if (!defined(globeDepth._updateDepthCommand)) { - globeDepth._updateDepthCommand = context.createViewportQuadCommand(PassThroughDepth, { - owner : globeDepth, - renderState : RenderState.fromCache({ - stencilTest : { - enabled : true, - frontFunction : StencilFunction.EQUAL, - frontOperation : { - fail : StencilOperation.KEEP, - zFail : StencilOperation.KEEP, - zPass : StencilOperation.KEEP - }, - backFunction : StencilFunction.NEVER, - reference : StencilConstants.CESIUM_3D_TILE_MASK, - mask : StencilConstants.CESIUM_3D_TILE_MASK + globeDepth._updateDepthCommand = context.createViewportQuadCommand(PassThrough, { + uniformMap : { + colorTexture : function() { + return globeDepth._tempGlobeDepthTexture; } - }) + }, + owner : globeDepth }); } - globeDepth._copyDepthCommand.renderState = globeDepth._rs; - globeDepth._copyColorCommand.renderState = globeDepth._rs; + globeDepth._updateDepthCommand.framebuffer = globeDepth._updateDepthFramebuffer; + globeDepth._updateDepthCommand.renderState = globeDepth._rsUpdate; if (!defined(globeDepth._clearColorCommand)) { globeDepth._clearColorCommand = new ClearCommand({ @@ -268,15 +334,16 @@ define([ executeDebugGlobeDepth(this, context, passState, useLogDepth); }; - GlobeDepth.prototype.update = function(context, passState, viewport, hdr) { + GlobeDepth.prototype.update = function(context, passState, viewport, hdr, clearGlobeDepth) { var width = viewport.width; var height = viewport.height; - updateFramebuffers(this, context, width, height, hdr); + updateFramebuffers(this, context, width, height, hdr, clearGlobeDepth); updateCopyCommands(this, context, width, height, passState); context.uniformState.globeDepthTexture = undefined; this._useHdr = hdr; + this._clearGlobeDepth = clearGlobeDepth; }; GlobeDepth.prototype.executeCopyDepth = function(context, passState) { @@ -286,8 +353,22 @@ define([ } }; - GlobeDepth.prototype.updateDepth = function(context, passState) { - if (defined(this._copyDepthCommand + GlobeDepth.prototype.executeUpdateDepth = function(context, passState, clearGlobeDepth) { + if (clearGlobeDepth) { + // First copy the depth to a temporary globe depth texture, then update the + // main globe depth texture where the stencil bit for 3D Tiles is set. + // This preserves the original globe depth except where 3D Tiles is rendered. + if (defined(this._tempCopyDepthCommand) && defined(this._updateDepthCommand)) { + this._tempCopyDepthCommand.execute(context, passState); + this._updateDepthCommand.execute(context, passState); + } + return; + } + + // Fast path - the depth texture can be copied normally. + if (defined(this._copyDepthCommand)) { + this._copyDepthCommand.execute(context, passState); + } }; GlobeDepth.prototype.executeCopyColor = function(context, passState) { diff --git a/Source/Scene/Scene.js b/Source/Scene/Scene.js index 92823beab81b..95166c3bbf12 100644 --- a/Source/Scene/Scene.js +++ b/Source/Scene/Scene.js @@ -2243,6 +2243,10 @@ define([ executeCommand(commands[j], scene, context, passState); } + if (defined(globeDepth) && environmentState.useGlobeDepthFramebuffer) { + globeDepth.executeUpdateDepth(context, passState, clearGlobeDepth); + } + // Draw classifications. Modifies 3D Tiles color. us.updatePass(Pass.CESIUM_3D_TILE_CLASSIFICATION); commands = frustumCommands.commands[Pass.CESIUM_3D_TILE_CLASSIFICATION]; @@ -2296,6 +2300,10 @@ define([ executeCommand(commands[j], scene, context, passState); } + if (defined(globeDepth) && environmentState.useGlobeDepthFramebuffer) { + globeDepth.executeUpdateDepth(context, passState, clearGlobeDepth); + } + // Set stencil us.updatePass(Pass.CESIUM_3D_TILE_CLASSIFICATION_IGNORE_SHOW); commands = frustumCommands.commands[Pass.CESIUM_3D_TILE_CLASSIFICATION_IGNORE_SHOW]; @@ -2926,7 +2934,7 @@ define([ // Globe depth is copied for the pick pass to support picking batched geometries in GroundPrimitives. var useGlobeDepthFramebuffer = environmentState.useGlobeDepthFramebuffer = defined(view.globeDepth); if (useGlobeDepthFramebuffer) { - view.globeDepth.update(context, passState, view.viewport, scene._hdr); + view.globeDepth.update(context, passState, view.viewport, scene._hdr, environmentState.clearGlobeDepth); view.globeDepth.clear(context, passState, clearColor); } From dd45faa902ddf65d86f7f7ac23e6d8dd06d239ae Mon Sep 17 00:00:00 2001 From: Sean Lilley Date: Thu, 20 Dec 2018 11:59:37 -0500 Subject: [PATCH 03/12] Support ground primitive batches for all classification types --- Source/DataSources/GeometryVisualizer.js | 25 +++---- .../StaticGroundGeometryPerMaterialBatch.js | 10 +-- Source/Scene/GroundPrimitive.js | 8 +-- Specs/DataSources/GeometryVisualizerSpec.js | 66 ------------------- ...taticGroundGeometryPerMaterialBatchSpec.js | 14 ++-- 5 files changed, 23 insertions(+), 100 deletions(-) diff --git a/Source/DataSources/GeometryVisualizer.js b/Source/DataSources/GeometryVisualizer.js index 2f70c1eb260a..1ccbea669c13 100644 --- a/Source/DataSources/GeometryVisualizer.js +++ b/Source/DataSources/GeometryVisualizer.js @@ -173,27 +173,21 @@ define([ var groundColorBatches = new Array(numberOfClassificationTypes); var groundMaterialBatches = []; if (supportsMaterialsforEntitiesOnTerrain) { - // Culling, phong shading only supported for ClassificationType.TERRAIN at the moment because - // tileset depth information not yet available. - groundColorBatches[ClassificationType.TERRAIN] = new StaticGroundGeometryPerMaterialBatch(groundPrimitives, PerInstanceColorAppearance); for (i = 0; i < numberOfClassificationTypes; ++i) { - if (i !== ClassificationType.TERRAIN) { - groundColorBatches[i] = new StaticGroundGeometryColorBatch(groundPrimitives, i); - } - } - groundMaterialBatches[0] = new StaticGroundGeometryPerMaterialBatch(groundPrimitives, MaterialAppearance); - this._groundTerrainMaterialBatch = groundMaterialBatches[0]; - } else { - for (i = 0; i < numberOfClassificationTypes; ++i) { - groundColorBatches[i] = new StaticGroundGeometryColorBatch(groundPrimitives, i); + groundMaterialBatches.push(new StaticGroundGeometryPerMaterialBatch(groundPrimitives, i, MaterialAppearance)); } } + for (i = 0; i < numberOfClassificationTypes; ++i) { + groundColorBatches[i] = new StaticGroundGeometryColorBatch(groundPrimitives, i); + } + this._groundColorBatches = groundColorBatches; + this._groundMaterialBatches = groundMaterialBatches; this._dynamicBatch = new DynamicGeometryBatch(primitives, groundPrimitives); - this._batches = this._outlineBatches.concat(this._closedColorBatches, this._closedMaterialBatches, this._openColorBatches, this._openMaterialBatches, this._groundColorBatches, groundMaterialBatches, 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(); @@ -414,10 +408,7 @@ define([ this._groundColorBatches[classificationType].add(time, updater); } else { // If unsupported, updater will not be on terrain. - // If the updater has a material, ignore input ClassificationType for now and only classify terrain. - // Culling, phong shading only supported for ClassificationType.TERRAIN at the moment because - // tileset depth information not yet available. - this._groundTerrainMaterialBatch.add(time, updater); + this._groundMaterialBatches[classificationType].add(time, updater); } } else if (updater.isClosed) { if (updater.fillMaterialProperty instanceof ColorMaterialProperty) { diff --git a/Source/DataSources/StaticGroundGeometryPerMaterialBatch.js b/Source/DataSources/StaticGroundGeometryPerMaterialBatch.js index c4fe25feea59..b761892ae5ff 100644 --- a/Source/DataSources/StaticGroundGeometryPerMaterialBatch.js +++ b/Source/DataSources/StaticGroundGeometryPerMaterialBatch.js @@ -34,8 +34,9 @@ define([ var defaultDistanceDisplayCondition = new DistanceDisplayCondition(); // Encapsulates a Primitive and all the entities that it represents. - function Batch(primitives, appearanceType, materialProperty, usingSphericalTextureCoordinates, zIndex) { + function Batch(primitives, classificationType, appearanceType, materialProperty, usingSphericalTextureCoordinates, zIndex) { this.primitives = primitives; // scene level primitive collection + this.classificationType = classificationType; this.appearanceType = appearanceType; this.materialProperty = materialProperty; this.updaters = new AssociativeArray(); @@ -142,7 +143,7 @@ define([ material : this.material // translucent and closed properties overridden }), - classificationType : ClassificationType.TERRAIN + classificationType : this.classificationType }); primitives.add(primitive, this.zIndex); @@ -266,9 +267,10 @@ define([ /** * @private */ - function StaticGroundGeometryPerMaterialBatch(primitives, appearanceType) { + function StaticGroundGeometryPerMaterialBatch(primitives, classificationType, appearanceType) { this._items = []; this._primitives = primitives; + this._classificationType = classificationType; this._appearanceType = appearanceType; } @@ -293,7 +295,7 @@ define([ } } // If a compatible batch wasn't found, create a new batch. - var batch = new Batch(this._primitives, this._appearanceType, updater.fillMaterialProperty, usingSphericalTextureCoordinates, zIndex); + var batch = new Batch(this._primitives, this._classificationType, this._appearanceType, updater.fillMaterialProperty, usingSphericalTextureCoordinates, zIndex); batch.add(time, updater, geometryInstance); items.push(batch); }; diff --git a/Source/Scene/GroundPrimitive.js b/Source/Scene/GroundPrimitive.js index 3efbaac2bd55..0837060bdc98 100644 --- a/Source/Scene/GroundPrimitive.js +++ b/Source/Scene/GroundPrimitive.js @@ -659,12 +659,6 @@ define([ return; } - //>>includeStart('debug', pragmas.debug); - if (this.classificationType !== ClassificationType.TERRAIN && !(this.appearance instanceof PerInstanceColorAppearance)) { - throw new DeveloperError('GroundPrimitives with Materials can only classify ClassificationType.TERRAIN at this time.'); - } - //>>includeEnd('debug'); - var that = this; var primitiveOptions = this._classificationPrimitiveOptions; @@ -712,7 +706,7 @@ define([ this._minHeight = this._minTerrainHeight * exaggeration; this._maxHeight = this._maxTerrainHeight * exaggeration; - var useFragmentCulling = GroundPrimitive._supportsMaterials(frameState.context) && this.classificationType === ClassificationType.TERRAIN; + var useFragmentCulling = GroundPrimitive._supportsMaterials(frameState.context); this._useFragmentCulling = useFragmentCulling; if (useFragmentCulling) { diff --git a/Specs/DataSources/GeometryVisualizerSpec.js b/Specs/DataSources/GeometryVisualizerSpec.js index f0fd0c5e426c..70692ad75c32 100644 --- a/Specs/DataSources/GeometryVisualizerSpec.js +++ b/Specs/DataSources/GeometryVisualizerSpec.js @@ -911,72 +911,6 @@ defineSuite([ }); }); - it('batches ground entities by identical color if ClassificationType is not TERRAIN', function() { - var entities = new EntityCollection(); - var visualizer = new GeometryVisualizer(scene, entities, scene.primitives, scene.groundPrimitives); - - var blueColor = Color.BLUE.withAlpha(0.5); - entities.add({ - position : new Cartesian3(1, 2, 3), - ellipse : { - semiMajorAxis : 2, - semiMinorAxis : 1, - material : blueColor, - classificationType : ClassificationType.BOTH - } - }); - - return pollToPromise(function() { - scene.initializeFrame(); - var isUpdated = visualizer.update(time); - scene.render(time); - return isUpdated; - }).then(function() { - expect(scene.groundPrimitives.length).toEqual(1); - - entities.add({ - position : new Cartesian3(12, 34, 45), - ellipse : { - semiMajorAxis : 2, - semiMinorAxis : 1, - material : blueColor, - classificationType : ClassificationType.BOTH - } - }); - - return pollToPromise(function() { - scene.initializeFrame(); - var isUpdated = visualizer.update(time); - scene.render(time); - return isUpdated; - }); - }).then(function() { - expect(scene.groundPrimitives.length).toEqual(1); - - entities.add({ - position : new Cartesian3(123, 456, 789), - ellipse : { - semiMajorAxis : 2, - semiMinorAxis : 1, - material : Color.BLUE.withAlpha(0.6), - classificationType : ClassificationType.BOTH - } - }); - - return pollToPromise(function() { - scene.initializeFrame(); - var isUpdated = visualizer.update(time); - scene.render(time); - return isUpdated; - }); - }).then(function() { - expect(scene.groundPrimitives.length).toEqual(2); - - entities.removeAll(); - visualizer.destroy(); - }); - }); - it('batches ground entities classifying terrain by material if ground entity materials is supported', function() { if (!GroundPrimitive.isSupported(scene) || !GroundPrimitive.supportsMaterials(scene)) { return; diff --git a/Specs/DataSources/StaticGroundGeometryPerMaterialBatchSpec.js b/Specs/DataSources/StaticGroundGeometryPerMaterialBatchSpec.js index e90c7393f5b9..4562e01a394e 100644 --- a/Specs/DataSources/StaticGroundGeometryPerMaterialBatchSpec.js +++ b/Specs/DataSources/StaticGroundGeometryPerMaterialBatchSpec.js @@ -20,6 +20,7 @@ defineSuite([ 'DataSources/PolylineGeometryUpdater', 'DataSources/PolylineGraphics', 'DataSources/TimeIntervalCollectionProperty', + 'Scene/ClassificationType', 'Scene/GroundPrimitive', 'Scene/MaterialAppearance', 'Scene/PolylineColorAppearance', @@ -48,6 +49,7 @@ defineSuite([ PolylineGeometryUpdater, PolylineGraphics, TimeIntervalCollectionProperty, + ClassificationType, GroundPrimitive, MaterialAppearance, PolylineColorAppearance, @@ -80,7 +82,7 @@ defineSuite([ return; } - var batch = new StaticGroundGeometryPerMaterialBatch(scene.primitives, MaterialAppearance); + var batch = new StaticGroundGeometryPerMaterialBatch(scene.primitives, ClassificationType.BOTH, MaterialAppearance); var ellipse = new EllipseGraphics(); ellipse.semiMajorAxis = new ConstantProperty(2); @@ -151,7 +153,7 @@ defineSuite([ } }); - var batch = new StaticGroundGeometryPerMaterialBatch(scene.primitives, MaterialAppearance); + var batch = new StaticGroundGeometryPerMaterialBatch(scene.primitives, ClassificationType.BOTH, MaterialAppearance); var updater = new EllipseGeometryUpdater(entity, scene); batch.add(validTime, updater); @@ -184,7 +186,7 @@ defineSuite([ return; } - var batch = new StaticGroundGeometryPerMaterialBatch(scene.primitives, MaterialAppearance); + var batch = new StaticGroundGeometryPerMaterialBatch(scene.primitives, ClassificationType.BOTH, MaterialAppearance); function buildEntity(x, y, z) { var material = new GridMaterialProperty({ @@ -258,7 +260,7 @@ defineSuite([ return; } - var batch = new StaticGroundGeometryPerMaterialBatch(scene.primitives, MaterialAppearance); + var batch = new StaticGroundGeometryPerMaterialBatch(scene.primitives, ClassificationType.BOTH, MaterialAppearance); var ellipse = new EllipseGraphics(); ellipse.semiMajorAxis = new ConstantProperty(2); @@ -303,7 +305,7 @@ defineSuite([ return; } - var batch = new StaticGroundGeometryPerMaterialBatch(scene.primitives, MaterialAppearance); + var batch = new StaticGroundGeometryPerMaterialBatch(scene.primitives, ClassificationType.BOTH, MaterialAppearance); var entity = new Entity({ position : new Cartesian3(1234, 5678, 9101112), ellipse : { @@ -349,7 +351,7 @@ defineSuite([ return; } - var batch = new StaticGroundGeometryPerMaterialBatch(scene.primitives, MaterialAppearance); + var batch = new StaticGroundGeometryPerMaterialBatch(scene.primitives, ClassificationType.BOTH, MaterialAppearance); function buildEntity(x, y, z) { var material = new GridMaterialProperty({ From 6a50bbc423f44cd8b979992a95c0907d3adb3010 Mon Sep 17 00:00:00 2001 From: Sean Lilley Date: Thu, 20 Dec 2018 12:08:57 -0500 Subject: [PATCH 04/12] Update Classification Types demo --- .../gallery/Classification Types.html | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/Apps/Sandcastle/gallery/Classification Types.html b/Apps/Sandcastle/gallery/Classification Types.html index f818b0c10787..c1d6c8d3d4b4 100644 --- a/Apps/Sandcastle/gallery/Classification Types.html +++ b/Apps/Sandcastle/gallery/Classification Types.html @@ -48,7 +48,7 @@ } }); -var options = [{ +var classificationOptions = [{ text : 'Classify Both', onselect : function() { entity.polygon.classificationType = Cesium.ClassificationType.BOTH; @@ -64,7 +64,21 @@ entity.polygon.classificationType = Cesium.ClassificationType.CESIUM_3D_TILE; } }]; -Sandcastle.addToolbarMenu(options); + +var materialOptions = [{ + text : 'Red Material', + onselect : function() { + entity.polygon.material = Cesium.Color.RED.withAlpha(0.5); + } +}, { + text : 'Textured Material', + onselect : function() { + entity.polygon.material = '../images/Cesium_Logo_Color.jpg'; + } +}]; + +Sandcastle.addToolbarMenu(classificationOptions); +Sandcastle.addToolbarMenu(materialOptions); //Sandcastle_End Sandcastle.finishedLoading(); } From eeea2bef896fdb79524ae3f6e92d37dd400a3bd2 Mon Sep 17 00:00:00 2001 From: Sean Lilley Date: Thu, 20 Dec 2018 12:12:14 -0500 Subject: [PATCH 05/12] Change classification defaults to BOTH everywhere --- Source/DataSources/GeometryUpdater.js | 2 +- Source/Scene/GroundPrimitive.js | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Source/DataSources/GeometryUpdater.js b/Source/DataSources/GeometryUpdater.js index 6783a2c650cf..d33253d5d28c 100644 --- a/Source/DataSources/GeometryUpdater.js +++ b/Source/DataSources/GeometryUpdater.js @@ -43,7 +43,7 @@ define([ var defaultOutlineColor = new ConstantProperty(Color.BLACK); var defaultShadows = new ConstantProperty(ShadowMode.DISABLED); var defaultDistanceDisplayCondition = new ConstantProperty(new DistanceDisplayCondition()); - var defaultClassificationType = new ConstantProperty(ClassificationType.TERRAIN); + var defaultClassificationType = new ConstantProperty(ClassificationType.BOTH); /** * An abstract class for updating geometry entites. diff --git a/Source/Scene/GroundPrimitive.js b/Source/Scene/GroundPrimitive.js index 0837060bdc98..09e94b02845a 100644 --- a/Source/Scene/GroundPrimitive.js +++ b/Source/Scene/GroundPrimitive.js @@ -105,7 +105,7 @@ define([ * @param {Boolean} [options.releaseGeometryInstances=true] When true, the primitive does not keep a reference to the input geometryInstances to save memory. * @param {Boolean} [options.allowPicking=true] When true, each geometry instance will only be pickable with {@link Scene#pick}. When false, GPU memory is saved. * @param {Boolean} [options.asynchronous=true] Determines if the primitive will be created asynchronously or block until ready. If false initializeTerrainHeights() must be called first. - * @param {ClassificationType} [options.classificationType=ClassificationType.TERRAIN] Determines whether terrain, 3D Tiles or both will be classified. + * @param {ClassificationType} [options.classificationType=ClassificationType.BOTH] Determines whether terrain, 3D Tiles or both will be classified. * @param {Boolean} [options.debugShowBoundingVolume=false] For debugging only. Determines if this primitive's commands' bounding spheres are shown. * @param {Boolean} [options.debugShowShadowVolume=false] For debugging only. Determines if the shadow volume for each geometry in the primitive is drawn. Must be true on * creation for the volumes to be created before the geometry is released or options.releaseGeometryInstance must be false. @@ -214,9 +214,9 @@ define([ * * @type {ClassificationType} * - * @default ClassificationType.TERRAIN + * @default ClassificationType.BOTH */ - this.classificationType = defaultValue(options.classificationType, ClassificationType.TERRAIN); + this.classificationType = defaultValue(options.classificationType, ClassificationType.BOTH); /** * This property is for debugging only; it is not for production use nor is it optimized. *

From 572102fe7d051a78cd9c74d847e457bc2e884570 Mon Sep 17 00:00:00 2001 From: Sean Lilley Date: Thu, 20 Dec 2018 13:15:12 -0500 Subject: [PATCH 06/12] Fix tests --- Source/DataSources/GeometryVisualizer.js | 9 +- Specs/DataSources/GeometryVisualizerSpec.js | 15 +- Specs/Scene/GroundPrimitiveSpec.js | 156 +++++++------------- 3 files changed, 69 insertions(+), 111 deletions(-) diff --git a/Source/DataSources/GeometryVisualizer.js b/Source/DataSources/GeometryVisualizer.js index 1ccbea669c13..7e1ee6c4cf29 100644 --- a/Source/DataSources/GeometryVisualizer.js +++ b/Source/DataSources/GeometryVisualizer.js @@ -175,11 +175,12 @@ define([ if (supportsMaterialsforEntitiesOnTerrain) { for (i = 0; i < numberOfClassificationTypes; ++i) { groundMaterialBatches.push(new StaticGroundGeometryPerMaterialBatch(groundPrimitives, i, MaterialAppearance)); + groundColorBatches[i] = new StaticGroundGeometryPerMaterialBatch(groundPrimitives, i, PerInstanceColorAppearance); + } + } else { + for (i = 0; i < numberOfClassificationTypes; ++i) { + groundColorBatches[i] = new StaticGroundGeometryColorBatch(groundPrimitives, i); } - } - - for (i = 0; i < numberOfClassificationTypes; ++i) { - groundColorBatches[i] = new StaticGroundGeometryColorBatch(groundPrimitives, i); } this._groundColorBatches = groundColorBatches; diff --git a/Specs/DataSources/GeometryVisualizerSpec.js b/Specs/DataSources/GeometryVisualizerSpec.js index 70692ad75c32..489d7694c243 100644 --- a/Specs/DataSources/GeometryVisualizerSpec.js +++ b/Specs/DataSources/GeometryVisualizerSpec.js @@ -911,7 +911,7 @@ defineSuite([ }); }); - it('batches ground entities classifying terrain by material if ground entity materials is supported', function() { + it('batches ground entities by material if ground entity materials is supported', function() { if (!GroundPrimitive.isSupported(scene) || !GroundPrimitive.supportsMaterials(scene)) { return; } @@ -986,13 +986,22 @@ defineSuite([ } }); + return pollToPromise(function() { + scene.initializeFrame(); + var isUpdated = visualizer.update(time); + scene.render(time); + return isUpdated; + }); + }).then(function() { + expect(scene.groundPrimitives.length).toEqual(2); + entities.add({ position : Cartesian3.fromDegrees(-12, -34), ellipse : { semiMajorAxis : 2, semiMinorAxis : 1, material : './Data/Images/White.png', - classificationType : ClassificationType.BOTH // expect to render as ClassificationType.TERRAIN + classificationType : ClassificationType.CESIUM_3D_TILE } }); @@ -1003,7 +1012,7 @@ defineSuite([ return isUpdated; }); }).then(function() { - expect(scene.groundPrimitives.length).toEqual(2); + expect(scene.groundPrimitives.length).toEqual(3); entities.removeAll(); visualizer.destroy(); diff --git a/Specs/Scene/GroundPrimitiveSpec.js b/Specs/Scene/GroundPrimitiveSpec.js index 65e592793db1..6c8e3d22c64c 100644 --- a/Specs/Scene/GroundPrimitiveSpec.js +++ b/Specs/Scene/GroundPrimitiveSpec.js @@ -374,13 +374,15 @@ defineSuite([ expect(frameState.commandList.length).toEqual(0); }); - function expectRender(color) { - expect(scene).toRender(color); + function expectRender(scene, color) { + expect(scene).toRenderAndCall(function(rgba) { + expect(arraySlice(rgba, 0, 4)).toEqual(color); + }); } - function expectRenderBlank() { + function expectRenderBlank(scene) { expect(scene).toRenderAndCall(function(rgba) { - expect(rgba).not.toEqual([0, 0, 0, 255]); + expect(arraySlice(rgba)).not.toEqual([0, 0, 0, 255]); expect(rgba[0]).toEqual(0); }); } @@ -391,33 +393,33 @@ defineSuite([ scene.primitives.add(globePrimitive); scene.primitives.add(tilesetPrimitive); - expectRenderBlank(); + expectRenderBlank(scene); scene.groundPrimitives.add(primitive); primitive.classificationType = ClassificationType.BOTH; globePrimitive.show = false; tilesetPrimitive.show = true; - expectRender(color); + expectRender(scene, color); globePrimitive.show = true; tilesetPrimitive.show = false; - expectRender(color); + expectRender(scene, color); primitive.classificationType = ClassificationType.CESIUM_3D_TILE; globePrimitive.show = false; tilesetPrimitive.show = true; - expectRender(color); + expectRender(scene, color); globePrimitive.show = true; tilesetPrimitive.show = false; - expectRenderBlank(); + expectRenderBlank(scene); primitive.classificationType = ClassificationType.TERRAIN; globePrimitive.show = false; tilesetPrimitive.show = true; - expectRenderBlank(); + expectRenderBlank(scene); globePrimitive.show = true; tilesetPrimitive.show = false; - expectRender(color); + expectRender(scene, color); globePrimitive.show = true; tilesetPrimitive.show = true; @@ -565,17 +567,41 @@ defineSuite([ largeScene.camera.setView({destination : destination}); var largeSceneGlobePrimitive = new MockPrimitive(largeSceneReusableGlobePrimitive, Pass.GLOBE); + var largeSceneTilesetPrimitive = new MockPrimitive(largeSceneReusableTilesetPrimitive, Pass.CESIUM_3D_TILE); largeScene.primitives.add(largeSceneGlobePrimitive); - expect(largeScene).toRenderAndCall(function(rgba) { - expect(arraySlice(rgba, 0, 4)).not.toEqual([0, 0, 0, 255]); - expect(rgba[0]).toEqual(0); - }); + largeScene.primitives.add(largeSceneTilesetPrimitive); + + expectRenderBlank(largeScene); largeScene.groundPrimitives.add(groundPrimitive); - expect(largeScene).toRenderAndCall(function(rgba) { - expect(arraySlice(rgba, 0, 4)).toEqual(expectedColor); - }); + + groundPrimitive.classificationType = ClassificationType.BOTH; + largeSceneGlobePrimitive.show = false; + largeSceneTilesetPrimitive.show = true; + expectRender(largeScene, expectedColor); + globePrimitive.show = true; + tilesetPrimitive.show = false; + expectRender(largeScene, expectedColor); + + groundPrimitive.classificationType = ClassificationType.CESIUM_3D_TILE; + largeSceneGlobePrimitive.show = false; + largeSceneTilesetPrimitive.show = true; + expectRender(largeScene, expectedColor); + globePrimitive.show = true; + largeSceneTilesetPrimitive.show = false; + expectRenderBlank(largeScene); + + groundPrimitive.classificationType = ClassificationType.TERRAIN; + largeSceneGlobePrimitive.show = false; + largeSceneTilesetPrimitive.show = true; + expectRenderBlank(largeScene); + largeSceneGlobePrimitive.show = true; + largeSceneTilesetPrimitive.show = false; + expectRender(largeScene, expectedColor); + + largeSceneGlobePrimitive.show = true; + largeSceneTilesetPrimitive.show = true; } it('renders batched instances', function() { @@ -613,7 +639,7 @@ defineSuite([ verifyLargerScene(batchedPrimitive, [0, 255, 255, 255], rectangle); }); - it('renders small GeometryInstances with texture classifying terrain', function() { + it('renders small GeometryInstances with texture', function() { if (!GroundPrimitive.isSupported(scene) || !GroundPrimitive.supportsMaterials(scene)) { return; } @@ -638,14 +664,13 @@ defineSuite([ flat : true, material : whiteImageMaterial }), - asynchronous : false, - classificationType : ClassificationType.TERRAIN + asynchronous : false }); verifyLargerScene(smallRectanglePrimitive, [255, 255, 255, 255], smallRectangle); }); - it('renders large GeometryInstances with texture classifying terrain', function() { + it('renders large GeometryInstances with texture', function() { if (!GroundPrimitive.isSupported(scene) || !GroundPrimitive.supportsMaterials(scene)) { return; } @@ -670,14 +695,13 @@ defineSuite([ flat : true, material : whiteImageMaterial }), - asynchronous : false, - classificationType : ClassificationType.TERRAIN + asynchronous : false }); verifyLargerScene(largeRectanglePrimitive, [255, 255, 255, 255], largeRectangle); }); - it('renders GeometryInstances with texture classifying terrain across the IDL', function() { + it('renders GeometryInstances with texture across the IDL', function() { if (!GroundPrimitive.isSupported(scene) || !GroundPrimitive.supportsMaterials(scene)) { return; } @@ -699,46 +723,11 @@ defineSuite([ flat : true, material : whiteImageMaterial }), - asynchronous : false, - classificationType : ClassificationType.TERRAIN + asynchronous : false }); verifyLargerScene(largeRectanglePrimitive, [255, 255, 255, 255], largeRectangle); }); - - it('update throws with texture and ClassificationType that is not TERRAIN', function() { - if (!GroundPrimitive.isSupported(scene) || !GroundPrimitive.supportsMaterials(scene)) { - return; - } - - var whiteImageMaterial = Material.fromType(Material.DiffuseMapType); - whiteImageMaterial.uniforms.image = './Data/Images/White.png'; - - var radians = CesiumMath.toRadians(0.1); - var west = rectangle.west; - var south = rectangle.south; - var smallRectangle = new Rectangle(west, south, west + radians, south + radians); - var smallRectanglePrimitive = new GroundPrimitive({ - geometryInstances : new GeometryInstance({ - geometry : new RectangleGeometry({ - ellipsoid : ellipsoid, - rectangle : smallRectangle - }), - id : 'smallRectangle' - }), - appearance : new EllipsoidSurfaceAppearance({ - aboveGround : false, - flat : true, - material : whiteImageMaterial - }), - asynchronous : false, - classificationType : ClassificationType.BOTH - }); - - expect(function() { - verifyLargerScene(smallRectanglePrimitive, [255, 255, 255, 255], smallRectangle); - }).toThrowDeveloperError(); - }); }); it('renders with invert classification and an opaque color', function() { @@ -753,8 +742,7 @@ defineSuite([ primitive = new GroundPrimitive({ geometryInstances : rectangleInstance, - asynchronous : false, - classificationType : ClassificationType.BOTH + asynchronous : false }); scene.camera.setView({ destination : rectangle }); @@ -793,8 +781,7 @@ defineSuite([ primitive = new GroundPrimitive({ geometryInstances : rectangleInstance, - asynchronous : false, - classificationType : ClassificationType.BOTH + asynchronous : false }); scene.camera.setView({ destination : rectangle }); @@ -1213,45 +1200,6 @@ defineSuite([ }).toThrowDeveloperError(); }); - it('update throws when batched instance colors are different and ClassificationType is not TERRAIN', function() { - if (!GroundPrimitive.isSupported(scene) || !GroundPrimitive.supportsMaterials(scene)) { - return; - } - - var rectColorAttribute = ColorGeometryInstanceAttribute.fromColor(new Color(0.0, 1.0, 1.0, 1.0)); - var rectangleInstance1 = new GeometryInstance({ - geometry : new RectangleGeometry({ - ellipsoid : ellipsoid, - rectangle : new Rectangle(rectangle.west, rectangle.south, rectangle.east, (rectangle.north + rectangle.south) * 0.5) - }), - id : 'rectangle1', - attributes : { - color : rectColorAttribute - } - }); - rectColorAttribute = ColorGeometryInstanceAttribute.fromColor(new Color(1.0, 1.0, 0.0, 1.0)); - var rectangleInstance2 = new GeometryInstance({ - geometry : new RectangleGeometry({ - ellipsoid : ellipsoid, - rectangle : new Rectangle(rectangle.west, (rectangle.north + rectangle.south) * 0.5, rectangle.east, rectangle.north) - }), - id : 'rectangle2', - attributes : { - color : rectColorAttribute - } - }); - - primitive = new GroundPrimitive({ - geometryInstances : [rectangleInstance1, rectangleInstance2], - asynchronous : false, - classificationType : ClassificationType.BOTH - }); - - expect(function() { - verifyGroundPrimitiveRender(primitive, rectColorAttribute.value); - }).toThrowDeveloperError(); - }); - it('update throws when one batched instance color is undefined', function() { if (!GroundPrimitive.isSupported(scene)) { return; From adf2881cf4b1ad66d44b41ed22d408a07785eff9 Mon Sep 17 00:00:00 2001 From: Sean Lilley Date: Thu, 20 Dec 2018 13:36:33 -0500 Subject: [PATCH 07/12] Optimization to not update depth or render CESUM_3D_TILE classification if there are no 3D Tiles commands --- Source/Scene/GlobeDepth.js | 88 ++++++++++++++++++--------------- Source/Scene/Scene.js | 22 +++++---- Specs/Scene/MultifrustumSpec.js | 2 +- 3 files changed, 60 insertions(+), 52 deletions(-) diff --git a/Source/Scene/GlobeDepth.js b/Source/Scene/GlobeDepth.js index 188e07450832..bcd9857d91b9 100644 --- a/Source/Scene/GlobeDepth.js +++ b/Source/Scene/GlobeDepth.js @@ -64,6 +64,8 @@ define([ this._tempCopyDepthCommand = undefined; this._updateDepthCommand = undefined; + this._requiresUpdateDepthResources = false; + this._viewport = new BoundingRectangle(); this._rs = undefined; this._rsUpdate = undefined; @@ -73,7 +75,6 @@ define([ this._useLogDepth = undefined; this._useHdr = undefined; - this._clearGlobeDepth = false; this._debugGlobeDepthViewportCommand = undefined; } @@ -127,7 +128,34 @@ define([ globeDepth._updateDepthFramebuffer = globeDepth._updateDepthFramebuffer && !globeDepth._updateDepthFramebuffer.isDestroyed() && globeDepth._updateDepthFramebuffer.destroy(); } - function createTextures(globeDepth, context, width, height, hdr, clearGlobeDepth) { + function createUpdateDepthResources(globeDepth, context, width, height) { + globeDepth._tempGlobeDepthTexture = new Texture({ + context : context, + width : width, + height : height, + pixelFormat : PixelFormat.RGBA, + pixelDatatype : PixelDatatype.UNSIGNED_BYTE, + sampler : new Sampler({ + wrapS : TextureWrap.CLAMP_TO_EDGE, + wrapT : TextureWrap.CLAMP_TO_EDGE, + minificationFilter : TextureMinificationFilter.NEAREST, + magnificationFilter : TextureMagnificationFilter.NEAREST + }) + }); + globeDepth._tempCopyDepthFramebuffer = new Framebuffer({ + context : context, + colorTextures : [globeDepth._tempGlobeDepthTexture], + destroyAttachments : false + }); + globeDepth._updateDepthFramebuffer = new Framebuffer({ + context : context, + colorTextures : [globeDepth._globeDepthTexture], + depthStencilTexture : globeDepth._depthStencilTexture, + destroyAttachments : false + }); + } + + function createTextures(globeDepth, context, width, height, hdr) { var pixelDatatype = hdr ? (context.halfFloatingPointTexture ? PixelDatatype.HALF_FLOAT : PixelDatatype.FLOAT) : PixelDatatype.UNSIGNED_BYTE; globeDepth._colorTexture = new Texture({ context : context, @@ -164,25 +192,9 @@ define([ magnificationFilter : TextureMagnificationFilter.NEAREST }) }); - - if (clearGlobeDepth) { - globeDepth._tempGlobeDepthTexture = new Texture({ - context : context, - width : width, - height : height, - pixelFormat : PixelFormat.RGBA, - pixelDatatype : PixelDatatype.UNSIGNED_BYTE, - sampler : new Sampler({ - wrapS : TextureWrap.CLAMP_TO_EDGE, - wrapT : TextureWrap.CLAMP_TO_EDGE, - minificationFilter : TextureMinificationFilter.NEAREST, - magnificationFilter : TextureMagnificationFilter.NEAREST - }) - }); - } } - function createFramebuffers(globeDepth, context, clearGlobeDepth) { + function createFramebuffers(globeDepth, context) { globeDepth.framebuffer = new Framebuffer({ context : context, colorTextures : [globeDepth._colorTexture], @@ -195,31 +207,19 @@ define([ colorTextures : [globeDepth._globeDepthTexture], destroyAttachments : false }); - - if (clearGlobeDepth) { - globeDepth._tempCopyDepthFramebuffer = new Framebuffer({ - context : context, - colorTextures : [globeDepth._tempGlobeDepthTexture], - destroyAttachments : false - }); - globeDepth._updateDepthFramebuffer = new Framebuffer({ - context : context, - colorTextures : [globeDepth._globeDepthTexture], - depthStencilTexture : globeDepth._depthStencilTexture, - destroyAttachments : false - }); - } } - function updateFramebuffers(globeDepth, context, width, height, hdr, clearGlobeDepth) { + function updateFramebuffers(globeDepth, context, width, height, hdr) { var colorTexture = globeDepth._colorTexture; var textureChanged = !defined(colorTexture) || colorTexture.width !== width || colorTexture.height !== height || hdr !== globeDepth._useHdr; - var clearGlobeDepthChanged = clearGlobeDepth !== globeDepth._clearGlobeDepth; - if (!defined(globeDepth.framebuffer) || textureChanged || clearGlobeDepthChanged) { + if (!defined(globeDepth.framebuffer) || textureChanged) { destroyTextures(globeDepth); destroyFramebuffers(globeDepth); - createTextures(globeDepth, context, width, height, hdr, clearGlobeDepth); - createFramebuffers(globeDepth, context, clearGlobeDepth); + createTextures(globeDepth, context, width, height, hdr); + createFramebuffers(globeDepth, context); + if (globeDepth._requiresUpdateDepthResources) { + createUpdateDepthResources(globeDepth, context, width, height); + } } } @@ -334,16 +334,15 @@ define([ executeDebugGlobeDepth(this, context, passState, useLogDepth); }; - GlobeDepth.prototype.update = function(context, passState, viewport, hdr, clearGlobeDepth) { + GlobeDepth.prototype.update = function(context, passState, viewport, hdr) { var width = viewport.width; var height = viewport.height; - updateFramebuffers(this, context, width, height, hdr, clearGlobeDepth); + updateFramebuffers(this, context, width, height, hdr); updateCopyCommands(this, context, width, height, passState); context.uniformState.globeDepthTexture = undefined; this._useHdr = hdr; - this._clearGlobeDepth = clearGlobeDepth; }; GlobeDepth.prototype.executeCopyDepth = function(context, passState) { @@ -358,7 +357,14 @@ define([ // First copy the depth to a temporary globe depth texture, then update the // main globe depth texture where the stencil bit for 3D Tiles is set. // This preserves the original globe depth except where 3D Tiles is rendered. + // The additional texture and framebuffer resources are created on demand. + this._requiresUpdateDepthResources = true; if (defined(this._tempCopyDepthCommand) && defined(this._updateDepthCommand)) { + if (!defined(this._updateDepthFramebuffer)) { + var width = this._globeDepthTexture.width; + var height = this._globeDepthTexture.height; + createUpdateDepthResources(this, context, width, height); + } this._tempCopyDepthCommand.execute(context, passState); this._updateDepthCommand.execute(context, passState); } diff --git a/Source/Scene/Scene.js b/Source/Scene/Scene.js index 95166c3bbf12..bb826571254a 100644 --- a/Source/Scene/Scene.js +++ b/Source/Scene/Scene.js @@ -2243,16 +2243,18 @@ define([ executeCommand(commands[j], scene, context, passState); } - if (defined(globeDepth) && environmentState.useGlobeDepthFramebuffer) { - globeDepth.executeUpdateDepth(context, passState, clearGlobeDepth); - } + if (length > 0) { + if (defined(globeDepth) && environmentState.useGlobeDepthFramebuffer) { + globeDepth.executeUpdateDepth(context, passState, clearGlobeDepth); + } - // Draw classifications. Modifies 3D Tiles color. - us.updatePass(Pass.CESIUM_3D_TILE_CLASSIFICATION); - commands = frustumCommands.commands[Pass.CESIUM_3D_TILE_CLASSIFICATION]; - length = frustumCommands.indices[Pass.CESIUM_3D_TILE_CLASSIFICATION]; - for (j = 0; j < length; ++j) { - executeCommand(commands[j], scene, context, passState); + // Draw classifications. Modifies 3D Tiles color. + us.updatePass(Pass.CESIUM_3D_TILE_CLASSIFICATION); + commands = frustumCommands.commands[Pass.CESIUM_3D_TILE_CLASSIFICATION]; + length = frustumCommands.indices[Pass.CESIUM_3D_TILE_CLASSIFICATION]; + for (j = 0; j < length; ++j) { + executeCommand(commands[j], scene, context, passState); + } } } else { // When the invert classification color is opaque: @@ -2934,7 +2936,7 @@ define([ // Globe depth is copied for the pick pass to support picking batched geometries in GroundPrimitives. var useGlobeDepthFramebuffer = environmentState.useGlobeDepthFramebuffer = defined(view.globeDepth); if (useGlobeDepthFramebuffer) { - view.globeDepth.update(context, passState, view.viewport, scene._hdr, environmentState.clearGlobeDepth); + view.globeDepth.update(context, passState, view.viewport, scene._hdr); view.globeDepth.clear(context, passState, clearColor); } diff --git a/Specs/Scene/MultifrustumSpec.js b/Specs/Scene/MultifrustumSpec.js index 692536eab401..8a89b7a66d99 100644 --- a/Specs/Scene/MultifrustumSpec.js +++ b/Specs/Scene/MultifrustumSpec.js @@ -218,7 +218,7 @@ defineSuite([ var found = false; var sources = billboardCall.object.shaderProgram.fragmentShaderSource.sources; for (var j = 0; j < sources.length; ++j) { - if (sources[i].indexOf('czm_Debug_main') !== -1) { + if (sources[j].indexOf('czm_Debug_main') !== -1) { found = true; break; } From 42cc67c4ae6584e0973f8cbef4ab9b4d9df1b732 Mon Sep 17 00:00:00 2001 From: Sean Lilley Date: Thu, 20 Dec 2018 15:06:39 -0500 Subject: [PATCH 08/12] Doc updates --- Source/DataSources/Entity.js | 2 +- Source/DataSources/GroundGeometryUpdater.js | 70 ++++++++++----------- Source/Scene/ClassificationPrimitive.js | 3 +- Source/Scene/GroundPrimitive.js | 12 ++-- 4 files changed, 42 insertions(+), 45 deletions(-) diff --git a/Source/DataSources/Entity.js b/Source/DataSources/Entity.js index b5170a14fa46..f3b8eb4411ca 100644 --- a/Source/DataSources/Entity.js +++ b/Source/DataSources/Entity.js @@ -664,7 +664,7 @@ define([ }; /** - * Checks if the given Scene supports materials besides Color on Entities draped on terrain. + * Checks if the given Scene supports materials besides Color on Entities draped on terrain or 3D Tiles. * If this feature is not supported, Entities with non-color materials but no `height` will * instead be rendered as if height is 0. * diff --git a/Source/DataSources/GroundGeometryUpdater.js b/Source/DataSources/GroundGeometryUpdater.js index c7fd10b8fe43..97908b9f0228 100644 --- a/Source/DataSources/GroundGeometryUpdater.js +++ b/Source/DataSources/GroundGeometryUpdater.js @@ -1,39 +1,39 @@ define([ - '../Core/ApproximateTerrainHeights', - '../Core/Cartesian3', - '../Core/Check', - '../Core/defaultValue', - '../Core/defined', - '../Core/defineProperties', - '../Core/DeveloperError', - '../Core/GeometryOffsetAttribute', - '../Core/Iso8601', - '../Core/oneTimeWarning', - '../Scene/GroundPrimitive', - '../Scene/HeightReference', - './CallbackProperty', - './ConstantProperty', - './GeometryUpdater', - './Property', - './TerrainOffsetProperty' -], function( - ApproximateTerrainHeights, - Cartesian3, - Check, - defaultValue, - defined, - defineProperties, - DeveloperError, - GeometryOffsetAttribute, - Iso8601, - oneTimeWarning, - GroundPrimitive, - HeightReference, - CallbackProperty, - ConstantProperty, - GeometryUpdater, - Property, - TerrainOffsetProperty) { + '../Core/ApproximateTerrainHeights', + '../Core/Cartesian3', + '../Core/Check', + '../Core/defaultValue', + '../Core/defined', + '../Core/defineProperties', + '../Core/DeveloperError', + '../Core/GeometryOffsetAttribute', + '../Core/Iso8601', + '../Core/oneTimeWarning', + '../Scene/GroundPrimitive', + '../Scene/HeightReference', + './CallbackProperty', + './ConstantProperty', + './GeometryUpdater', + './Property', + './TerrainOffsetProperty' + ], function( + ApproximateTerrainHeights, + Cartesian3, + Check, + defaultValue, + defined, + defineProperties, + DeveloperError, + GeometryOffsetAttribute, + Iso8601, + oneTimeWarning, + GroundPrimitive, + HeightReference, + CallbackProperty, + ConstantProperty, + GeometryUpdater, + Property, + TerrainOffsetProperty) { 'use strict'; var defaultZIndex = new ConstantProperty(0); diff --git a/Source/Scene/ClassificationPrimitive.js b/Source/Scene/ClassificationPrimitive.js index d2c1ca987238..d0dcc4695b7a 100644 --- a/Source/Scene/ClassificationPrimitive.js +++ b/Source/Scene/ClassificationPrimitive.js @@ -67,8 +67,7 @@ define([ * and match most of them and add a new geometry or appearance independently of each other. * Only {@link PerInstanceColorAppearance} with the same color across all instances is supported at this time when using * ClassificationPrimitive directly. - * For full {@link Appearance} support when classifying terrain use {@link GroundPrimitive} instead. - * + * For full {@link Appearance} support when classifying terrain or 3D Tiles use {@link GroundPrimitive} instead. *

*

* For correct rendering, this feature requires the EXT_frag_depth WebGL extension. For hardware that do not support this extension, there diff --git a/Source/Scene/GroundPrimitive.js b/Source/Scene/GroundPrimitive.js index 09e94b02845a..dbeddae47721 100644 --- a/Source/Scene/GroundPrimitive.js +++ b/Source/Scene/GroundPrimitive.js @@ -67,22 +67,20 @@ define([ }; /** - * A ground primitive represents geometry draped over the terrain in the {@link Scene}. + * A ground primitive represents geometry draped over terrain or 3D Tiles in the {@link Scene}. *

* A primitive combines geometry instances with an {@link Appearance} that describes the full shading, including * {@link Material} and {@link RenderState}. Roughly, the geometry instance defines the structure and placement, * and the appearance defines the visual characteristics. Decoupling geometry and appearance allows us to mix * and match most of them and add a new geometry or appearance independently of each other. - * - * Only {@link PerInstanceColorAppearance} with the same color across all instances is supported at this time when - * classifying {@link ClassificationType}.CESIUM_3D_TILE and {@link ClassificationType}.BOTH. - * + *

+ *

* Support for the WEBGL_depth_texture extension is required to use GeometryInstances with different PerInstanceColors * or materials besides PerInstanceColorAppearance. - * + *

+ *

* Textured GroundPrimitives were designed for notional patterns and are not meant for precisely mapping * textures to terrain - for that use case, use {@link SingleTileImageryProvider}. - * *

*

* For correct rendering, this feature requires the EXT_frag_depth WebGL extension. For hardware that do not support this extension, there From c17cf47aacca88228c8554662e5f6b95b2391bf7 Mon Sep 17 00:00:00 2001 From: Sean Lilley Date: Thu, 20 Dec 2018 15:16:02 -0500 Subject: [PATCH 09/12] Update CHANGES.md --- CHANGES.md | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 30522b7c7b57..5d2532c5c69b 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,11 +1,19 @@ Change Log ========== -### 1.45 - 2019-02-01 +### 1.54 - 2019-02-01 + +##### Additions :tada: + +* Added support for textured ground entities (entities with unspecified `height`) and `GroundPrimitives` on 3D Tiles. ##### Fixes :wrench: -* Fixed an issue where classification primitives with the `CESIUM_3D_TILE` classification type would render on terrain. [#6568](https://github.com/AnalyticalGraphicsInc/cesium/issues/6568) -* Fixed an issue where 3D Tiles would show through the globe. [#6867](https://github.com/AnalyticalGraphicsInc/cesium/issues/6867) +* Fixed an issue where classification primitives with the `CESIUM_3D_TILE` classification type would render on terrain. +* Fixed an issue where 3D Tiles would show through the globe. + +##### Breaking Changes :mega: +* Billboards with `HeightReference.CLAMP_TO_GROUND` are now clamped to both terrain and 3D Tiles. +* The default `classificationType` for `GroundPrimitive`, `CorridorGraphics`, `EllipseGraphics`, `PolygonGraphics` and `RectangleGraphics` is now `ClassificationType.BOTH`. ### 1.53 - 2019-01-02 From cea11caeac072398a828cea51c893d8fc141248c Mon Sep 17 00:00:00 2001 From: Sean Lilley Date: Fri, 21 Dec 2018 13:09:53 -0500 Subject: [PATCH 10/12] Fix for first frame after depthTestAgainstTerrain is disabled --- Source/Scene/GlobeDepth.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Source/Scene/GlobeDepth.js b/Source/Scene/GlobeDepth.js index bcd9857d91b9..b79f4a644c68 100644 --- a/Source/Scene/GlobeDepth.js +++ b/Source/Scene/GlobeDepth.js @@ -359,11 +359,12 @@ define([ // This preserves the original globe depth except where 3D Tiles is rendered. // The additional texture and framebuffer resources are created on demand. this._requiresUpdateDepthResources = true; - if (defined(this._tempCopyDepthCommand) && defined(this._updateDepthCommand)) { + if (defined(this._updateDepthCommand)) { if (!defined(this._updateDepthFramebuffer)) { var width = this._globeDepthTexture.width; var height = this._globeDepthTexture.height; createUpdateDepthResources(this, context, width, height); + updateCopyCommands(this, context, width, height, passState); } this._tempCopyDepthCommand.execute(context, passState); this._updateDepthCommand.execute(context, passState); From 845377934c729fb0fde369cb4df15d01a9901994 Mon Sep 17 00:00:00 2001 From: Sean Lilley Date: Wed, 2 Jan 2019 09:39:51 -0500 Subject: [PATCH 11/12] Move depth update command after invert clsasification --- Source/Scene/Scene.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Source/Scene/Scene.js b/Source/Scene/Scene.js index bb826571254a..241ecdbb326c 100644 --- a/Source/Scene/Scene.js +++ b/Source/Scene/Scene.js @@ -2302,10 +2302,6 @@ define([ executeCommand(commands[j], scene, context, passState); } - if (defined(globeDepth) && environmentState.useGlobeDepthFramebuffer) { - globeDepth.executeUpdateDepth(context, passState, clearGlobeDepth); - } - // Set stencil us.updatePass(Pass.CESIUM_3D_TILE_CLASSIFICATION_IGNORE_SHOW); commands = frustumCommands.commands[Pass.CESIUM_3D_TILE_CLASSIFICATION_IGNORE_SHOW]; @@ -2328,6 +2324,10 @@ define([ clearClassificationStencil.execute(context, passState); } + if (defined(globeDepth) && environmentState.useGlobeDepthFramebuffer) { + globeDepth.executeUpdateDepth(context, passState, clearGlobeDepth); + } + // Draw style over classification. us.updatePass(Pass.CESIUM_3D_TILE_CLASSIFICATION); commands = frustumCommands.commands[Pass.CESIUM_3D_TILE_CLASSIFICATION]; From 9e7f30a47516e1a7f565f2367850e68b489e549e Mon Sep 17 00:00:00 2001 From: Sean Lilley Date: Wed, 2 Jan 2019 10:54:08 -0500 Subject: [PATCH 12/12] Move breaking changes section to the top --- CHANGES.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 5d2532c5c69b..516df500175b 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -3,6 +3,10 @@ Change Log ### 1.54 - 2019-02-01 +##### Breaking Changes :mega: +* Billboards with `HeightReference.CLAMP_TO_GROUND` are now clamped to both terrain and 3D Tiles. +* The default `classificationType` for `GroundPrimitive`, `CorridorGraphics`, `EllipseGraphics`, `PolygonGraphics` and `RectangleGraphics` is now `ClassificationType.BOTH`. + ##### Additions :tada: * Added support for textured ground entities (entities with unspecified `height`) and `GroundPrimitives` on 3D Tiles. @@ -11,10 +15,6 @@ Change Log * Fixed an issue where classification primitives with the `CESIUM_3D_TILE` classification type would render on terrain. * Fixed an issue where 3D Tiles would show through the globe. -##### Breaking Changes :mega: -* Billboards with `HeightReference.CLAMP_TO_GROUND` are now clamped to both terrain and 3D Tiles. -* The default `classificationType` for `GroundPrimitive`, `CorridorGraphics`, `EllipseGraphics`, `PolygonGraphics` and `RectangleGraphics` is now `ClassificationType.BOTH`. - ### 1.53 - 2019-01-02 ##### Fixes :wrench: