Skip to content

Commit bd5a049

Browse files
committed
Move uniform map creation so it's easier to merge in mutables
1 parent 59e169a commit bd5a049

File tree

1 file changed

+83
-71
lines changed

1 file changed

+83
-71
lines changed

Source/Scene/PointCloud.js

+83-71
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ define([
118118
this._styleTranslucent = false;
119119
this._constantColor = Color.clone(Color.DARKGRAY);
120120
this._highlightColor = Color.clone(Color.WHITE);
121-
this._pointSize = 1.0;
121+
this._pointSize = 10.0;
122122

123123
this._rtcCenter = undefined;
124124
this._quantizedVolumeScale = undefined;
@@ -540,71 +540,6 @@ define([
540540
}
541541
}
542542
}
543-
var uniformMap = {
544-
u_pointSizeAndTimeAndGeometricErrorAndDepthMultiplier : function() {
545-
var scratch = scratchPointSizeAndTimeAndGeometricErrorAndDepthMultiplier;
546-
scratch.x = pointCloud._attenuation ? pointCloud.maximumAttenuation : pointCloud._pointSize;
547-
scratch.y = pointCloud.time;
548-
549-
if (pointCloud._attenuation) {
550-
var frustum = frameState.camera.frustum;
551-
var depthMultiplier;
552-
// Attenuation is maximumAttenuation in 2D/ortho
553-
if (frameState.mode === SceneMode.SCENE2D || frustum instanceof OrthographicFrustum) {
554-
depthMultiplier = Number.POSITIVE_INFINITY;
555-
} else {
556-
depthMultiplier = context.drawingBufferHeight / frameState.camera.frustum.sseDenominator;
557-
}
558-
559-
scratch.z = pointCloud.geometricError * pointCloud.geometricErrorScale;
560-
scratch.w = depthMultiplier;
561-
}
562-
563-
return scratch;
564-
},
565-
u_highlightColor : function() {
566-
return pointCloud._highlightColor;
567-
},
568-
u_constantColor : function() {
569-
return pointCloud._constantColor;
570-
},
571-
u_clippingPlanes : function() {
572-
var clippingPlanes = pointCloud.clippingPlanes;
573-
var isClipped = pointCloud.isClipped;
574-
return isClipped ? clippingPlanes.texture : context.defaultTexture;
575-
},
576-
u_clippingPlanesEdgeStyle : function() {
577-
var clippingPlanes = pointCloud.clippingPlanes;
578-
if (!defined(clippingPlanes)) {
579-
return Color.TRANSPARENT;
580-
}
581-
582-
var style = Color.clone(clippingPlanes.edgeColor, scratchColor);
583-
style.alpha = clippingPlanes.edgeWidth;
584-
return style;
585-
},
586-
u_clippingPlanesMatrix : function() {
587-
var clippingPlanes = pointCloud.clippingPlanes;
588-
if (!defined(clippingPlanes)) {
589-
return Matrix4.IDENTITY;
590-
}
591-
var modelViewMatrix = Matrix4.multiply(context.uniformState.view3D, pointCloud._modelMatrix, scratchClippingPlaneMatrix);
592-
return Matrix4.multiply(modelViewMatrix, clippingPlanes.modelMatrix, scratchClippingPlaneMatrix);
593-
}
594-
};
595-
596-
if (isQuantized || isQuantizedDraco || isOctEncodedDraco) {
597-
uniformMap = combine(uniformMap, {
598-
u_quantizedVolumeScaleAndOctEncodedRange : function() {
599-
var scratch = scratchQuantizedVolumeScaleAndOctEncodedRange;
600-
if (defined(pointCloud._quantizedVolumeScale)) {
601-
Cartesian3.clone(pointCloud._quantizedVolumeScale, scratch);
602-
}
603-
scratch.w = pointCloud._octEncodedRange;
604-
return scratch;
605-
}
606-
});
607-
}
608543

609544
var positionsVertexBuffer = Buffer.createVertexBuffer({
610545
context : context,
@@ -735,10 +670,6 @@ define([
735670
attributes : attributes
736671
});
737672

738-
if (defined(pointCloud._uniformMapLoaded)) {
739-
uniformMap = pointCloud._uniformMapLoaded(uniformMap);
740-
}
741-
742673
pointCloud._opaqueRenderState = RenderState.fromCache({
743674
depthTest : {
744675
enabled : true
@@ -761,7 +692,7 @@ define([
761692
vertexArray : vertexArray,
762693
count : pointsLength,
763694
shaderProgram : undefined, // Updated in createShaders
764-
uniformMap : uniformMap,
695+
uniformMap : undefined, // Updated in createShaders
765696
renderState : isTranslucent ? pointCloud._translucentRenderState : pointCloud._opaqueRenderState,
766697
pass : isTranslucent ? Pass.TRANSLUCENT : pointCloud._opaquePass,
767698
owner : pointCloud,
@@ -771,6 +702,85 @@ define([
771702
});
772703
}
773704

705+
function createUniformMap(pointCloud, frameState) {
706+
var context = frameState.context;
707+
var isQuantized = pointCloud._isQuantized;
708+
var isQuantizedDraco = pointCloud._isQuantizedDraco;
709+
var isOctEncodedDraco = pointCloud._isOctEncodedDraco;
710+
711+
var uniformMap = {
712+
u_pointSizeAndTimeAndGeometricErrorAndDepthMultiplier : function() {
713+
var scratch = scratchPointSizeAndTimeAndGeometricErrorAndDepthMultiplier;
714+
scratch.x = pointCloud._attenuation ? pointCloud.maximumAttenuation : pointCloud._pointSize;
715+
scratch.y = pointCloud.time;
716+
717+
if (pointCloud._attenuation) {
718+
var frustum = frameState.camera.frustum;
719+
var depthMultiplier;
720+
// Attenuation is maximumAttenuation in 2D/ortho
721+
if (frameState.mode === SceneMode.SCENE2D || frustum instanceof OrthographicFrustum) {
722+
depthMultiplier = Number.POSITIVE_INFINITY;
723+
} else {
724+
depthMultiplier = context.drawingBufferHeight / frameState.camera.frustum.sseDenominator;
725+
}
726+
727+
scratch.z = pointCloud.geometricError * pointCloud.geometricErrorScale;
728+
scratch.w = depthMultiplier;
729+
}
730+
731+
return scratch;
732+
},
733+
u_highlightColor : function() {
734+
return pointCloud._highlightColor;
735+
},
736+
u_constantColor : function() {
737+
return pointCloud._constantColor;
738+
},
739+
u_clippingPlanes : function() {
740+
var clippingPlanes = pointCloud.clippingPlanes;
741+
var isClipped = pointCloud.isClipped;
742+
return isClipped ? clippingPlanes.texture : context.defaultTexture;
743+
},
744+
u_clippingPlanesEdgeStyle : function() {
745+
var clippingPlanes = pointCloud.clippingPlanes;
746+
if (!defined(clippingPlanes)) {
747+
return Color.TRANSPARENT;
748+
}
749+
750+
var style = Color.clone(clippingPlanes.edgeColor, scratchColor);
751+
style.alpha = clippingPlanes.edgeWidth;
752+
return style;
753+
},
754+
u_clippingPlanesMatrix : function() {
755+
var clippingPlanes = pointCloud.clippingPlanes;
756+
if (!defined(clippingPlanes)) {
757+
return Matrix4.IDENTITY;
758+
}
759+
var modelViewMatrix = Matrix4.multiply(context.uniformState.view3D, pointCloud._modelMatrix, scratchClippingPlaneMatrix);
760+
return Matrix4.multiply(modelViewMatrix, clippingPlanes.modelMatrix, scratchClippingPlaneMatrix);
761+
}
762+
};
763+
764+
if (isQuantized || isQuantizedDraco || isOctEncodedDraco) {
765+
uniformMap = combine(uniformMap, {
766+
u_quantizedVolumeScaleAndOctEncodedRange : function() {
767+
var scratch = scratchQuantizedVolumeScaleAndOctEncodedRange;
768+
if (defined(pointCloud._quantizedVolumeScale)) {
769+
Cartesian3.clone(pointCloud._quantizedVolumeScale, scratch);
770+
}
771+
scratch.w = pointCloud._octEncodedRange;
772+
return scratch;
773+
}
774+
});
775+
}
776+
777+
if (defined(pointCloud._uniformMapLoaded)) {
778+
uniformMap = pointCloud._uniformMapLoaded(uniformMap);
779+
}
780+
781+
pointCloud._drawCommand.uniformMap = uniformMap;
782+
}
783+
774784
var defaultProperties = ['POSITION', 'COLOR', 'NORMAL', 'POSITION_ABSOLUTE'];
775785

776786
function getStyleableProperties(source, properties) {
@@ -935,6 +945,8 @@ define([
935945
attributeLocations[attributeName] = attribute.location;
936946
}
937947

948+
createUniformMap(pointCloud, frameState);
949+
938950
var vs = 'attribute vec3 a_position; \n' +
939951
'varying vec4 v_color; \n' +
940952
'uniform vec4 u_pointSizeAndTimeAndGeometricErrorAndDepthMultiplier; \n' +

0 commit comments

Comments
 (0)