|
18 | 18 |
|
19 | 19 | #define PROCESSING_LINE_SHADER
|
20 | 20 |
|
21 |
| -precision mediump int; |
| 21 | +precision highp int; |
| 22 | +precision highp float; |
22 | 23 |
|
23 | 24 | uniform mat4 uModelViewMatrix;
|
24 | 25 | uniform mat4 uProjectionMatrix;
|
@@ -95,13 +96,33 @@ void main() {
|
95 | 96 |
|
96 | 97 | // Moving vertices slightly toward the camera
|
97 | 98 | // to avoid depth-fighting with the fill triangles.
|
98 |
| - // This prevents popping effects due to half of |
| 99 | + // A mix of scaling and offsetting is used based on distance |
| 100 | + // Discussion here: |
| 101 | + // https://github.com/processing/p5.js/issues/7200 |
| 102 | + |
| 103 | + // using a scale <1 moves the lines towards nearby camera |
| 104 | + // in order to prevent popping effects due to half of |
99 | 105 | // the line disappearing behind the geometry faces.
|
| 106 | + float zDistance = -posp.z; |
| 107 | + float distanceFactor = smoothstep(0.0, 800.0, zDistance); |
100 | 108 |
|
101 |
| - float zOffset = mix(-0.00045, -1., facingCamera); |
102 |
| - posp.z -= zOffset; |
103 |
| - posqIn.z -= zOffset; |
104 |
| - posqOut.z -= zOffset; |
| 109 | + // Discussed here: |
| 110 | + // http://www.opengl.org/discussion_boards/ubbthreads.php?ubb=showflat&Number=252848 |
| 111 | + float scale = mix(1., 0.995, facingCamera); |
| 112 | + float dynamicScale = mix(scale, 1.0, distanceFactor); // Closer = more scale, farther = less |
| 113 | + |
| 114 | + posp.xyz = posp.xyz * dynamicScale; |
| 115 | + posqIn.xyz = posqIn.xyz * dynamicScale; |
| 116 | + posqOut.xyz = posqOut.xyz * dynamicScale; |
| 117 | + |
| 118 | + // Moving vertices slightly toward camera when far away |
| 119 | + // https://github.com/processing/p5.js/issues/6956 |
| 120 | + float zOffset = mix(0., -1., facingCamera); |
| 121 | + float dynamicZAdjustment = mix(0.0, zOffset, distanceFactor); // Closer = less zAdjustment, farther = more |
| 122 | + |
| 123 | + posp.z -= dynamicZAdjustment; |
| 124 | + posqIn.z -= dynamicZAdjustment; |
| 125 | + posqOut.z -= dynamicZAdjustment; |
105 | 126 |
|
106 | 127 | vec4 p = uProjectionMatrix * posp;
|
107 | 128 | vec4 qIn = uProjectionMatrix * posqIn;
|
|
0 commit comments