Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Log depth buffer #5851

Merged
merged 82 commits into from
Apr 12, 2018
Merged
Show file tree
Hide file tree
Changes from 72 commits
Commits
Show all changes
82 commits
Select commit Hold shift + click to select a range
80f5976
added optional logarithmic depth buffer
geoscan-builder Sep 26, 2017
36264f7
fixed pickinig issue with log depth buffer
geoscan-builder Sep 27, 2017
e15adbf
removed trailing decimal point to avoid eslint warn
geoscan-builder Sep 27, 2017
bd5428f
added to CONTRIBUTORS
geoscan-builder Sep 27, 2017
ceedc32
fallback to multifrustum if no fragDepth extension
geoscan-builder Sep 27, 2017
d70db84
Update CHANGES.md
Vineg Sep 28, 2017
87f8415
Merge branch 'master' into log-depth-buffer
Vineg Sep 28, 2017
a79138d
added log depth to objects, removed option to turn it off
geoscan-builder Oct 13, 2017
7ee510c
Merge branch 'log-depth-buffer' of https://github.com/geoscan/cesium …
geoscan-builder Oct 13, 2017
7133aa5
Merge branch 'cesium-master' into log-depth-buffer
geoscan-builder Oct 13, 2017
4a79331
removed unused variable
geoscan-builder Oct 13, 2017
50c019c
fix wrong require
geoscan-builder Oct 13, 2017
043ebcc
moved extension to logDepth function
geoscan-builder Oct 13, 2017
a65596f
Merge branch 'cesium-master' into log-depth-buffer
geoscan-builder Nov 7, 2017
3d5cd2b
fixed polyline v_position
geoscan-builder Nov 10, 2017
451761c
Modified 3d tiles vertex shader.
geoscan-builder Nov 20, 2017
db0630f
fixed 3d tiles picking
geoscan-builder Dec 5, 2017
8191c36
fixed polyline depth
geoscan-builder Dec 29, 2017
2fb7ed2
Merge branch 'cesium-master' into log-depth-buffer
geoscan-builder Jan 9, 2018
665909c
fixed interpolation issue
geoscan-builder Jan 9, 2018
bcf1504
Merge branch 'cesium-master' into log-depth-buffer
geoscan-builder Jan 9, 2018
22bfd34
removed unnecessary variable
geoscan-builder Jan 9, 2018
9f7c4d8
Merge branch 'cesium-master' into log-depth-buffer
geoscan-builder Feb 9, 2018
417c3f9
fixed some artifacts
geoscan-builder Feb 9, 2018
f5ad7c6
Use uniform semantic for model-view-projection matrix.
bagnell Feb 9, 2018
23f99c2
Use decoded position attribute for log z.
bagnell Feb 9, 2018
33cfca7
Fix classification model log depth.
bagnell Feb 12, 2018
caf032a
Write globe log depth on pick.
bagnell Feb 12, 2018
8d49519
Fix issue with the BIM tileset.
bagnell Feb 13, 2018
b6db381
Fix depth for polylines in a polyline collection.
bagnell Feb 13, 2018
c94e5ad
Update moon.
bagnell Feb 13, 2018
7d716e9
Add missing log depth to appearances, point primitives and vector til…
bagnell Feb 15, 2018
567a110
Fix disable depth test distance.
bagnell Feb 15, 2018
7c46e11
Minor clean up.
bagnell Feb 16, 2018
e331d4c
Use derived commands to enable log depth and disable when using an or…
bagnell Feb 16, 2018
75bd3ba
Fix picking.
bagnell Feb 19, 2018
e62f28b
Merge remote-tracking branch 'origin/master' into log-depth-buffer
bagnell Feb 19, 2018
d681755
Fix shadow mapping and use log depth with OIT.
bagnell Feb 20, 2018
6e07e89
Fix depth plane.
bagnell Feb 20, 2018
90a089b
Re-add multi-frustum for log depth.
bagnell Feb 22, 2018
462d229
Clamp shadow volume depth to far plane only when not using log depth.
bagnell Feb 22, 2018
27447fc
Generate log depth shaders with derived commands when possible.
bagnell Feb 23, 2018
0a628db
Make log z functions for vertex and fragment shader. Change log z fun…
bagnell Feb 24, 2018
afcc7ed
Fix depth picking. Simplify frag depth write. Update gl_Position.z.
bagnell Feb 26, 2018
9cea995
Fix log depth issue with the skip LOD optimization.
bagnell Mar 2, 2018
122ca66
Fix shadows.
bagnell Mar 2, 2018
2f710de
Merge branch 'master' into log-depth-buffer
lilleyse Mar 5, 2018
bcc2dc4
Updated CHANGES.md
lilleyse Mar 5, 2018
4ee738d
Fix 2D. Update some tests.
bagnell Mar 5, 2018
0d90d98
Fix a few tests and updates from review.
bagnell Mar 6, 2018
22ecbe6
Add option to disable log depth. Fix frustum equality and frustum cha…
bagnell Mar 7, 2018
e72c849
Fix billboards not being occluded by the near plane. Fix more tests.
bagnell Mar 8, 2018
3c9c92b
Fix shadow maps without varying eye coordinate. Fix tests.
bagnell Mar 9, 2018
1440a9a
Ignore nodes when searching for model semantics. Fix tests.
bagnell Mar 9, 2018
27118ee
Fix depth picking point clouds with EDL.
bagnell Mar 9, 2018
7fdf9c9
Fix depth picking tests.
bagnell Mar 10, 2018
d94aa07
Updates from review. Fix more tests.
bagnell Mar 12, 2018
1d5adab
Fix tests broken by last commit.
bagnell Mar 12, 2018
e029f10
Fix batched classification test.
bagnell Mar 12, 2018
f14a2cf
Fix inverted classification test.
bagnell Mar 12, 2018
7c06ec8
Fix tests when log depth isn't supported.
bagnell Mar 12, 2018
1635c92
Merge branch 'master' into log-depth-buffer
bagnell Mar 12, 2018
5913ffe
Fixes after merge.
bagnell Mar 12, 2018
a648dea
Updates from review.
bagnell Mar 14, 2018
b6de470
Fix translucent overlap. Fix geometry showing through depth plane. Up…
bagnell Mar 19, 2018
1525950
Fix picking depth which had a hardcoded value for the near plane.
bagnell Mar 20, 2018
6a5a6b0
Fix issue setting enabling/disabling log depth.
bagnell Mar 20, 2018
2f53039
Merge branch 'master' into log-depth-buffer
bagnell Mar 20, 2018
fb3a2b2
Fix eslint errors.
bagnell Mar 20, 2018
530f41d
Fix polyline geometry.
bagnell Mar 26, 2018
78dcea9
Merge branch 'master' into log-depth-buffer
bagnell Apr 2, 2018
979b541
Update CHANGES.md.
bagnell Apr 2, 2018
4dd219f
Fix Draco compressed models.
bagnell Apr 5, 2018
b5f83d9
Update CHANGES.md
bagnell Apr 5, 2018
9bc6e32
Merge branch 'master' into log-depth-buffer
bagnell Apr 5, 2018
d546e45
Move derived commands to own class.
bagnell Apr 5, 2018
e17dbcc
Update multi-frustum tests.
bagnell Apr 5, 2018
6e9fc3e
Use eye coordinates instead of window coordinates in the billboard ve…
bagnell Apr 9, 2018
4cf9479
Merge branch 'master' into log-depth-buffer
bagnell Apr 9, 2018
bed9f0e
Fix NaNs returned by barycentricCoordinates.
bagnell Apr 10, 2018
3419ad5
Fix debug show globe and pick depth.
bagnell Apr 10, 2018
d7d14a5
Rename from review.
bagnell Apr 10, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
Change Log
==========

