Skip to content

Commit e624307

Browse files
authored
Merge pull request #7206 from TiborUdvari/fix/line.vert-v1.10.0
Line.vert fix for small units
2 parents 7e20954 + 9a81d77 commit e624307

File tree

1 file changed

+24
-4
lines changed

1 file changed

+24
-4
lines changed

src/webgl/shaders/line.vert

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,33 @@ void main() {
9595

9696
// Moving vertices slightly toward the camera
9797
// to avoid depth-fighting with the fill triangles.
98-
// This prevents popping effects due to half of
98+
// A mix of scaling and offsetting is used based on distance
99+
// Discussion here:
100+
// https://github.com/processing/p5.js/issues/7200
101+
102+
// using a scale <1 moves the lines towards nearby camera
103+
// in order to prevent popping effects due to half of
99104
// the line disappearing behind the geometry faces.
105+
float zDistance = -posp.z;
106+
float distanceFactor = smoothstep(0.0, 800.0, zDistance);
100107

108+
// Discussed here:
109+
// http://www.opengl.org/discussion_boards/ubbthreads.php?ubb=showflat&Number=252848
110+
float scale = mix(1., 0.995, facingCamera);
111+
float dynamicScale = mix(scale, 1.0, distanceFactor); // Closer = more scale, farther = less
112+
113+
posp.xyz = posp.xyz * dynamicScale;
114+
posqIn.xyz = posqIn.xyz * dynamicScale;
115+
posqOut.xyz = posqOut.xyz * dynamicScale;
116+
117+
// Moving vertices slightly toward camera when far away
118+
// https://github.com/processing/p5.js/issues/6956
101119
float zOffset = mix(-0.00045, -1., facingCamera);
102-
posp.z -= zOffset;
103-
posqIn.z -= zOffset;
104-
posqOut.z -= zOffset;
120+
float dynamicZAdjustment = mix(0.0, zOffset, distanceFactor); // Closer = less zAdjustment, farther = more
121+
122+
posp.z -= dynamicZAdjustment;
123+
posqIn.z -= dynamicZAdjustment;
124+
posqOut.z -= dynamicZAdjustment;
105125

106126
vec4 p = uProjectionMatrix * posp;
107127
vec4 qIn = uProjectionMatrix * posqIn;

0 commit comments

Comments
 (0)