From bd5a04992fb47ccbf9ca7aff317413b536d10253 Mon Sep 17 00:00:00 2001 From: Sean Lilley Date: Fri, 22 Jun 2018 14:17:57 -0400 Subject: [PATCH] Move uniform map creation so it's easier to merge in mutables --- Source/Scene/PointCloud.js | 154 ++++++++++++++++++++----------------- 1 file changed, 83 insertions(+), 71 deletions(-) diff --git a/Source/Scene/PointCloud.js b/Source/Scene/PointCloud.js index f7e8abff3851..7103da1a0cdc 100644 --- a/Source/Scene/PointCloud.js +++ b/Source/Scene/PointCloud.js @@ -118,7 +118,7 @@ define([ this._styleTranslucent = false; this._constantColor = Color.clone(Color.DARKGRAY); this._highlightColor = Color.clone(Color.WHITE); - this._pointSize = 1.0; + this._pointSize = 10.0; this._rtcCenter = undefined; this._quantizedVolumeScale = undefined; @@ -540,71 +540,6 @@ define([ } } } - var uniformMap = { - u_pointSizeAndTimeAndGeometricErrorAndDepthMultiplier : function() { - var scratch = scratchPointSizeAndTimeAndGeometricErrorAndDepthMultiplier; - scratch.x = pointCloud._attenuation ? pointCloud.maximumAttenuation : pointCloud._pointSize; - scratch.y = pointCloud.time; - - if (pointCloud._attenuation) { - var frustum = frameState.camera.frustum; - var depthMultiplier; - // Attenuation is maximumAttenuation in 2D/ortho - if (frameState.mode === SceneMode.SCENE2D || frustum instanceof OrthographicFrustum) { - depthMultiplier = Number.POSITIVE_INFINITY; - } else { - depthMultiplier = context.drawingBufferHeight / frameState.camera.frustum.sseDenominator; - } - - scratch.z = pointCloud.geometricError * pointCloud.geometricErrorScale; - scratch.w = depthMultiplier; - } - - return scratch; - }, - u_highlightColor : function() { - return pointCloud._highlightColor; - }, - u_constantColor : function() { - return pointCloud._constantColor; - }, - u_clippingPlanes : function() { - var clippingPlanes = pointCloud.clippingPlanes; - var isClipped = pointCloud.isClipped; - return isClipped ? clippingPlanes.texture : context.defaultTexture; - }, - u_clippingPlanesEdgeStyle : function() { - var clippingPlanes = pointCloud.clippingPlanes; - if (!defined(clippingPlanes)) { - return Color.TRANSPARENT; - } - - var style = Color.clone(clippingPlanes.edgeColor, scratchColor); - style.alpha = clippingPlanes.edgeWidth; - return style; - }, - u_clippingPlanesMatrix : function() { - var clippingPlanes = pointCloud.clippingPlanes; - if (!defined(clippingPlanes)) { - return Matrix4.IDENTITY; - } - var modelViewMatrix = Matrix4.multiply(context.uniformState.view3D, pointCloud._modelMatrix, scratchClippingPlaneMatrix); - return Matrix4.multiply(modelViewMatrix, clippingPlanes.modelMatrix, scratchClippingPlaneMatrix); - } - }; - - if (isQuantized || isQuantizedDraco || isOctEncodedDraco) { - uniformMap = combine(uniformMap, { - u_quantizedVolumeScaleAndOctEncodedRange : function() { - var scratch = scratchQuantizedVolumeScaleAndOctEncodedRange; - if (defined(pointCloud._quantizedVolumeScale)) { - Cartesian3.clone(pointCloud._quantizedVolumeScale, scratch); - } - scratch.w = pointCloud._octEncodedRange; - return scratch; - } - }); - } var positionsVertexBuffer = Buffer.createVertexBuffer({ context : context, @@ -735,10 +670,6 @@ define([ attributes : attributes }); - if (defined(pointCloud._uniformMapLoaded)) { - uniformMap = pointCloud._uniformMapLoaded(uniformMap); - } - pointCloud._opaqueRenderState = RenderState.fromCache({ depthTest : { enabled : true @@ -761,7 +692,7 @@ define([ vertexArray : vertexArray, count : pointsLength, shaderProgram : undefined, // Updated in createShaders - uniformMap : uniformMap, + uniformMap : undefined, // Updated in createShaders renderState : isTranslucent ? pointCloud._translucentRenderState : pointCloud._opaqueRenderState, pass : isTranslucent ? Pass.TRANSLUCENT : pointCloud._opaquePass, owner : pointCloud, @@ -771,6 +702,85 @@ define([ }); } + function createUniformMap(pointCloud, frameState) { + var context = frameState.context; + var isQuantized = pointCloud._isQuantized; + var isQuantizedDraco = pointCloud._isQuantizedDraco; + var isOctEncodedDraco = pointCloud._isOctEncodedDraco; + + var uniformMap = { + u_pointSizeAndTimeAndGeometricErrorAndDepthMultiplier : function() { + var scratch = scratchPointSizeAndTimeAndGeometricErrorAndDepthMultiplier; + scratch.x = pointCloud._attenuation ? pointCloud.maximumAttenuation : pointCloud._pointSize; + scratch.y = pointCloud.time; + + if (pointCloud._attenuation) { + var frustum = frameState.camera.frustum; + var depthMultiplier; + // Attenuation is maximumAttenuation in 2D/ortho + if (frameState.mode === SceneMode.SCENE2D || frustum instanceof OrthographicFrustum) { + depthMultiplier = Number.POSITIVE_INFINITY; + } else { + depthMultiplier = context.drawingBufferHeight / frameState.camera.frustum.sseDenominator; + } + + scratch.z = pointCloud.geometricError * pointCloud.geometricErrorScale; + scratch.w = depthMultiplier; + } + + return scratch; + }, + u_highlightColor : function() { + return pointCloud._highlightColor; + }, + u_constantColor : function() { + return pointCloud._constantColor; + }, + u_clippingPlanes : function() { + var clippingPlanes = pointCloud.clippingPlanes; + var isClipped = pointCloud.isClipped; + return isClipped ? clippingPlanes.texture : context.defaultTexture; + }, + u_clippingPlanesEdgeStyle : function() { + var clippingPlanes = pointCloud.clippingPlanes; + if (!defined(clippingPlanes)) { + return Color.TRANSPARENT; + } + + var style = Color.clone(clippingPlanes.edgeColor, scratchColor); + style.alpha = clippingPlanes.edgeWidth; + return style; + }, + u_clippingPlanesMatrix : function() { + var clippingPlanes = pointCloud.clippingPlanes; + if (!defined(clippingPlanes)) { + return Matrix4.IDENTITY; + } + var modelViewMatrix = Matrix4.multiply(context.uniformState.view3D, pointCloud._modelMatrix, scratchClippingPlaneMatrix); + return Matrix4.multiply(modelViewMatrix, clippingPlanes.modelMatrix, scratchClippingPlaneMatrix); + } + }; + + if (isQuantized || isQuantizedDraco || isOctEncodedDraco) { + uniformMap = combine(uniformMap, { + u_quantizedVolumeScaleAndOctEncodedRange : function() { + var scratch = scratchQuantizedVolumeScaleAndOctEncodedRange; + if (defined(pointCloud._quantizedVolumeScale)) { + Cartesian3.clone(pointCloud._quantizedVolumeScale, scratch); + } + scratch.w = pointCloud._octEncodedRange; + return scratch; + } + }); + } + + if (defined(pointCloud._uniformMapLoaded)) { + uniformMap = pointCloud._uniformMapLoaded(uniformMap); + } + + pointCloud._drawCommand.uniformMap = uniformMap; + } + var defaultProperties = ['POSITION', 'COLOR', 'NORMAL', 'POSITION_ABSOLUTE']; function getStyleableProperties(source, properties) { @@ -935,6 +945,8 @@ define([ attributeLocations[attributeName] = attribute.location; } + createUniformMap(pointCloud, frameState); + var vs = 'attribute vec3 a_position; \n' + 'varying vec4 v_color; \n' + 'uniform vec4 u_pointSizeAndTimeAndGeometricErrorAndDepthMultiplier; \n' +