@@ -169,51 +169,34 @@ ShaderLib[ 'line' ] = {
169
169
170
170
#ifdef WORLD_UNITS
171
171
172
- // get the offset direction as perpendicular to the view vector
173
172
vec3 worldDir = normalize( end.xyz - start.xyz );
174
- vec3 offset;
175
- if ( position.y < 0.5 ) {
173
+ vec3 tmpFwd = normalize( mix( start.xyz, end.xyz, 0.5 ) );
174
+ vec3 worldUp = normalize( cross( worldDir, tmpFwd ) );
175
+ vec3 worldFwd = cross( worldDir, worldUp );
176
+ worldPos = position.y < 0.5 ? start: end;
176
177
177
- offset = normalize( cross( start.xyz, worldDir ) );
178
-
179
- } else {
180
-
181
- offset = normalize( cross( end.xyz, worldDir ) );
182
-
183
- }
184
-
185
- // sign flip
186
- if ( position.x < 0.0 ) offset *= - 1.0;
187
-
188
- float forwardOffset = dot( worldDir, vec3( 0.0, 0.0, 1.0 ) );
178
+ // height offset
179
+ float hw = linewidth * 0.5;
180
+ worldPos.xyz += position.x < 0.0 ? hw * worldUp : - hw * worldUp;
189
181
190
182
// don't extend the line if we're rendering dashes because we
191
183
// won't be rendering the endcaps
192
184
#ifndef USE_DASH
193
185
194
- // extend the line bounds to encompass endcaps
195
- start.xyz += - worldDir * linewidth * 0.5;
196
- end.xyz += worldDir * linewidth * 0.5;
186
+ // cap extension
187
+ worldPos.xyz += position.y < 0.5 ? - hw * worldDir : hw * worldDir;
197
188
198
- // shift the position of the quad so it hugs the forward edge of the line
199
- offset.xy -= dir * forwardOffset;
200
- offset.z += 0.5;
189
+ // add width to the box
190
+ worldPos.xyz += worldFwd * hw;
201
191
202
- #endif
203
-
204
- // endcaps
205
- if ( position.y > 1.0 || position.y < 0.0 ) {
206
-
207
- offset.xy += dir * 2.0 * forwardOffset;
192
+ // endcaps
193
+ if ( position.y > 1.0 || position.y < 0.0 ) {
208
194
209
- }
195
+ worldPos.xyz -= worldFwd * 2.0 * hw;
210
196
211
- // adjust for linewidth
212
- offset *= linewidth * 0.5;
197
+ }
213
198
214
- // set the world position
215
- worldPos = ( position.y < 0.5 ) ? start : end;
216
- worldPos.xyz += offset;
199
+ #endif
217
200
218
201
// project the worldpos
219
202
vec4 clip = projectionMatrix * worldPos;
0 commit comments