### 1.46 - 2018-05-01

##### Breaking Changes :mega:
* `Camera.distanceToBoundingSphere` now returns the signed distance to the bounding sphere. Positive values indicate that the bounding sphere is in the positive half-plane of the camera position and view direction while a negative value indicates it is in the negative half-plane.

##### Additions :tada:
* Added option `logDepthBuffer` to `Viewer`. With this option there is typically a single frustum using logarithmic depth rendered. This increases performance by issuing less draw calls to the GPU and helps to avoid artifacts on the connection of two frustums. [#5851](https://github.com/AnalyticalGraphicsInc/cesium/pull/5851)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did we also change the default near value?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Late to the party, but should this be logarithmicDepthBuffer in Scene?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

* Added `Math.log2` to compute the base 2 logarithm of a number.

### 1.44 - 2018-04-02

##### Breaking Changes :mega:
Expand Down
1 change: 1 addition & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ See [CONTRIBUTING.md](CONTRIBUTING.md) for details on how to contribute to Cesiu
* [Dave Whipps](https://github.com/dwhipps)
* [Geoscan](https://www.geoscan.aero)
* [Andrey Orlov](https://github.com/AndreyOrlov)
* [George Vinokhodov](https://github.com/Vineg)
* [The Imagineers](https://www.theimagineers.com/)
* [Heerco Grond](https://github.com/HeercoGrond)
* [Camptocamp SA](https://www.camptocamp.com/)
Expand Down
12 changes: 12 additions & 0 deletions Source/Core/Math.js
Original file line number Diff line number Diff line change
Expand Up @@ -849,6 +849,18 @@ define([
*/
CesiumMath.cbrt = defined(Math.cbrt) ? Math.cbrt : cbrt;

function log2(x) {
return Math.log(x) * Math.LOG2E;
}

/**
* Finds the base 2 logarithm of a number.
*
* @param {Number} number The number.
* @returns {Number} The result.
*/
CesiumMath.log2 = defined(Math.log2) ? Math.log2 : log2;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add to CHANGES.md.


/**
* @private
*/
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/OrthographicFrustum.js
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ define([
* @returns {Boolean} <code>true</code> if they are equal, <code>false</code> otherwise.
*/
OrthographicFrustum.prototype.equals = function(other) {
if (!defined(other)) {
if (!defined(other) || !(other instanceof OrthographicFrustum)) {
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion Source/Core/OrthographicOffCenterFrustum.js
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ define([
* @returns {Boolean} <code>true</code> if they are equal, <code>false</code> otherwise.
*/
OrthographicOffCenterFrustum.prototype.equals = function(other) {
return (defined(other) &&
return (defined(other) && other instanceof OrthographicOffCenterFrustum &&
this.right === other.right &&
this.left === other.left &&
this.top === other.top &&
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/PerspectiveFrustum.js
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ define([
* @returns {Boolean} <code>true</code> if they are equal, <code>false</code> otherwise.
*/
PerspectiveFrustum.prototype.equals = function(other) {
if (!defined(other)) {
if (!defined(other) || !(other instanceof PerspectiveFrustum)) {
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion Source/Core/PerspectiveOffCenterFrustum.js
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ define([
* @returns {Boolean} <code>true</code> if they are equal, <code>false</code> otherwise.
*/
PerspectiveOffCenterFrustum.prototype.equals = function(other) {
return (defined(other) &&
return (defined(other) && other instanceof PerspectiveOffCenterFrustum &&
this.right === other.right &&
this.left === other.left &&
this.top === other.top &&
Expand Down
16 changes: 16 additions & 0 deletions Source/Renderer/AutomaticUniforms.js
Original file line number Diff line number Diff line change
Expand Up @@ -1135,6 +1135,22 @@ define([
}
}),

/**
* The log of the current frustums far plane. Used for computing the log depth.
*
* @alias czm_logFarDistance
* @glslUniform
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add an @example like the other items in here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added the private tag instead in case we ever make this class public (likely for post-processing). It only has the one purpose and removes an extra log from the shaders.

*
* @private
*/
czm_logFarDistance : new AutomaticUniform({
size : 1,
datatype : WebGLConstants.FLOAT,
getValue : function(uniformState) {
return uniformState.logFarDistance;
}
}),

/**
* An automatic GLSL uniform representing the sun position in world coordinates.
*
Expand Down
14 changes: 14 additions & 0 deletions Source/Renderer/UniformState.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ define([
this._entireFrustum = new Cartesian2();
this._currentFrustum = new Cartesian2();
this._frustumPlanes = new Cartesian4();
this._logFarDistance = undefined;

this._frameState = undefined;
this._temeToPseudoFixed = Matrix3.clone(Matrix4.IDENTITY);
Expand Down Expand Up @@ -641,6 +642,17 @@ define([
}
},

/**
* The log of the current frustum's far distance. Used to compute the log depth.
* @memberof UniformState.prototype
* @type {Number}
*/
logFarDistance : {
get : function() {
return this._logFarDistance;
}
},

/**
* The the height (<code>x</code>) and the height squared (<code>y</code>)
* in meters of the camera above the 2D world plane. This uniform is only valid
Expand Down Expand Up @@ -987,6 +999,8 @@ define([
this._currentFrustum.x = frustum.near;
this._currentFrustum.y = frustum.far;

this._logFarDistance = 2.0 / CesiumMath.log2(frustum.far + 1.0);

if (defined(frustum._offCenterFrustum)) {
frustum = frustum._offCenterFrustum;
}
Expand Down
17 changes: 13 additions & 4 deletions Source/Scene/Camera.js
Original file line number Diff line number Diff line change
Expand Up @@ -2574,10 +2574,13 @@ define([
var scratchProj = new Cartesian3();

/**
* Return the distance from the camera to the front of the bounding sphere.
* Return the signed distance from the camera to the front of the bounding sphere.
* <p>
* Positive values indicate that the bounding sphere is in the positive half-plane of the camera position and view direction while a negative value indicates it is in the negative half-plane.
* </p>
*
* @param {BoundingSphere} boundingSphere The bounding sphere in world coordinates.
* @returns {Number} The distance to the bounding sphere.
* @returns {Number} The signed distance to the bounding sphere.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warrants an update the CHANGES.md?

*/
Camera.prototype.distanceToBoundingSphere = function(boundingSphere) {
//>>includeStart('debug', pragmas.debug);
Expand All @@ -2587,8 +2590,10 @@ define([
//>>includeEnd('debug');

var toCenter = Cartesian3.subtract(this.positionWC, boundingSphere.center, scratchToCenter);
var proj = Cartesian3.multiplyByScalar(this.directionWC, Cartesian3.dot(toCenter, this.directionWC), scratchProj);
return Math.max(0.0, Cartesian3.magnitude(proj) - boundingSphere.radius);
var distance = -Cartesian3.dot(toCenter, this.directionWC);
var proj = Cartesian3.multiplyByScalar(this.directionWC, distance, scratchProj);
var unsignedDistance = Math.max(0.0, Cartesian3.magnitude(proj) - boundingSphere.radius);
return distance < 0.0 ? -unsignedDistance : unsignedDistance;
};

var scratchPixelSize = new Cartesian2();
Expand All @@ -2615,6 +2620,9 @@ define([
//>>includeEnd('debug');

var distance = this.distanceToBoundingSphere(boundingSphere);
if (distance < 0.0) {
return 0.0;
}
var pixelSize = this.frustum.getPixelDimensions(drawingBufferWidth, drawingBufferHeight, distance, scratchPixelSize);
return Math.max(pixelSize.x, pixelSize.y);
};
Expand Down Expand Up @@ -3229,6 +3237,7 @@ define([
Cartesian3.clone(camera.right, result.right);
Matrix4.clone(camera._transform, result.transform);
result._transformChanged = true;
result.frustum = camera.frustum.clone();

return result;
};
Expand Down
24 changes: 22 additions & 2 deletions Source/Scene/Cesium3DTileBatchTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -1351,7 +1351,7 @@ define([
if (bivariateVisibilityTest) {
if (command.pass !== Pass.TRANSLUCENT && !finalResolution) {
if (!defined(derivedCommands.zback)) {
derivedCommands.zback = deriveZBackfaceCommand(derivedCommands.originalCommand);
derivedCommands.zback = deriveZBackfaceCommand(frameState.context, derivedCommands.originalCommand);
}
tileset._backfaceCommands.push(derivedCommands.zback);
}
Expand Down Expand Up @@ -1436,7 +1436,24 @@ define([
return derivedCommand;
}

function deriveZBackfaceCommand(command) {
function getDisableLogDepthFragmentShaderProgram(context, shaderProgram) {
var shader = context.shaderCache.getDerivedShaderProgram(shaderProgram, 'zBackfaceLogDepth');
if (!defined(shader)) {
var fs = shaderProgram.fragmentShaderSource.clone();
fs.defines = defined(fs.defines) ? fs.defines.slice(0) : [];
fs.defines.push('DISABLE_LOG_DEPTH_FRAGMENT_WRITE');

shader = context.shaderCache.createDerivedShaderProgram(shaderProgram, 'zBackfaceLogDepth', {
vertexShaderSource : shaderProgram.vertexShaderSource,
fragmentShaderSource : fs,
attributeLocations : shaderProgram._attributeLocations
});
}

return shader;
}

function deriveZBackfaceCommand(context, command) {
// Write just backface depth of unresolved tiles so resolved stenciled tiles do not appear in front
var derivedCommand = DrawCommand.shallowClone(command);
var rs = clone(derivedCommand.renderState, true);
Expand All @@ -1459,6 +1476,9 @@ define([
derivedCommand.renderState = RenderState.fromCache(rs);
derivedCommand.castShadows = false;
derivedCommand.receiveShadows = false;
// Disable the depth writes in the fragment shader. The back face commands were causing the higher resolution
// tiles to disappear.
derivedCommand.shaderProgram = getDisableLogDepthFragmentShaderProgram(context, command.shaderProgram);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested that skip lods still works with this change, but I'm confused why. Wouldn't the regular commands write log depth while the back face commands write normal depth?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The back face commands still write log depth in the vertex shader. The depth is correct at the vertices but interpolated linearly which is incorrect, but only noticeable for long triangles close to the camera. The fix is to output a linear value from the vertex shader and compute the log in the fragment shader.

return derivedCommand;
}

Expand Down
28 changes: 19 additions & 9 deletions Source/Scene/ClassificationModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -663,34 +663,38 @@ define([
}

function createProgram(model) {
var positionName = ModelUtility.getAttributeOrUniformBySemantic(model.gltf, 'POSITION');
var batchIdName = ModelUtility.getAttributeOrUniformBySemantic(model.gltf, '_BATCHID');
var gltf = model.gltf;

var positionName = ModelUtility.getAttributeOrUniformBySemantic(gltf, 'POSITION');
var batchIdName = ModelUtility.getAttributeOrUniformBySemantic(gltf, '_BATCHID');

var attributeLocations = {};
attributeLocations[positionName] = 0;
attributeLocations[batchIdName] = 1;

var modelViewProjectionName = ModelUtility.getAttributeOrUniformBySemantic(model.gltf, 'MODELVIEWPROJECTION');
var modelViewProjectionName = ModelUtility.getAttributeOrUniformBySemantic(gltf, 'MODELVIEWPROJECTION');

var uniformDecl;
var computePosition;
var toClip;

if (!defined(modelViewProjectionName)) {
var projectionName = ModelUtility.getAttributeOrUniformBySemantic(model.gltf, 'PROJECTION');
var modelViewName = ModelUtility.getAttributeOrUniformBySemantic(model.gltf, 'MODELVIEW');
var projectionName = ModelUtility.getAttributeOrUniformBySemantic(gltf, 'PROJECTION');
var modelViewName = ModelUtility.getAttributeOrUniformBySemantic(gltf, 'MODELVIEW');
if (!defined(modelViewName)) {
modelViewName = ModelUtility.getAttributeOrUniformBySemantic(model.gltf, 'CESIUM_RTC_MODELVIEW');
modelViewName = ModelUtility.getAttributeOrUniformBySemantic(gltf, 'CESIUM_RTC_MODELVIEW');
}

uniformDecl =
'uniform mat4 ' + modelViewName + ';\n' +
'uniform mat4 ' + projectionName + ';\n';
computePosition = ' vec4 positionInClipCoords = ' + projectionName + ' * ' + modelViewName + ' * vec4(' + positionName + ', 1.0);\n';
toClip = projectionName + ' * ' + modelViewName + ' * vec4(' + positionName + ', 1.0)';
} else {
uniformDecl = 'uniform mat4 ' + modelViewProjectionName + ';\n';
computePosition = ' vec4 positionInClipCoords = ' + modelViewProjectionName + ' * vec4(' + positionName + ', 1.0);\n';
toClip = modelViewProjectionName + ' * vec4(' + positionName + ', 1.0)';
}

var computePosition = ' vec4 positionInClipCoords = ' + toClip + ';\n';

var vs =
'attribute vec3 ' + positionName + ';\n' +
'attribute float ' + batchIdName + ';\n' +
Expand All @@ -716,6 +720,9 @@ define([
var drawVS = modifyShader(vs, model._vertexShaderLoaded);
var drawFS = modifyShader(fs, model._classificationShaderLoaded);

drawVS = ModelUtility.modifyVertexShaderForLogDepth(drawVS, toClip);
drawFS = ModelUtility.modifyFragmentShaderForLogDepth(drawFS);

model._shaderProgram = {
vertexShaderSource : drawVS,
fragmentShaderSource : drawFS,
Expand All @@ -726,6 +733,9 @@ define([
var pickVS = modifyShader(vs, model._pickVertexShaderLoaded);
var pickFS = modifyShader(fs, model._pickFragmentShaderLoaded);

pickVS = ModelUtility.modifyVertexShaderForLogDepth(pickVS, toClip);
pickFS = ModelUtility.modifyFragmentShaderForLogDepth(pickFS);

model._pickShaderProgram = {
vertexShaderSource : pickVS,
fragmentShaderSource : pickFS,
Expand Down
49 changes: 38 additions & 11 deletions Source/Scene/DepthPlane.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ define([
'../Renderer/Pass',
'../Renderer/RenderState',
'../Renderer/ShaderProgram',
'../Renderer/ShaderSource',
'../Renderer/VertexArray',
'../Shaders/DepthPlaneFS',
'../Shaders/DepthPlaneVS',
Expand All @@ -30,6 +31,7 @@ define([
Pass,
RenderState,
ShaderProgram,
ShaderSource,
VertexArray,
DepthPlaneFS,
DepthPlaneVS,
Expand All @@ -45,6 +47,7 @@ define([
this._va = undefined;
this._command = undefined;
this._mode = undefined;
this._useLogDepth = false;
}

var depthQuadScratch = FeatureDetection.supportsTypedArrays() ? new Float32Array(12) : [];
Expand Down Expand Up @@ -100,7 +103,7 @@ define([
return depthQuadScratch;
}

DepthPlane.prototype.update = function(frameState) {
DepthPlane.prototype.update = function(frameState, useLogDepth) {
this._mode = frameState.mode;
if (frameState.mode !== SceneMode.SCENE3D) {
return;
Expand All @@ -125,24 +128,48 @@ define([
}
});

this._sp = ShaderProgram.fromCache({
context : context,
vertexShaderSource : DepthPlaneVS,
fragmentShaderSource : DepthPlaneFS,
attributeLocations : {
position : 0
}
});

this._command = new DrawCommand({
renderState : this._rs,
shaderProgram : this._sp,
boundingVolume : new BoundingSphere(Cartesian3.ZERO, ellipsoid.maximumRadius),
pass : Pass.OPAQUE,
owner : this
});
}

if (!defined(this._sp) || this._useLogDepth !== useLogDepth) {
this._useLogDepth = useLogDepth;

var vs = new ShaderSource({
sources : [DepthPlaneVS]
});
var fs = new ShaderSource({
sources : [DepthPlaneFS]
});
if (useLogDepth) {
var extension =
'#ifdef GL_EXT_frag_depth \n' +
'#extension GL_EXT_frag_depth : enable \n' +
'#endif \n\n';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of adding this code manually could it be included in writeLogZ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, no. When the shader is built, it searches the sources for extensions not the built-in functions.


fs.sources.push(extension);
fs.defines.push('LOG_DEPTH');
vs.defines.push('LOG_DEPTH');
vs.defines.push('DISABLE_GL_POSITION_LOG_DEPTH');
}

this._sp = ShaderProgram.replaceCache({
shaderProgram : this._sp,
context : context,
vertexShaderSource : vs,
fragmentShaderSource : fs,
attributeLocations : {
position : 0
}
});

this._command.shaderProgram = this._sp;
}

// update depth plane
var depthQuad = computeDepthQuad(ellipsoid, frameState);

Expand Down
Loading