From 9c96f56df148d389bb1efe1157defc9ca9d2a96d Mon Sep 17 00:00:00 2001 From: Dan Bagnell Date: Mon, 29 Apr 2013 15:39:45 -0400 Subject: [PATCH 1/4] Cull polyline if width is less than 1.0. --- Source/Shaders/PolylineVS.glsl | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Source/Shaders/PolylineVS.glsl b/Source/Shaders/PolylineVS.glsl index 76df7668dd73..13dc01ed5464 100644 --- a/Source/Shaders/PolylineVS.glsl +++ b/Source/Shaders/PolylineVS.glsl @@ -58,6 +58,13 @@ void clipLineSegmentToNearPlane( void main() { + // cull if width is less than 1.0 + if (abs(texCoordExpandWidthAndShow.z) < 1.0) + { + gl_Position = czm_projection * vec4(0.0, 0.0, 0.0, 1.0); + return; + } + float texCoord = texCoordExpandWidthAndShow.x; float expandDir = texCoordExpandWidthAndShow.y; float width = abs(texCoordExpandWidthAndShow.z) + 0.5; From c8de673d5549d30f92d8e2977e55e3fcf6278511 Mon Sep 17 00:00:00 2001 From: Dan Bagnell Date: Mon, 29 Apr 2013 16:49:13 -0400 Subject: [PATCH 2/4] Move polyline bounding sphere to surface in 2D to prevent incorrect culling by the near plane. --- Source/Scene/PolylineCollection.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Source/Scene/PolylineCollection.js b/Source/Scene/PolylineCollection.js index 5de10276416d..f1fe4f8aefb2 100644 --- a/Source/Scene/PolylineCollection.js +++ b/Source/Scene/PolylineCollection.js @@ -380,6 +380,7 @@ define([ }; var emptyArray = []; + var scracthBoundingSphere = new BoundingSphere(); /** * @private @@ -449,10 +450,13 @@ define([ if (frameState.mode === SceneMode.SCENE3D) { boundingVolume = this._boundingVolume; modelMatrix = this.modelMatrix; - } else if (frameState.mode === SceneMode.COLUMBUS_VIEW || frameState.mode === SceneMode.SCENE2D) { + } else if (frameState.mode === SceneMode.COLUMBUS_VIEW) { boundingVolume = this._boundingVolume2D; - } else { - boundingVolume = this._boundingVolume && this._boundingVolume2D && this._boundingVolume.union(this._boundingVolume2D); + } else if (frameState.mode === SceneMode.SCENE2D) { + boundingVolume = BoundingSphere.clone(this._boundingVolume2D, scracthBoundingSphere); + boundingVolume.center.x = 0.0; + } else if (typeof this._boundingVolume !== 'undefined' && typeof this._boundingVolume2D !== 'undefined') { + boundingVolume = BoundingSphere.union(this._boundingVolume, this._boundingVolume2D, scracthBoundingSphere); } var pass = frameState.passes; From 2e39b84fc9e3b11366ac6a5c02d868df1777f92b Mon Sep 17 00:00:00 2001 From: Dan Bagnell Date: Tue, 30 Apr 2013 14:40:57 -0400 Subject: [PATCH 3/4] Updates based on review. --- Source/Scene/PolylineCollection.js | 4 ++-- Source/Shaders/PolylineVS.glsl | 7 ------- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/Source/Scene/PolylineCollection.js b/Source/Scene/PolylineCollection.js index f1fe4f8aefb2..f23ae497c9a7 100644 --- a/Source/Scene/PolylineCollection.js +++ b/Source/Scene/PolylineCollection.js @@ -1073,7 +1073,7 @@ define([ for ( var i = 0; i < length; ++i) { var polyline = polylines[i]; var width = polyline.getWidth(); - var show = polyline.getShow(); + var show = polyline.getShow() && width > 0.0; var segments = this.getSegments(polyline); var positions = segments.positions; var lengths = segments.lengths; @@ -1397,7 +1397,7 @@ define([ var position; var width = polyline.getWidth(); - var show = polyline.getShow(); + var show = polyline.getShow() && width > 0.0; positionsLength = positions.length; for ( var i = 0; i < positionsLength; ++i) { diff --git a/Source/Shaders/PolylineVS.glsl b/Source/Shaders/PolylineVS.glsl index 13dc01ed5464..76df7668dd73 100644 --- a/Source/Shaders/PolylineVS.glsl +++ b/Source/Shaders/PolylineVS.glsl @@ -58,13 +58,6 @@ void clipLineSegmentToNearPlane( void main() { - // cull if width is less than 1.0 - if (abs(texCoordExpandWidthAndShow.z) < 1.0) - { - gl_Position = czm_projection * vec4(0.0, 0.0, 0.0, 1.0); - return; - } - float texCoord = texCoordExpandWidthAndShow.x; float expandDir = texCoordExpandWidthAndShow.y; float width = abs(texCoordExpandWidthAndShow.z) + 0.5; From b0233d14401fee5419925509441c4bad4c9f7aee Mon Sep 17 00:00:00 2001 From: Dan Bagnell Date: Tue, 30 Apr 2013 15:14:54 -0400 Subject: [PATCH 4/4] Add polyline test for width of 0.0. --- Specs/Scene/PolylineCollectionSpec.js | 29 +++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/Specs/Scene/PolylineCollectionSpec.js b/Specs/Scene/PolylineCollectionSpec.js index 3e8392b452db..4004beaca574 100644 --- a/Specs/Scene/PolylineCollectionSpec.js +++ b/Specs/Scene/PolylineCollectionSpec.js @@ -1503,6 +1503,35 @@ defineSuite([ expect(context.readPixels()).toNotEqual([0, 0, 0, 0]); }); + it('does not render with width 0.0', function() { + var positions = [ + { + x : -1.0, + y : 1.0, + z : 0.0 + },{ + x : -1.0, + y : -1.0, + z : 0.0 + }]; + var line = polylines.add({ + positions : positions + }); + + ClearCommand.ALL.execute(context); + expect(context.readPixels()).toEqual([0, 0, 0, 0]); + + render(context, frameState, polylines); + expect(context.readPixels()).toNotEqual([0, 0, 0, 0]); + + ClearCommand.ALL.execute(context); + expect(context.readPixels()).toEqual([0, 0, 0, 0]); + + line.setWidth(0.0); + render(context, frameState, polylines); + expect(context.readPixels()).toEqual([0, 0, 0, 0]); + }); + it('changes polyline position size recreates vertex arrays', function() { var positions = []; for(var i = 0; i < 20; ++i){