ShadowVolumeAppearanceVS.glsl 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. in vec3 position3DHigh;
  2. in vec3 position3DLow;
  3. in float batchId;
  4. #ifdef EXTRUDED_GEOMETRY
  5. in vec3 extrudeDirection;
  6. uniform float u_globeMinimumAltitude;
  7. #endif // EXTRUDED_GEOMETRY
  8. #ifdef PER_INSTANCE_COLOR
  9. out vec4 v_color;
  10. #endif // PER_INSTANCE_COLOR
  11. #ifdef TEXTURE_COORDINATES
  12. #ifdef SPHERICAL
  13. out vec4 v_sphericalExtents;
  14. #else // SPHERICAL
  15. out vec2 v_inversePlaneExtents;
  16. out vec4 v_westPlane;
  17. out vec4 v_southPlane;
  18. #endif // SPHERICAL
  19. out vec3 v_uvMinAndSphericalLongitudeRotation;
  20. out vec3 v_uMaxAndInverseDistance;
  21. out vec3 v_vMaxAndInverseDistance;
  22. #endif // TEXTURE_COORDINATES
  23. void main()
  24. {
  25. vec4 position = czm_computePosition();
  26. #ifdef EXTRUDED_GEOMETRY
  27. float delta = min(u_globeMinimumAltitude, czm_geometricToleranceOverMeter * length(position.xyz));
  28. delta *= czm_sceneMode == czm_sceneMode3D ? 1.0 : 0.0;
  29. //extrudeDirection is zero for the top layer
  30. position = position + vec4(extrudeDirection * delta, 0.0);
  31. #endif
  32. #ifdef TEXTURE_COORDINATES
  33. #ifdef SPHERICAL
  34. v_sphericalExtents = czm_batchTable_sphericalExtents(batchId);
  35. v_uvMinAndSphericalLongitudeRotation.z = czm_batchTable_longitudeRotation(batchId);
  36. #else // SPHERICAL
  37. #ifdef COLUMBUS_VIEW_2D
  38. vec4 planes2D_high = czm_batchTable_planes2D_HIGH(batchId);
  39. vec4 planes2D_low = czm_batchTable_planes2D_LOW(batchId);
  40. // If the primitive is split across the IDL (planes2D_high.x > planes2D_high.w):
  41. // - If this vertex is on the east side of the IDL (position3DLow.y > 0.0, comparison with position3DHigh may produce artifacts)
  42. // - existing "east" is on the wrong side of the world, far away (planes2D_high/low.w)
  43. // - so set "east" as beyond the eastmost extent of the projection (idlSplitNewPlaneHiLow)
  44. vec2 idlSplitNewPlaneHiLow = vec2(EAST_MOST_X_HIGH - (WEST_MOST_X_HIGH - planes2D_high.w), EAST_MOST_X_LOW - (WEST_MOST_X_LOW - planes2D_low.w));
  45. bool idlSplit = planes2D_high.x > planes2D_high.w && position3DLow.y > 0.0;
  46. planes2D_high.w = czm_branchFreeTernary(idlSplit, idlSplitNewPlaneHiLow.x, planes2D_high.w);
  47. planes2D_low.w = czm_branchFreeTernary(idlSplit, idlSplitNewPlaneHiLow.y, planes2D_low.w);
  48. // - else, if this vertex is on the west side of the IDL (position3DLow.y < 0.0)
  49. // - existing "west" is on the wrong side of the world, far away (planes2D_high/low.x)
  50. // - so set "west" as beyond the westmost extent of the projection (idlSplitNewPlaneHiLow)
  51. idlSplit = planes2D_high.x > planes2D_high.w && position3DLow.y < 0.0;
  52. idlSplitNewPlaneHiLow = vec2(WEST_MOST_X_HIGH - (EAST_MOST_X_HIGH - planes2D_high.x), WEST_MOST_X_LOW - (EAST_MOST_X_LOW - planes2D_low.x));
  53. planes2D_high.x = czm_branchFreeTernary(idlSplit, idlSplitNewPlaneHiLow.x, planes2D_high.x);
  54. planes2D_low.x = czm_branchFreeTernary(idlSplit, idlSplitNewPlaneHiLow.y, planes2D_low.x);
  55. vec3 southWestCorner = (czm_modelViewRelativeToEye * czm_translateRelativeToEye(vec3(0.0, planes2D_high.xy), vec3(0.0, planes2D_low.xy))).xyz;
  56. vec3 northWestCorner = (czm_modelViewRelativeToEye * czm_translateRelativeToEye(vec3(0.0, planes2D_high.x, planes2D_high.z), vec3(0.0, planes2D_low.x, planes2D_low.z))).xyz;
  57. vec3 southEastCorner = (czm_modelViewRelativeToEye * czm_translateRelativeToEye(vec3(0.0, planes2D_high.w, planes2D_high.y), vec3(0.0, planes2D_low.w, planes2D_low.y))).xyz;
  58. #else // COLUMBUS_VIEW_2D
  59. // 3D case has smaller "plane extents," so planes encoded as a 64 bit position and 2 vec3s for distances/direction
  60. vec3 southWestCorner = (czm_modelViewRelativeToEye * czm_translateRelativeToEye(czm_batchTable_southWest_HIGH(batchId), czm_batchTable_southWest_LOW(batchId))).xyz;
  61. vec3 northWestCorner = czm_normal * czm_batchTable_northward(batchId) + southWestCorner;
  62. vec3 southEastCorner = czm_normal * czm_batchTable_eastward(batchId) + southWestCorner;
  63. #endif // COLUMBUS_VIEW_2D
  64. vec3 eastWard = southEastCorner - southWestCorner;
  65. float eastExtent = length(eastWard);
  66. eastWard /= eastExtent;
  67. vec3 northWard = northWestCorner - southWestCorner;
  68. float northExtent = length(northWard);
  69. northWard /= northExtent;
  70. v_westPlane = vec4(eastWard, -dot(eastWard, southWestCorner));
  71. v_southPlane = vec4(northWard, -dot(northWard, southWestCorner));
  72. v_inversePlaneExtents = vec2(1.0 / eastExtent, 1.0 / northExtent);
  73. #endif // SPHERICAL
  74. vec4 uvMinAndExtents = czm_batchTable_uvMinAndExtents(batchId);
  75. vec4 uMaxVmax = czm_batchTable_uMaxVmax(batchId);
  76. v_uMaxAndInverseDistance = vec3(uMaxVmax.xy, uvMinAndExtents.z);
  77. v_vMaxAndInverseDistance = vec3(uMaxVmax.zw, uvMinAndExtents.w);
  78. v_uvMinAndSphericalLongitudeRotation.xy = uvMinAndExtents.xy;
  79. #endif // TEXTURE_COORDINATES
  80. #ifdef PER_INSTANCE_COLOR
  81. v_color = czm_batchTable_color(batchId);
  82. #endif
  83. gl_Position = czm_depthClamp(czm_modelViewProjectionRelativeToEye * position);
  84. }