Vector3DTileClampedPolylinesVS.glsl 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. attribute vec3 startEllipsoidNormal;
  2. attribute vec3 endEllipsoidNormal;
  3. attribute vec4 startPositionAndHeight;
  4. attribute vec4 endPositionAndHeight;
  5. attribute vec4 startFaceNormalAndVertexCorner;
  6. attribute vec4 endFaceNormalAndHalfWidth;
  7. attribute float a_batchId;
  8. uniform mat4 u_modifiedModelView;
  9. uniform vec2 u_minimumMaximumVectorHeights;
  10. varying vec4 v_startPlaneEC;
  11. varying vec4 v_endPlaneEC;
  12. varying vec4 v_rightPlaneEC;
  13. varying float v_halfWidth;
  14. varying vec3 v_volumeUpEC;
  15. void main()
  16. {
  17. // vertex corner IDs
  18. // 3-----------7
  19. // /| left /|
  20. // / | 1 / |
  21. // 2-----------6 5 end
  22. // | / | /
  23. // start |/ right |/
  24. // 0-----------4
  25. //
  26. float isEnd = floor(startFaceNormalAndVertexCorner.w * 0.251); // 0 for front, 1 for end
  27. float isTop = floor(startFaceNormalAndVertexCorner.w * mix(0.51, 0.19, isEnd)); // 0 for bottom, 1 for top
  28. vec3 forward = endPositionAndHeight.xyz - startPositionAndHeight.xyz;
  29. vec3 right = normalize(cross(forward, startEllipsoidNormal));
  30. vec4 position = vec4(startPositionAndHeight.xyz, 1.0);
  31. position.xyz += forward * isEnd;
  32. v_volumeUpEC = czm_normal * normalize(cross(right, forward));
  33. // Push for volume height
  34. float offset;
  35. vec3 ellipsoidNormal = mix(startEllipsoidNormal, endEllipsoidNormal, isEnd);
  36. // offset height to create volume
  37. offset = mix(startPositionAndHeight.w, endPositionAndHeight.w, isEnd);
  38. offset = mix(u_minimumMaximumVectorHeights.y, u_minimumMaximumVectorHeights.x, isTop) - offset;
  39. position.xyz += offset * ellipsoidNormal;
  40. // move from RTC to EC
  41. position = u_modifiedModelView * position;
  42. right = czm_normal * right;
  43. // Push for width in a direction that is in the start or end plane and in a plane with right
  44. // N = normalEC ("right-facing" direction for push)
  45. // R = right
  46. // p = angle between N and R
  47. // w = distance to push along R if R == N
  48. // d = distance to push along N
  49. //
  50. // N R
  51. // { \ p| } * cos(p) = dot(N, R) = w / d
  52. // d\ \ | |w * d = w / dot(N, R)
  53. // { \| }
  54. // o---------- polyline segment ---->
  55. //
  56. vec3 scratchNormal = mix(-startFaceNormalAndVertexCorner.xyz, endFaceNormalAndHalfWidth.xyz, isEnd);
  57. scratchNormal = cross(scratchNormal, mix(startEllipsoidNormal, endEllipsoidNormal, isEnd));
  58. vec3 miterPushNormal = czm_normal * normalize(scratchNormal);
  59. offset = 2.0 * endFaceNormalAndHalfWidth.w * max(0.0, czm_metersPerPixel(position)); // offset = widthEC
  60. offset = offset / dot(miterPushNormal, right);
  61. position.xyz += miterPushNormal * (offset * sign(0.5 - mod(startFaceNormalAndVertexCorner.w, 2.0)));
  62. gl_Position = czm_depthClamp(czm_projection * position);
  63. position = u_modifiedModelView * vec4(startPositionAndHeight.xyz, 1.0);
  64. vec3 startNormalEC = czm_normal * startFaceNormalAndVertexCorner.xyz;
  65. v_startPlaneEC = vec4(startNormalEC, -dot(startNormalEC, position.xyz));
  66. v_rightPlaneEC = vec4(right, -dot(right, position.xyz));
  67. position = u_modifiedModelView * vec4(endPositionAndHeight.xyz, 1.0);
  68. vec3 endNormalEC = czm_normal * endFaceNormalAndHalfWidth.xyz;
  69. v_endPlaneEC = vec4(endNormalEC, -dot(endNormalEC, position.xyz));
  70. v_halfWidth = endFaceNormalAndHalfWidth.w;
  71. }