|
@@ -169,51 +169,34 @@ ShaderLib[ 'line' ] = {
|
|
|
|
|
|
#ifdef WORLD_UNITS
|
|
#ifdef WORLD_UNITS
|
|
|
|
|
|
- // get the offset direction as perpendicular to the view vector
|
|
|
|
vec3 worldDir = normalize( end.xyz - start.xyz );
|
|
vec3 worldDir = normalize( end.xyz - start.xyz );
|
|
- vec3 offset;
|
|
|
|
- if ( position.y < 0.5 ) {
|
|
|
|
|
|
+ vec3 tmpFwd = normalize( mix( start.xyz, end.xyz, 0.5 ) );
|
|
|
|
+ vec3 worldUp = normalize( cross( worldDir, tmpFwd ) );
|
|
|
|
+ vec3 worldFwd = cross( worldDir, worldUp );
|
|
|
|
+ worldPos = position.y < 0.5 ? start: end;
|
|
|
|
|
|
- offset = normalize( cross( start.xyz, worldDir ) );
|
|
|
|
-
|
|
|
|
- } else {
|
|
|
|
-
|
|
|
|
- offset = normalize( cross( end.xyz, worldDir ) );
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- // sign flip
|
|
|
|
- if ( position.x < 0.0 ) offset *= - 1.0;
|
|
|
|
-
|
|
|
|
- float forwardOffset = dot( worldDir, vec3( 0.0, 0.0, 1.0 ) );
|
|
|
|
|
|
+ // height offset
|
|
|
|
+ float hw = linewidth * 0.5;
|
|
|
|
+ worldPos.xyz += position.x < 0.0 ? hw * worldUp : - hw * worldUp;
|
|
|
|
|
|
// don't extend the line if we're rendering dashes because we
|
|
// don't extend the line if we're rendering dashes because we
|
|
// won't be rendering the endcaps
|
|
// won't be rendering the endcaps
|
|
#ifndef USE_DASH
|
|
#ifndef USE_DASH
|
|
|
|
|
|
- // extend the line bounds to encompass endcaps
|
|
|
|
- start.xyz += - worldDir * linewidth * 0.5;
|
|
|
|
- end.xyz += worldDir * linewidth * 0.5;
|
|
|
|
|
|
+ // cap extension
|
|
|
|
+ worldPos.xyz += position.y < 0.5 ? - hw * worldDir : hw * worldDir;
|
|
|
|
|
|
- // shift the position of the quad so it hugs the forward edge of the line
|
|
|
|
- offset.xy -= dir * forwardOffset;
|
|
|
|
- offset.z += 0.5;
|
|
|
|
|
|
+ // add width to the box
|
|
|
|
+ worldPos.xyz += worldFwd * hw;
|
|
|
|
|
|
- #endif
|
|
|
|
-
|
|
|
|
- // endcaps
|
|
|
|
- if ( position.y > 1.0 || position.y < 0.0 ) {
|
|
|
|
-
|
|
|
|
- offset.xy += dir * 2.0 * forwardOffset;
|
|
|
|
|
|
+ // endcaps
|
|
|
|
+ if ( position.y > 1.0 || position.y < 0.0 ) {
|
|
|
|
|
|
- }
|
|
|
|
|
|
+ worldPos.xyz -= worldFwd * 2.0 * hw;
|
|
|
|
|
|
- // adjust for linewidth
|
|
|
|
- offset *= linewidth * 0.5;
|
|
|
|
|
|
+ }
|
|
|
|
|
|
- // set the world position
|
|
|
|
- worldPos = ( position.y < 0.5 ) ? start : end;
|
|
|
|
- worldPos.xyz += offset;
|
|
|
|
|
|
+ #endif
|
|
|
|
|
|
// project the worldpos
|
|
// project the worldpos
|
|
vec4 clip = projectionMatrix * worldPos;
|
|
vec4 clip = projectionMatrix * worldPos;
|