Skip to content

Instantly share code, notes, and snippets.

@mattdesl
Last active August 11, 2020 06:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattdesl/d573f4797423a4fff9f15947d9db95e8 to your computer and use it in GitHub Desktop.
Save mattdesl/d573f4797423a4fff9f15947d9db95e8 to your computer and use it in GitHub Desktop.
vec3 point3D = mix(pointA.xyz, pointB.xyz, position.z);
vec4 eyePos = modelViewMatrix * vec4(point3D, 1.0);
float spriteWidth = uniformRadius * vertexRadius * (2.0 / 3.0);
vec4 projCorner = projectionMatrix * vec4(
0.5 * spriteWidth, 0.5 * spriteWidth, eyePos.z, eyePos.w
);
float computedRadius = projCorner.x / projCorner.w * screenWidth;
@mattdesl
Copy link
Author

Fixed version below from @wwwtyro's example

        float cr = uniformRadius * vertexRadius * 2.0 * screenWidth / aspect;
        float wz0 = abs(cr / (modelViewMatrix * vec4(pointA.xyz, 1.0)).z);
        float wz1 = abs(cr / (modelViewMatrix * vec4(pointB.xyz, 1.0)).z);

        vec2 pt0 = screen0 + wz0 * (position.x * xBasis + position.y * yBasis);
        vec2 pt1 = screen1 + wz1 * (position.x * xBasis + position.y * yBasis);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment