PolylineShadowVolumeMorphVS.js 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. //This file is automatically rebuilt by the Cesium build process.
  2. export default "attribute vec3 position3DHigh;\n\
  3. attribute vec3 position3DLow;\n\
  4. attribute vec4 startHiAndForwardOffsetX;\n\
  5. attribute vec4 startLoAndForwardOffsetY;\n\
  6. attribute vec4 startNormalAndForwardOffsetZ;\n\
  7. attribute vec4 endNormalAndTextureCoordinateNormalizationX;\n\
  8. attribute vec4 rightNormalAndTextureCoordinateNormalizationY;\n\
  9. attribute vec4 startHiLo2D;\n\
  10. attribute vec4 offsetAndRight2D;\n\
  11. attribute vec4 startEndNormals2D;\n\
  12. attribute vec2 texcoordNormalization2D;\n\
  13. attribute float batchId;\n\
  14. varying vec3 v_forwardDirectionEC;\n\
  15. varying vec3 v_texcoordNormalizationAndHalfWidth;\n\
  16. varying float v_batchId;\n\
  17. #ifdef WIDTH_VARYING\n\
  18. varying float v_width;\n\
  19. #endif\n\
  20. #ifdef ANGLE_VARYING\n\
  21. varying float v_polylineAngle;\n\
  22. #endif\n\
  23. #ifdef PER_INSTANCE_COLOR\n\
  24. varying vec4 v_color;\n\
  25. #else\n\
  26. varying vec2 v_alignedPlaneDistances;\n\
  27. varying float v_texcoordT;\n\
  28. #endif\n\
  29. void main()\n\
  30. {\n\
  31. v_batchId = batchId;\n\
  32. vec4 posRelativeToEye2D = czm_translateRelativeToEye(vec3(0.0, startHiLo2D.xy), vec3(0.0, startHiLo2D.zw));\n\
  33. vec4 posRelativeToEye3D = czm_translateRelativeToEye(startHiAndForwardOffsetX.xyz, startLoAndForwardOffsetY.xyz);\n\
  34. vec4 posRelativeToEye = czm_columbusViewMorph(posRelativeToEye2D, posRelativeToEye3D, czm_morphTime);\n\
  35. vec3 posEc2D = (czm_modelViewRelativeToEye * posRelativeToEye2D).xyz;\n\
  36. vec3 posEc3D = (czm_modelViewRelativeToEye * posRelativeToEye3D).xyz;\n\
  37. vec3 startEC = (czm_modelViewRelativeToEye * posRelativeToEye).xyz;\n\
  38. vec4 startPlane2D;\n\
  39. vec4 startPlane3D;\n\
  40. startPlane2D.xyz = czm_normal * vec3(0.0, startEndNormals2D.xy);\n\
  41. startPlane3D.xyz = czm_normal * startNormalAndForwardOffsetZ.xyz;\n\
  42. startPlane2D.w = -dot(startPlane2D.xyz, posEc2D);\n\
  43. startPlane3D.w = -dot(startPlane3D.xyz, posEc3D);\n\
  44. vec4 rightPlane2D;\n\
  45. vec4 rightPlane3D;\n\
  46. rightPlane2D.xyz = czm_normal * vec3(0.0, offsetAndRight2D.zw);\n\
  47. rightPlane3D.xyz = czm_normal * rightNormalAndTextureCoordinateNormalizationY.xyz;\n\
  48. rightPlane2D.w = -dot(rightPlane2D.xyz, posEc2D);\n\
  49. rightPlane3D.w = -dot(rightPlane3D.xyz, posEc3D);\n\
  50. posRelativeToEye2D = posRelativeToEye2D + vec4(0.0, offsetAndRight2D.xy, 0.0);\n\
  51. posRelativeToEye3D = posRelativeToEye3D + vec4(startHiAndForwardOffsetX.w, startLoAndForwardOffsetY.w, startNormalAndForwardOffsetZ.w, 0.0);\n\
  52. posRelativeToEye = czm_columbusViewMorph(posRelativeToEye2D, posRelativeToEye3D, czm_morphTime);\n\
  53. posEc2D = (czm_modelViewRelativeToEye * posRelativeToEye2D).xyz;\n\
  54. posEc3D = (czm_modelViewRelativeToEye * posRelativeToEye3D).xyz;\n\
  55. vec3 endEC = (czm_modelViewRelativeToEye * posRelativeToEye).xyz;\n\
  56. vec3 forwardEc3D = czm_normal * normalize(vec3(startHiAndForwardOffsetX.w, startLoAndForwardOffsetY.w, startNormalAndForwardOffsetZ.w));\n\
  57. vec3 forwardEc2D = czm_normal * normalize(vec3(0.0, offsetAndRight2D.xy));\n\
  58. vec4 endPlane2D;\n\
  59. vec4 endPlane3D;\n\
  60. endPlane2D.xyz = czm_normal * vec3(0.0, startEndNormals2D.zw);\n\
  61. endPlane3D.xyz = czm_normal * endNormalAndTextureCoordinateNormalizationX.xyz;\n\
  62. endPlane2D.w = -dot(endPlane2D.xyz, posEc2D);\n\
  63. endPlane3D.w = -dot(endPlane3D.xyz, posEc3D);\n\
  64. v_forwardDirectionEC = normalize(endEC - startEC);\n\
  65. vec2 cleanTexcoordNormalization2D;\n\
  66. cleanTexcoordNormalization2D.x = abs(texcoordNormalization2D.x);\n\
  67. cleanTexcoordNormalization2D.y = czm_branchFreeTernary(texcoordNormalization2D.y > 1.0, 0.0, abs(texcoordNormalization2D.y));\n\
  68. vec2 cleanTexcoordNormalization3D;\n\
  69. cleanTexcoordNormalization3D.x = abs(endNormalAndTextureCoordinateNormalizationX.w);\n\
  70. cleanTexcoordNormalization3D.y = rightNormalAndTextureCoordinateNormalizationY.w;\n\
  71. cleanTexcoordNormalization3D.y = czm_branchFreeTernary(cleanTexcoordNormalization3D.y > 1.0, 0.0, abs(cleanTexcoordNormalization3D.y));\n\
  72. v_texcoordNormalizationAndHalfWidth.xy = mix(cleanTexcoordNormalization2D, cleanTexcoordNormalization3D, czm_morphTime);\n\
  73. #ifdef PER_INSTANCE_COLOR\n\
  74. v_color = czm_batchTable_color(batchId);\n\
  75. #else // PER_INSTANCE_COLOR\n\
  76. v_alignedPlaneDistances.x = -dot(v_forwardDirectionEC, startEC);\n\
  77. v_alignedPlaneDistances.y = -dot(-v_forwardDirectionEC, endEC);\n\
  78. #endif // PER_INSTANCE_COLOR\n\
  79. #ifdef WIDTH_VARYING\n\
  80. float width = czm_batchTable_width(batchId);\n\
  81. float halfWidth = width * 0.5;\n\
  82. v_width = width;\n\
  83. v_texcoordNormalizationAndHalfWidth.z = halfWidth;\n\
  84. #else\n\
  85. float halfWidth = 0.5 * czm_batchTable_width(batchId);\n\
  86. v_texcoordNormalizationAndHalfWidth.z = halfWidth;\n\
  87. #endif\n\
  88. vec4 positionEc3D = czm_modelViewRelativeToEye * czm_translateRelativeToEye(position3DHigh, position3DLow);\n\
  89. float absStartPlaneDistance = abs(czm_planeDistance(startPlane3D, positionEc3D.xyz));\n\
  90. float absEndPlaneDistance = abs(czm_planeDistance(endPlane3D, positionEc3D.xyz));\n\
  91. vec3 planeDirection = czm_branchFreeTernary(absStartPlaneDistance < absEndPlaneDistance, startPlane3D.xyz, endPlane3D.xyz);\n\
  92. vec3 upOrDown = normalize(cross(rightPlane3D.xyz, planeDirection));\n\
  93. vec3 normalEC = normalize(cross(planeDirection, upOrDown));\n\
  94. vec3 geodeticSurfaceNormal = normalize(cross(normalEC, forwardEc3D));\n\
  95. geodeticSurfaceNormal *= float(0.0 <= rightNormalAndTextureCoordinateNormalizationY.w && rightNormalAndTextureCoordinateNormalizationY.w <= 1.0);\n\
  96. geodeticSurfaceNormal *= MAX_TERRAIN_HEIGHT;\n\
  97. positionEc3D.xyz += geodeticSurfaceNormal;\n\
  98. normalEC *= sign(endNormalAndTextureCoordinateNormalizationX.w);\n\
  99. positionEc3D.xyz += halfWidth * max(0.0, czm_metersPerPixel(positionEc3D)) * normalEC;\n\
  100. vec4 positionEc2D = czm_modelViewRelativeToEye * czm_translateRelativeToEye(position2DHigh.zxy, position2DLow.zxy);\n\
  101. absStartPlaneDistance = abs(czm_planeDistance(startPlane2D, positionEc2D.xyz));\n\
  102. absEndPlaneDistance = abs(czm_planeDistance(endPlane2D, positionEc2D.xyz));\n\
  103. planeDirection = czm_branchFreeTernary(absStartPlaneDistance < absEndPlaneDistance, startPlane2D.xyz, endPlane2D.xyz);\n\
  104. upOrDown = normalize(cross(rightPlane2D.xyz, planeDirection));\n\
  105. normalEC = normalize(cross(planeDirection, upOrDown));\n\
  106. geodeticSurfaceNormal = normalize(cross(normalEC, forwardEc2D));\n\
  107. geodeticSurfaceNormal *= float(0.0 <= texcoordNormalization2D.y && texcoordNormalization2D.y <= 1.0);\n\
  108. geodeticSurfaceNormal *= MAX_TERRAIN_HEIGHT;\n\
  109. positionEc2D.xyz += geodeticSurfaceNormal;\n\
  110. normalEC *= sign(texcoordNormalization2D.x);\n\
  111. #ifndef PER_INSTANCE_COLOR\n\
  112. v_texcoordT = clamp(sign(texcoordNormalization2D.x), 0.0, 1.0);\n\
  113. #endif\n\
  114. positionEc2D.xyz += halfWidth * max(0.0, czm_metersPerPixel(positionEc2D)) * normalEC;\n\
  115. gl_Position = czm_projection * mix(positionEc2D, positionEc3D, czm_morphTime);\n\
  116. #ifdef ANGLE_VARYING\n\
  117. vec2 approxLineDirection = normalize(vec2(v_forwardDirectionEC.x, -v_forwardDirectionEC.y));\n\
  118. approxLineDirection.y = czm_branchFreeTernary(approxLineDirection.x == 0.0 && approxLineDirection.y == 0.0, -1.0, approxLineDirection.y);\n\
  119. v_polylineAngle = czm_fastApproximateAtan(approxLineDirection.x, approxLineDirection.y);\n\
  120. #endif\n\
  121. }\n\
  122. ";