ModelExperimentalVS.glsl 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. // Compute the bitangent according to the formula in the glTF spec.
  26. // Normal and tangents can be affected by morphing and skinning, so
  27. // the bitangent should not be computed until their values are finalized.
  28. #ifdef HAS_BITANGENTS
  29. attributes.bitangentMC = normalize(cross(attributes.normalMC, attributes.tangentMC) * attributes.tangentSignMC);
  30. #endif
  31. FeatureIds featureIds;
  32. featureIdStage(featureIds, attributes);
  33. #ifdef HAS_SELECTED_FEATURE_ID
  34. SelectedFeature feature;
  35. selectedFeatureIdStage(feature, featureIds);
  36. cpuStylingStage(attributes.positionMC, feature);
  37. #endif
  38. mat4 modelView = czm_modelView;
  39. mat3 normal = czm_normal;
  40. // Update the position for this instance in place
  41. #ifdef HAS_INSTANCING
  42. // The legacy instance stage is used when rendering I3DM models that
  43. // encode instances transforms in world space, as opposed to glTF models
  44. // that use EXT_mesh_gpu_instancing, where instance transforms are encoded
  45. // in object space.
  46. #ifdef USE_LEGACY_INSTANCING
  47. mat4 instanceModelView;
  48. mat3 instanceModelViewInverseTranspose;
  49. legacyInstancingStage(attributes.positionMC, instanceModelView, instanceModelViewInverseTranspose);
  50. modelView = instanceModelView;
  51. normal = instanceModelViewInverseTranspose;
  52. #else
  53. instancingStage(attributes.positionMC);
  54. #endif
  55. #ifdef USE_PICKING
  56. v_pickColor = a_pickColor;
  57. #endif
  58. #endif
  59. Metadata metadata;
  60. metadataStage(metadata, attributes);
  61. #ifdef HAS_CUSTOM_VERTEX_SHADER
  62. czm_modelVertexOutput vsOutput = defaultVertexOutput(attributes.positionMC);
  63. customShaderStage(vsOutput, attributes, featureIds, metadata);
  64. #endif
  65. // Compute the final position in each coordinate system needed.
  66. // This also sets gl_Position.
  67. geometryStage(attributes, modelView, normal);
  68. #ifdef PRIMITIVE_TYPE_POINTS
  69. #ifdef HAS_CUSTOM_VERTEX_SHADER
  70. gl_PointSize = vsOutput.pointSize;
  71. #elif defined(USE_POINT_CLOUD_ATTENUATION)
  72. gl_PointSize = pointCloudAttenuationStage(v_positionEC);
  73. #else
  74. gl_PointSize = 1.0;
  75. #endif
  76. #endif
  77. }