Skip to content

Commit e7c5c5e

Browse files
committed
Fix line rendering glitches
1 parent 50dd4b1 commit e7c5c5e

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/3d/shaders/lines.geom

+11
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,17 @@ void main( void )
5959
vec3 wp2 = VertexIn[2].worldPosition;
6060
vec3 wp3 = VertexIn[3].worldPosition;
6161

62+
// This implements rejection of lines from Cohen-Sutherland line clipping algorithm.
63+
// Thanks to that we filter out majority of lines that may otherwise cause issues.
64+
// Lines that can't be trivially rejected, should be further clipped - the clipping
65+
// in the next step is a bit half-baked but seems to work relatively well.
66+
vec4 px1 = gl_in[1].gl_Position;
67+
vec4 px2 = gl_in[2].gl_Position;
68+
int px1c = int(px1.w+px1.x<0) << 0 | int(px1.w-px1.x<0) << 1 | int(px1.w+px1.y<0) << 2 | int(px1.w-px1.y<0) << 3 | int(px1.w+px1.z<0) << 4 | int(px1.w-px1.z<0) << 5;
69+
int px2c = int(px2.w+px2.x<0) << 0 | int(px2.w-px2.x<0) << 1 | int(px2.w+px2.y<0) << 2 | int(px2.w-px2.y<0) << 3 | int(px2.w+px2.z<0) << 4 | int(px2.w-px2.z<0) << 5;
70+
if ((px1c & px2c) != 0)
71+
return; // trivial reject
72+
6273
// Perform line clipping first. we search for intersection between the line and the near plane.
6374
// In case the near plane intersects line between segment's endpoints, we need to adjust the line
6475
// otherwise we would use completely non-sense points when points get 'behind' the camera.

0 commit comments

Comments
 (0)