ModelVS.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. //This file is automatically rebuilt by the Cesium build process.
  2. export default "precision highp float;\n\
  3. \n\
  4. czm_modelVertexOutput defaultVertexOutput(vec3 positionMC) {\n\
  5. czm_modelVertexOutput vsOutput;\n\
  6. vsOutput.positionMC = positionMC;\n\
  7. vsOutput.pointSize = 1.0;\n\
  8. return vsOutput;\n\
  9. }\n\
  10. \n\
  11. void main() \n\
  12. {\n\
  13. // Initialize the attributes struct with all\n\
  14. // attributes except quantized ones.\n\
  15. ProcessedAttributes attributes;\n\
  16. initializeAttributes(attributes);\n\
  17. \n\
  18. // Dequantize the quantized ones and add them to the\n\
  19. // attributes struct.\n\
  20. #ifdef USE_DEQUANTIZATION\n\
  21. dequantizationStage(attributes);\n\
  22. #endif\n\
  23. \n\
  24. #ifdef HAS_MORPH_TARGETS\n\
  25. morphTargetsStage(attributes);\n\
  26. #endif\n\
  27. \n\
  28. #ifdef HAS_SKINNING\n\
  29. skinningStage(attributes);\n\
  30. #endif\n\
  31. \n\
  32. #ifdef HAS_PRIMITIVE_OUTLINE\n\
  33. primitiveOutlineStage();\n\
  34. #endif\n\
  35. \n\
  36. // Compute the bitangent according to the formula in the glTF spec.\n\
  37. // Normal and tangents can be affected by morphing and skinning, so\n\
  38. // the bitangent should not be computed until their values are finalized.\n\
  39. #ifdef HAS_BITANGENTS\n\
  40. attributes.bitangentMC = normalize(cross(attributes.normalMC, attributes.tangentMC) * attributes.tangentSignMC);\n\
  41. #endif\n\
  42. \n\
  43. FeatureIds featureIds;\n\
  44. featureIdStage(featureIds, attributes);\n\
  45. \n\
  46. #ifdef HAS_SELECTED_FEATURE_ID\n\
  47. SelectedFeature feature;\n\
  48. selectedFeatureIdStage(feature, featureIds);\n\
  49. // Handle any show properties that come from the style.\n\
  50. cpuStylingStage(attributes.positionMC, feature);\n\
  51. #endif\n\
  52. \n\
  53. #if defined(USE_2D_POSITIONS) || defined(USE_2D_INSTANCING)\n\
  54. // The scene mode 2D pipeline stage and instancing stage add a different\n\
  55. // model view matrix to accurately project the model to 2D. However, the\n\
  56. // output positions and normals should be transformed by the 3D matrices\n\
  57. // to keep the data the same for the fragment shader.\n\
  58. mat4 modelView = czm_modelView3D;\n\
  59. mat3 normal = czm_normal3D;\n\
  60. #else\n\
  61. // These are used for individual model projection because they will\n\
  62. // automatically change based on the scene mode.\n\
  63. mat4 modelView = czm_modelView;\n\
  64. mat3 normal = czm_normal;\n\
  65. #endif\n\
  66. \n\
  67. // Update the position for this instance in place\n\
  68. #ifdef HAS_INSTANCING\n\
  69. \n\
  70. // The legacy instance stage is used when rendering i3dm models that \n\
  71. // encode instances transforms in world space, as opposed to glTF models\n\
  72. // that use EXT_mesh_gpu_instancing, where instance transforms are encoded\n\
  73. // in object space.\n\
  74. #ifdef USE_LEGACY_INSTANCING\n\
  75. mat4 instanceModelView;\n\
  76. mat3 instanceModelViewInverseTranspose;\n\
  77. \n\
  78. legacyInstancingStage(attributes, instanceModelView, instanceModelViewInverseTranspose);\n\
  79. \n\
  80. modelView = instanceModelView;\n\
  81. normal = instanceModelViewInverseTranspose;\n\
  82. #else\n\
  83. instancingStage(attributes);\n\
  84. #endif\n\
  85. \n\
  86. #ifdef USE_PICKING\n\
  87. v_pickColor = a_pickColor;\n\
  88. #endif\n\
  89. \n\
  90. #endif\n\
  91. \n\
  92. Metadata metadata;\n\
  93. MetadataClass metadataClass;\n\
  94. MetadataStatistics metadataStatistics;\n\
  95. metadataStage(metadata, metadataClass, metadataStatistics, attributes);\n\
  96. \n\
  97. #ifdef HAS_CUSTOM_VERTEX_SHADER\n\
  98. czm_modelVertexOutput vsOutput = defaultVertexOutput(attributes.positionMC);\n\
  99. customShaderStage(vsOutput, attributes, featureIds, metadata, metadataClass, metadataStatistics);\n\
  100. #endif\n\
  101. \n\
  102. // Compute the final position in each coordinate system needed.\n\
  103. // This returns the value that will be assigned to gl_Position.\n\
  104. vec4 positionClip = geometryStage(attributes, modelView, normal); \n\
  105. \n\
  106. #ifdef HAS_SILHOUETTE\n\
  107. silhouetteStage(attributes, positionClip);\n\
  108. #endif\n\
  109. \n\
  110. #ifdef HAS_POINT_CLOUD_SHOW_STYLE\n\
  111. float show = pointCloudShowStylingStage(attributes, metadata);\n\
  112. #else\n\
  113. float show = 1.0;\n\
  114. #endif\n\
  115. \n\
  116. #ifdef HAS_POINT_CLOUD_BACK_FACE_CULLING\n\
  117. show *= pointCloudBackFaceCullingStage();\n\
  118. #endif\n\
  119. \n\
  120. #ifdef HAS_POINT_CLOUD_COLOR_STYLE\n\
  121. v_pointCloudColor = pointCloudColorStylingStage(attributes, metadata);\n\
  122. #endif\n\
  123. \n\
  124. #ifdef PRIMITIVE_TYPE_POINTS\n\
  125. #ifdef HAS_CUSTOM_VERTEX_SHADER\n\
  126. gl_PointSize = vsOutput.pointSize;\n\
  127. #elif defined(HAS_POINT_CLOUD_POINT_SIZE_STYLE) || defined(HAS_POINT_CLOUD_ATTENUATION)\n\
  128. gl_PointSize = pointCloudPointSizeStylingStage(attributes, metadata);\n\
  129. #else\n\
  130. gl_PointSize = 1.0;\n\
  131. #endif\n\
  132. \n\
  133. gl_PointSize *= show;\n\
  134. #endif\n\
  135. \n\
  136. gl_Position = show * positionClip;\n\
  137. }\n\
  138. ";