From fb385b962909ee12e30b4388caec8c918589655f Mon Sep 17 00:00:00 2001 From: Connor Manning Date: Tue, 19 Nov 2024 13:16:18 -0600 Subject: [PATCH 1/4] Discard hidden points in the fragment shader, rather than moving them in the vertex shader. Fixes #11270. --- .../Scene/Model/PointCloudStylingPipelineStage.js | 3 ++- packages/engine/Source/Shaders/Model/ModelFS.glsl | 7 +++++++ packages/engine/Source/Shaders/Model/ModelVS.glsl | 10 +++++++++- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/packages/engine/Source/Scene/Model/PointCloudStylingPipelineStage.js b/packages/engine/Source/Scene/Model/PointCloudStylingPipelineStage.js index 967e07fcfe98..c89786f88f05 100644 --- a/packages/engine/Source/Scene/Model/PointCloudStylingPipelineStage.js +++ b/packages/engine/Source/Scene/Model/PointCloudStylingPipelineStage.js @@ -333,9 +333,10 @@ function addShaderFunctionsAndDefines(shaderBuilder, shaderFunctionInfo) { shaderBuilder.addDefine( "HAS_POINT_CLOUD_SHOW_STYLE", undefined, - ShaderDestination.VERTEX, + ShaderDestination.BOTH, ); shaderBuilder.addVertexLines(showStyleFunction); + shaderBuilder.addVarying("float", "v_pointCloudShow"); } const pointSizeStyleFunction = shaderFunctionInfo.pointSizeStyleFunction; diff --git a/packages/engine/Source/Shaders/Model/ModelFS.glsl b/packages/engine/Source/Shaders/Model/ModelFS.glsl index 0500c0b9f1ff..a6cb2827f60f 100644 --- a/packages/engine/Source/Shaders/Model/ModelFS.glsl +++ b/packages/engine/Source/Shaders/Model/ModelFS.glsl @@ -28,6 +28,13 @@ SelectedFeature selectedFeature; void main() { + #ifdef HAS_POINT_CLOUD_SHOW_STYLE + if (v_pointCloudShow == 0.0) + { + discard; + } + #endif + #ifdef HAS_MODEL_SPLITTER modelSplitterStage(); #endif diff --git a/packages/engine/Source/Shaders/Model/ModelVS.glsl b/packages/engine/Source/Shaders/Model/ModelVS.glsl index b95b329f59ff..2164da1024bc 100644 --- a/packages/engine/Source/Shaders/Model/ModelVS.glsl +++ b/packages/engine/Source/Shaders/Model/ModelVS.glsl @@ -145,5 +145,13 @@ void main() gl_PointSize *= show; #endif - gl_Position = show * positionClip; + // Important NOT to compute gl_Position = show * positionClip or we hit: + // https://github.com/CesiumGS/cesium/issues/11270 + // + // We will discard points with v_pointCloudShow == 0 in the fragment shader. + gl_Position = positionClip; + + #ifdef HAS_POINT_CLOUD_SHOW_STYLE + v_pointCloudShow = show; + #endif } From 251a67f43da47c718b03b9358fb1c9c95c586930 Mon Sep 17 00:00:00 2001 From: Connor Manning Date: Tue, 19 Nov 2024 14:19:36 -0600 Subject: [PATCH 2/4] Add to contributors list. --- CONTRIBUTORS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index cc7913527093..d53965da58ef 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -416,3 +416,4 @@ See [CONTRIBUTING.md](CONTRIBUTING.md) for details on how to contribute to Cesiu - [Jérôme Fayot](https://github.com/jfayot) - [Kirn Kim](https://github.com/squrki) - [Emanuele Mastaglia](https://github.com/Masty88) +- [Connor Manning](https://github.com/connormanning) From 7bf4fbed1c011d7ab29fa03abad27b402f512e56 Mon Sep 17 00:00:00 2001 From: Connor Manning Date: Tue, 19 Nov 2024 14:21:29 -0600 Subject: [PATCH 3/4] Add note to changelog. --- CHANGES.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES.md b/CHANGES.md index 49e2c0056ac6..ade02069a297 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -11,6 +11,7 @@ ##### Fixes :wrench: - Fix label rendering bug in WebGL1 contexts. [#12301](https://github.com/CesiumGS/cesium/pull/12301) +- Fix point cloud filtering performance on certain hardware [#12317](https://github.com/CesiumGS/cesium/pull/12317) #### @cesium/widgets From a394dab7573cb160045b953d1299068c296ed6ab Mon Sep 17 00:00:00 2001 From: Connor Manning Date: Wed, 20 Nov 2024 14:21:47 -0600 Subject: [PATCH 4/4] Fix unit test. --- .../Specs/Scene/Model/PointCloudStylingPipelineStageSpec.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/engine/Specs/Scene/Model/PointCloudStylingPipelineStageSpec.js b/packages/engine/Specs/Scene/Model/PointCloudStylingPipelineStageSpec.js index 11cf22014bd7..ae7deeead20b 100644 --- a/packages/engine/Specs/Scene/Model/PointCloudStylingPipelineStageSpec.js +++ b/packages/engine/Specs/Scene/Model/PointCloudStylingPipelineStageSpec.js @@ -314,7 +314,9 @@ describe( "HAS_POINT_CLOUD_SHOW_STYLE", "COMPUTE_POSITION_WC_STYLE", ]); - ShaderBuilderTester.expectHasFragmentDefines(shaderBuilder, []); + ShaderBuilderTester.expectHasFragmentDefines(shaderBuilder, [ + "HAS_POINT_CLOUD_SHOW_STYLE", + ]); ShaderBuilderTester.expectHasVertexUniforms(shaderBuilder, [ "uniform vec4 model_pointCloudParameters;",