line.vertex.fx 765 B

1234567891011121314151617181920212223242526272829
  1. // Attributes
  2. attribute vec3 position;
  3. attribute vec4 normal;
  4. // Uniforms
  5. uniform mat4 worldViewProjection;
  6. uniform float width;
  7. uniform float aspectRatio;
  8. void main(void) {
  9. vec4 viewPosition = worldViewProjection * vec4(position, 1.0);
  10. vec4 viewPositionNext = worldViewProjection * vec4(normal.xyz, 1.0);
  11. vec2 currentScreen = viewPosition.xy / viewPosition.w;
  12. vec2 nextScreen = viewPositionNext.xy / viewPositionNext.w;
  13. currentScreen.x *= aspectRatio;
  14. nextScreen.x *= aspectRatio;
  15. vec2 dir = normalize(nextScreen - currentScreen);
  16. vec2 normalDir = vec2(-dir.y, dir.x);
  17. normalDir *= width / 2.0;
  18. normalDir.x /= aspectRatio;
  19. vec4 offset = vec4(normalDir * normal.w, 0.0, 0.0);
  20. gl_Position = viewPosition + offset;
  21. }