diff --git a/CHANGES.md b/CHANGES.md index 6b673c42ed6b..f3a98577b653 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -5,6 +5,7 @@ Change Log * Reduced the amount of CPU memory used by terrain by ~25% in Chrome. * Fixed a picking problem ([#3386](https://github.com/AnalyticalGraphicsInc/cesium/issues/3386)) that sometimes prevented objects being selected. +* Added `Scene.useDepthPicking` to enable or disable picking using the depth buffer. [#3390](https://github.com/AnalyticalGraphicsInc/cesium/pull/3390) ### 1.17 - 2016-01-04 diff --git a/Source/Scene/Scene.js b/Source/Scene/Scene.js index 304a0f9cf908..d35ceec68ee7 100644 --- a/Source/Scene/Scene.js +++ b/Source/Scene/Scene.js @@ -500,6 +500,14 @@ define([ */ this.fxaa = true; + /** + * When true, enables picking using the depth buffer. + * + * @type Boolean + * @default true + */ + this.useDepthPicking = true; + /** * The time in milliseconds to wait before checking if the camera has not moved and fire the cameraMoveEnd event. * @type {Number} @@ -1555,7 +1563,7 @@ define([ commands.length = frustumCommands.indices[Pass.TRANSLUCENT]; executeTranslucentCommands(scene, executeCommand, passState, commands); - if (defined(globeDepth) && environmentState.useGlobeDepthFramebuffer) { + if (defined(globeDepth) && environmentState.useGlobeDepthFramebuffer && scene.useDepthPicking) { // PERFORMANCE_IDEA: Use MRT to avoid the extra copy. var pickDepth = getPickDepth(scene, index); pickDepth.update(context, globeDepth.framebuffer.depthStencilTexture); @@ -2013,6 +2021,10 @@ define([ * @exception {DeveloperError} 2D is not supported. An orthographic projection matrix is not invertible. */ Scene.prototype.pickPosition = function(windowPosition, result) { + if (!this.useDepthPicking) { + return undefined; + } + //>>includeStart('debug', pragmas.debug); if(!defined(windowPosition)) { throw new DeveloperError('windowPosition is undefined.'); diff --git a/Specs/Scene/SceneSpec.js b/Specs/Scene/SceneSpec.js index 865658159cdb..30f92b8e30a9 100644 --- a/Specs/Scene/SceneSpec.js +++ b/Specs/Scene/SceneSpec.js @@ -584,6 +584,40 @@ defineSuite([ expect(position).toBeDefined(); }); + it('pickPosition returns undefined when useDepthPicking is false', function() { + if (!scene.pickPositionSupported) { + return; + } + + var rectangle = Rectangle.fromDegrees(-100.0, 30.0, -90.0, 40.0); + scene.camera.setView({ + destination : rectangle + }); + + var canvas = scene.canvas; + var windowPosition = new Cartesian2(canvas.clientWidth / 2, canvas.clientHeight / 2); + + var rectanglePrimitive = createRectangle(rectangle); + rectanglePrimitive.appearance.material.uniforms.color = new Color(1.0, 0.0, 0.0, 1.0); + + var primitives = scene.primitives; + primitives.add(rectanglePrimitive); + + scene.useDepthPicking = false; + + scene.renderForSpecs(); + + var position = scene.pickPosition(windowPosition); + expect(position).not.toBeDefined(); + + scene.useDepthPicking = true; + + scene.renderForSpecs(); + + position = scene.pickPosition(windowPosition); + expect(position).toBeDefined(); + }); + it('pickPosition throws without windowPosition', function() { expect(function() { scene.pickPosition();