ModelVS.glsl 4.3 KB

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