From e9903281f6c4cbca5e2f3434620833f9ee63c279 Mon Sep 17 00:00:00 2001 From: Dan Bagnell Date: Fri, 31 Mar 2017 14:08:53 -0400 Subject: [PATCH] Add scene.minimumDisableDepthTestDistance. --- Source/Renderer/AutomaticUniforms.js | 14 +++++++++++--- Source/Renderer/UniformState.js | 13 +++++++++++++ Source/Scene/BillboardCollection.js | 2 ++ Source/Scene/FrameState.js | 2 ++ Source/Scene/PointPrimitiveCollection.js | 2 ++ Source/Scene/Scene.js | 18 +++++++++++++++++- Source/Shaders/BillboardCollectionVS.glsl | 4 ++++ Source/Shaders/PointPrimitiveCollectionVS.glsl | 4 ++++ 8 files changed, 55 insertions(+), 4 deletions(-) diff --git a/Source/Renderer/AutomaticUniforms.js b/Source/Renderer/AutomaticUniforms.js index 5b838aa2bf66..30991a55c62c 100644 --- a/Source/Renderer/AutomaticUniforms.js +++ b/Source/Renderer/AutomaticUniforms.js @@ -1494,11 +1494,19 @@ define([ * @glslUniform */ czm_geometricToleranceOverMeter : new AutomaticUniform({ - size: 1, - datatype: WebGLConstants.FLOAT, - getValue: function(uniformState) { + size : 1, + datatype : WebGLConstants.FLOAT, + getValue : function(uniformState) { return uniformState.geometricToleranceOverMeter; } + }), + + czm_minimumDisableDepthTestDistance : new AutomaticUniform({ + size : 1, + datatype : WebGLConstants.FLOAT, + getValue : function(uniformState) { + return uniformState.minimumDisableDepthTestDistance; + } }) }; diff --git a/Source/Renderer/UniformState.js b/Source/Renderer/UniformState.js index e7c405267143..3ed71dfc124d 100644 --- a/Source/Renderer/UniformState.js +++ b/Source/Renderer/UniformState.js @@ -153,6 +153,8 @@ define([ this._imagerySplitPosition = 0.0; this._pixelSizePerMeter = undefined; this._geometricToleranceOverMeter = undefined; + + this._minimumDisableDepthTestDistance = undefined; } defineProperties(UniformState.prototype, { @@ -789,6 +791,12 @@ define([ get : function() { return this._imagerySplitPosition; } + }, + + minimumDisableDepthTestDistance : { + get : function() { + return this._minimumDisableDepthTestDistance; + } } }); @@ -963,6 +971,11 @@ define([ } this._geometricToleranceOverMeter = pixelSizePerMeter * frameState.maximumScreenSpaceError; + + this._minimumDisableDepthTestDistance = frameState.minimumDisableDepthTestDistance; + if (this._minimumDisableDepthTestDistance === Number.POSITIVE_INFINITY) { + this._minimumDisableDepthTestDistance = -1.0; + } }; function cleanViewport(uniformState) { diff --git a/Source/Scene/BillboardCollection.js b/Source/Scene/BillboardCollection.js index a4db98e6c609..6e5cca19f250 100644 --- a/Source/Scene/BillboardCollection.js +++ b/Source/Scene/BillboardCollection.js @@ -1494,6 +1494,8 @@ define([ } } + this._shaderDisableDepthDistance = frameState.minimumDisableDepthTestDistance !== 0.0; + if (blendOptionChanged || (this._shaderRotation !== this._compiledShaderRotation) || (this._shaderAlignedAxis !== this._compiledShaderAlignedAxis) || diff --git a/Source/Scene/FrameState.js b/Source/Scene/FrameState.js index 1431589182a0..328f27491351 100644 --- a/Source/Scene/FrameState.js +++ b/Source/Scene/FrameState.js @@ -249,6 +249,8 @@ define([ * @default [] */ this.frustumSplits = []; + + this.minimumDisableDepthTestDistance = undefined; } /** diff --git a/Source/Scene/PointPrimitiveCollection.js b/Source/Scene/PointPrimitiveCollection.js index 02959d5552f6..47a7db9a7484 100644 --- a/Source/Scene/PointPrimitiveCollection.js +++ b/Source/Scene/PointPrimitiveCollection.js @@ -896,6 +896,8 @@ define([ } } + this._shaderDisableDepthDistance = frameState.minimumDisableDepthTestDistance !== 0.0; + if (blendOptionChanged || (this._shaderScaleByDistance && !this._compiledShaderScaleByDistance) || (this._shaderTranslucencyByDistance && !this._compiledShaderTranslucencyByDistance) || diff --git a/Source/Scene/Scene.js b/Source/Scene/Scene.js index 3a40dd467699..20dbab2a0909 100644 --- a/Source/Scene/Scene.js +++ b/Source/Scene/Scene.js @@ -321,6 +321,8 @@ define([ this._cameraStartFired = false; this._cameraMovedTime = undefined; + this._minimumDisableDepthTestDistance = 0.0; + /** * Exceptions occurring in render are always caught in order to raise the * renderError event. If this property is true, the error is rethrown @@ -1141,10 +1143,23 @@ define([ get: function() { return this._frameState.imagerySplitPosition; }, - set: function(value) { this._frameState.imagerySplitPosition = value; } + }, + + minimumDisableDepthTestDistance : { + get : function() { + return this._minimumDisableDepthTestDistance; + }, + set : function(value) { + //>>includeStart('debug', pragmas.debug); + if (!defined(value) || value < 0.0) { + throw new DeveloperError('minimumDisableDepthTestDistance must be greater than or equal to 0.0.'); + } + //>>includeEnd('debug'); + this._minimumDisableDepthTestDistance = value; + } } }); @@ -1257,6 +1272,7 @@ define([ frameState.cullingVolume = camera.frustum.computeCullingVolume(camera.positionWC, camera.directionWC, camera.upWC); frameState.occluder = getOccluder(scene); frameState.terrainExaggeration = scene._terrainExaggeration; + frameState.minimumDisableDepthTestDistance = scene._minimumDisableDepthTestDistance; if (defined(scene.globe)) { frameState.maximumScreenSpaceError = scene.globe.maximumScreenSpaceError; } else { diff --git a/Source/Shaders/BillboardCollectionVS.glsl b/Source/Shaders/BillboardCollectionVS.glsl index 6834ca4cbc11..921540f349fd 100644 --- a/Source/Shaders/BillboardCollectionVS.glsl +++ b/Source/Shaders/BillboardCollectionVS.glsl @@ -260,6 +260,10 @@ void main() #ifdef DISABLE_DEPTH_DISTANCE float disableDepthTestDistance = distanceDisplayConditionAndDisableDepth.z; + if (disableDepthTestDistance == 0.0 && czm_minimumDisableDepthTestDistance != 0.0) { + disableDepthTestDistance = czm_minimumDisableDepthTestDistance; + } + if (disableDepthTestDistance != 0.0) { gl_Position.z = min(gl_Position.z, gl_Position.w); diff --git a/Source/Shaders/PointPrimitiveCollectionVS.glsl b/Source/Shaders/PointPrimitiveCollectionVS.glsl index 5ace5cac8fd6..11a80c98c9c1 100644 --- a/Source/Shaders/PointPrimitiveCollectionVS.glsl +++ b/Source/Shaders/PointPrimitiveCollectionVS.glsl @@ -153,6 +153,10 @@ void main() #ifdef DISABLE_DEPTH_DISTANCE float disableDepthTestDistance = distanceDisplayConditionAndDisableDepth.z; + if (disableDepthTestDistance == 0.0 && czm_minimumDisableDepthTestDistance != 0.0) { + disableDepthTestDistance = czm_minimumDisableDepthTestDistance; + } + if (disableDepthTestDistance != 0.0) { gl_Position.z = min(gl_Position.z, gl_Position.w);