Skip to content

Commit

Permalink
Add scene.minimumDisableDepthTestDistance.
Browse files Browse the repository at this point in the history
  • Loading branch information
bagnell committed Mar 31, 2017
1 parent a8575f6 commit e990328
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 4 deletions.
14 changes: 11 additions & 3 deletions Source/Renderer/AutomaticUniforms.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
})
};

Expand Down
13 changes: 13 additions & 0 deletions Source/Renderer/UniformState.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ define([
this._imagerySplitPosition = 0.0;
this._pixelSizePerMeter = undefined;
this._geometricToleranceOverMeter = undefined;

this._minimumDisableDepthTestDistance = undefined;
}

defineProperties(UniformState.prototype, {
Expand Down Expand Up @@ -789,6 +791,12 @@ define([
get : function() {
return this._imagerySplitPosition;
}
},

minimumDisableDepthTestDistance : {
get : function() {
return this._minimumDisableDepthTestDistance;
}
}
});

Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 2 additions & 0 deletions Source/Scene/BillboardCollection.js
Original file line number Diff line number Diff line change
Expand Up @@ -1494,6 +1494,8 @@ define([
}
}

this._shaderDisableDepthDistance = frameState.minimumDisableDepthTestDistance !== 0.0;

if (blendOptionChanged ||
(this._shaderRotation !== this._compiledShaderRotation) ||
(this._shaderAlignedAxis !== this._compiledShaderAlignedAxis) ||
Expand Down
2 changes: 2 additions & 0 deletions Source/Scene/FrameState.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,8 @@ define([
* @default []
*/
this.frustumSplits = [];

this.minimumDisableDepthTestDistance = undefined;
}

/**
Expand Down
2 changes: 2 additions & 0 deletions Source/Scene/PointPrimitiveCollection.js
Original file line number Diff line number Diff line change
Expand Up @@ -896,6 +896,8 @@ define([
}
}

this._shaderDisableDepthDistance = frameState.minimumDisableDepthTestDistance !== 0.0;

if (blendOptionChanged ||
(this._shaderScaleByDistance && !this._compiledShaderScaleByDistance) ||
(this._shaderTranslucencyByDistance && !this._compiledShaderTranslucencyByDistance) ||
Expand Down
18 changes: 17 additions & 1 deletion Source/Scene/Scene.js
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,8 @@ define([
this._cameraStartFired = false;
this._cameraMovedTime = undefined;

this._minimumDisableDepthTestDistance = 0.0;

/**
* Exceptions occurring in <code>render</code> are always caught in order to raise the
* <code>renderError</code> event. If this property is true, the error is rethrown
Expand Down Expand Up @@ -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;
}
}
});

Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 4 additions & 0 deletions Source/Shaders/BillboardCollectionVS.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
4 changes: 4 additions & 0 deletions Source/Shaders/PointPrimitiveCollectionVS.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit e990328

Please sign in to comment.