From 7c46e11acfcca8f52af1de2d55f63ce46cf615cd Mon Sep 17 00:00:00 2001 From: Dan Bagnell Date: Fri, 16 Feb 2018 14:17:06 -0500 Subject: [PATCH] Minor clean up. --- Source/Scene/ClassificationPrimitive.js | 14 ++++++-------- Source/Scene/GlobeSurfaceShaderSet.js | 3 --- Source/Scene/PointCloud3DTileContent.js | 2 +- Source/Scene/Scene.js | 19 +++++++------------ Source/Scene/SceneTransforms.js | 5 ++--- 5 files changed, 16 insertions(+), 27 deletions(-) diff --git a/Source/Scene/ClassificationPrimitive.js b/Source/Scene/ClassificationPrimitive.js index 8ef08a09ffba..c4ec4affb04b 100644 --- a/Source/Scene/ClassificationPrimitive.js +++ b/Source/Scene/ClassificationPrimitive.js @@ -1,6 +1,5 @@ define([ '../Core/ColorGeometryInstanceAttribute', - '../Core/combine', '../Core/defaultValue', '../Core/defined', '../Core/defineProperties', @@ -26,7 +25,6 @@ define([ './StencilOperation' ], function( ColorGeometryInstanceAttribute, - combine, defaultValue, defined, defineProperties, @@ -594,7 +592,7 @@ define([ }); } - function createColorCommands(classificationPrimitive, colorCommands, frameState) { + function createColorCommands(classificationPrimitive, colorCommands) { var primitive = classificationPrimitive._primitive; var length = primitive._va.length * 3; colorCommands.length = length; @@ -669,7 +667,7 @@ define([ } } - function createPickCommands(classificationPrimitive, pickCommands, frameState) { + function createPickCommands(classificationPrimitive, pickCommands) { var primitive = classificationPrimitive._primitive; var pickOffsets = primitive._pickOffsets; var length = pickOffsets.length * 3; @@ -737,9 +735,9 @@ define([ } } - function createCommands(classificationPrimitive, appearance, material, translucent, twoPasses, colorCommands, pickCommands, frameState) { - createColorCommands(classificationPrimitive, colorCommands, frameState); - createPickCommands(classificationPrimitive, pickCommands, frameState); + function createCommands(classificationPrimitive, appearance, material, translucent, twoPasses, colorCommands, pickCommands) { + createColorCommands(classificationPrimitive, colorCommands); + createPickCommands(classificationPrimitive, pickCommands); } function boundingVolumeIndex(commandIndex, length) { @@ -892,7 +890,7 @@ define([ createShaderProgram(that, frameState); }; primitiveOptions._createCommandsFunction = function(primitive, appearance, material, translucent, twoPasses, colorCommands, pickCommands) { - createCommands(that, undefined, undefined, true, false, colorCommands, pickCommands, frameState); + createCommands(that, undefined, undefined, true, false, colorCommands, pickCommands); }; if (defined(this._updateAndQueueCommandsFunction)) { diff --git a/Source/Scene/GlobeSurfaceShaderSet.js b/Source/Scene/GlobeSurfaceShaderSet.js index a6f5290a49d1..41df7c8e554e 100644 --- a/Source/Scene/GlobeSurfaceShaderSet.js +++ b/Source/Scene/GlobeSurfaceShaderSet.js @@ -117,9 +117,6 @@ define([ vs.defines.push(quantizationDefine); fs.defines.push('TEXTURE_UNITS ' + numberOfDayTextures); - if (frameState.logDepthBuffer) { - fs.defines.push('LOG_DEPTH_BUFFER'); - } if (applyBrightness) { fs.defines.push('APPLY_BRIGHTNESS'); } diff --git a/Source/Scene/PointCloud3DTileContent.js b/Source/Scene/PointCloud3DTileContent.js index bd0b46144e59..f312745e6909 100644 --- a/Source/Scene/PointCloud3DTileContent.js +++ b/Source/Scene/PointCloud3DTileContent.js @@ -1101,7 +1101,7 @@ define([ vs += ' v_color = color; \n' + ' gl_Position = czm_modelViewProjection * vec4(position, 1.0); \n' + - ' v_inverse_depth = 1. / gl_Position.w; \n'; + ' v_inverse_depth = 1.0 / gl_Position.w; \n'; if (hasNormals && backFaceCulling) { vs += ' float visible = step(-normal.z, 0.0); \n' + diff --git a/Source/Scene/Scene.js b/Source/Scene/Scene.js index 6e71a9516d04..8cef52d6c191 100644 --- a/Source/Scene/Scene.js +++ b/Source/Scene/Scene.js @@ -239,7 +239,6 @@ define([ */ function Scene(options) { options = defaultValue(options, defaultValue.EMPTY_OBJECT); - var canvas = options.canvas; var contextOptions = options.contextOptions; var creditContainer = options.creditContainer; @@ -262,20 +261,16 @@ define([ creditContainer.style['padding-right'] = '5px'; canvas.parentNode.appendChild(creditContainer); } - if (context.fragmentDepth) { - this.logDepthBuffer = true; - } else { - this.logDepthBuffer = false; - } if (!defined(creditViewport)) { creditViewport = canvas.parentNode; } + this._logDepthBuffer = context.fragmentDepth; + this._id = createGuid(); this._jobScheduler = new JobScheduler(); this._frameState = new FrameState(context, new CreditDisplay(creditContainer, ' • ', creditViewport), this._jobScheduler); this._frameState.scene3DOnly = defaultValue(options.scene3DOnly, false); - this._frameState.logDepthBuffer = this.logDepthBuffer; this._removeCreditContainer = !hasCreditContainer; this._creditContainer = creditContainer; @@ -773,7 +768,7 @@ define([ var far = camera.frustum.far; var numFrustums; var farToNearRatio; - if (this.logDepthBuffer) { + if (this._logDepthBuffer) { numFrustums = 1; farToNearRatio = far / near; } else { @@ -1719,13 +1714,13 @@ define([ // Exploit temporal coherence. If the frustums haven't changed much, use the frustums computed // last frame, else compute the new frustums and sort them by frustum again. var is2D = scene.mode === SceneMode.SCENE2D; - + var logDepth = scene._logDepthBuffer && !(camera.frustum instanceof OrthographicFrustum || camera.frustum instanceof OrthographicOffCenterFrustum); var farToNearRatio = scene.farToNearRatio; var numFrustums; if (!is2D) { // The multifrustum for 3D/CV is non-uniformly distributed. - if (scene.logDepthBuffer) { + if (logDepth) { numFrustums = 1; farToNearRatio = far / near; } else { @@ -1733,7 +1728,7 @@ define([ } } else { // The multifrustum for 2D is uniformly distributed. To avoid z-fighting in 2D, - // the camera i smoved to just before the frustum and the frustum depth is scaled + // the camera is moved to just before the frustum and the frustum depth is scaled // to be in [1.0, nearToFarDistance2D]. far = Math.min(far, camera.position.z + scene.nearToFarDistance2D); near = Math.min(near, far); @@ -1745,7 +1740,7 @@ define([ farChange = far / frustumCommandsList[numberOfFrustums - 1].far; } if ((near !== Number.MAX_VALUE && (numFrustums !== numberOfFrustums || (frustumCommandsList.length !== 0 && - ((scene.logDepthBuffer && isFinite(farChange) && !CesiumMath.equalsEpsilon(1, farChange, CesiumMath.EPSILON8)) || + ((logDepth && isFinite(farChange) && !CesiumMath.equalsEpsilon(1, farChange, CesiumMath.EPSILON8)) || (near < frustumCommandsList[0].near || (far > frustumCommandsList[numberOfFrustums - 1].far && !CesiumMath.equalsEpsilon(far, frustumCommandsList[numberOfFrustums - 1].far, CesiumMath.EPSILON8)))))))) { updateFrustums(near, far, farToNearRatio, numFrustums, frustumCommandsList, is2D, scene.nearToFarDistance2D); createPotentiallyVisibleSet(scene); diff --git a/Source/Scene/SceneTransforms.js b/Source/Scene/SceneTransforms.js index 9191f5a84b40..cd6331aa1034 100644 --- a/Source/Scene/SceneTransforms.js +++ b/Source/Scene/SceneTransforms.js @@ -308,7 +308,7 @@ define([ var ndc = Cartesian4.clone(Cartesian4.UNIT_W, scratchNDC); ndc.x = (drawingBufferPosition.x - viewport.x) / viewport.width * 2.0 - 1.0; ndc.y = (drawingBufferPosition.y - viewport.y) / viewport.height * 2.0 - 1.0; - if (scene.logDepthBuffer) { + if (scene._logDepthBuffer) { var frustumCommand = scene._frustumCommandsList[0]; var far = frustumCommand.far; var near = frustumCommand.near; @@ -343,8 +343,7 @@ define([ var w = 1.0 / worldCoords.w; Cartesian3.multiplyByScalar(worldCoords, w, worldCoords); } - result = Cartesian3.fromCartesian4(worldCoords, result); - return result; + return Cartesian3.fromCartesian4(worldCoords, result); }; return SceneTransforms;