File tree 1 file changed +11
-0
lines changed
1 file changed +11
-0
lines changed Original file line number Diff line number Diff line change @@ -59,6 +59,17 @@ void main( void )
59
59
vec3 wp2 = VertexIn[2 ].worldPosition;
60
60
vec3 wp3 = VertexIn[3 ].worldPosition;
61
61
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
+
62
73
// Perform line clipping first. we search for intersection between the line and the near plane.
63
74
// In case the near plane intersects line between segment's endpoints, we need to adjust the line
64
75
// otherwise we would use completely non-sense points when points get 'behind' the camera.
You can’t perform that action at this time.
0 commit comments