line.vertex.fx 890 B

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