ModelTypes.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. // Copyright (C) 2009-2021, Panagiotis Christopoulos Charitos and contributors.
  2. // All rights reserved.
  3. // Code licensed under the BSD License.
  4. // http://www.anki3d.org/LICENSE
  5. #pragma once
  6. #include <AnKi/Shaders/Include/Common.h>
  7. ANKI_BEGIN_NAMESPACE
  8. // Vertex attribute locations. Not all are used
  9. #if defined(__cplusplus)
  10. enum class VertexAttributeId : U8
  11. {
  12. POSITION,
  13. UV0,
  14. UV1,
  15. NORMAL,
  16. TANGENT,
  17. COLOR,
  18. BONE_WEIGHTS,
  19. BONE_INDICES,
  20. COUNT,
  21. FIRST = POSITION,
  22. SCALE = UV0, ///< Only for particles.
  23. ALPHA = UV1, ///< Only for particles.
  24. };
  25. ANKI_ENUM_ALLOW_NUMERIC_OPERATIONS(VertexAttributeId)
  26. #else
  27. const U32 VERTEX_ATTRIBUTE_ID_POSITION = 0u;
  28. const U32 VERTEX_ATTRIBUTE_ID_UV0 = 1u;
  29. const U32 VERTEX_ATTRIBUTE_ID_UV1 = 2u;
  30. const U32 VERTEX_ATTRIBUTE_ID_NORMAL = 3u;
  31. const U32 VERTEX_ATTRIBUTE_ID_TANGENT = 4u;
  32. const U32 VERTEX_ATTRIBUTE_ID_COLOR = 5u;
  33. const U32 VERTEX_ATTRIBUTE_ID_BONE_WEIGHTS = 6u;
  34. const U32 VERTEX_ATTRIBUTE_ID_BONE_INDICES = 7u;
  35. const U32 VERTEX_ATTRIBUTE_ID_COUNT = 8u;
  36. const U32 VERTEX_ATTRIBUTE_ID_SCALE = VERTEX_ATTRIBUTE_ID_UV0; ///< Only for particles.
  37. const U32 VERTEX_ATTRIBUTE_ID_ALPHA = VERTEX_ATTRIBUTE_ID_UV1; ///< Only for particles.
  38. #endif
  39. // Vertex buffers
  40. #if defined(__cplusplus)
  41. enum class VertexAttributeBufferId : U8
  42. {
  43. POSITION,
  44. NORMAL_TANGENT_UV0,
  45. BONE,
  46. COUNT
  47. };
  48. ANKI_ENUM_ALLOW_NUMERIC_OPERATIONS(VertexAttributeBufferId)
  49. #else
  50. const U32 VERTEX_ATTRIBUTE_BUFFER_ID_POSITION = 0u;
  51. const U32 VERTEX_ATTRIBUTE_BUFFER_ID_NORMAL_TANGENT_UV0 = 1u;
  52. const U32 VERTEX_ATTRIBUTE_BUFFER_ID_BONE = 2u;
  53. const U32 VERTEX_ATTRIBUTE_BUFFER_ID_COUNT = 3u;
  54. #endif
  55. /// The main vertex that contains normals, tangents and UVs.
  56. struct MainVertex
  57. {
  58. U32 m_normal; ///< Packed in a custom R11G11B10_SNorm
  59. U32 m_tangent; ///< Packed in a custom R10G10B11A1_SNorm format
  60. Vec2 m_uv0;
  61. };
  62. const U32 _ANKI_SIZEOF_MainVertex = 4u * 4u;
  63. const U32 _ANKI_ALIGNOF_MainVertex = 4u;
  64. ANKI_SHADER_STATIC_ASSERT(_ANKI_SIZEOF_MainVertex == sizeof(MainVertex));
  65. /// The vertex that contains the bone influences.
  66. struct BoneInfoVertex
  67. {
  68. U8Vec4 m_boneIndices;
  69. U8Vec4 m_boneWeights;
  70. };
  71. const U32 _ANKI_SIZEOF_BoneInfoVertex = 8u;
  72. const U32 _ANKI_ALIGNOF_BoneInfoVertex = 1u;
  73. ANKI_SHADER_STATIC_ASSERT(_ANKI_SIZEOF_BoneInfoVertex == sizeof(BoneInfoVertex));
  74. /// A structure that contains all the info of a geometry.
  75. struct MeshGpuDescriptor
  76. {
  77. Address m_indexBufferPtr; ///< Points to a buffer of U16 indices.
  78. #if defined(__cplusplus)
  79. Array<Address, U(VertexAttributeBufferId::COUNT)> m_vertexBufferPtrs;
  80. #else
  81. Address m_vertexBufferPtrs[VERTEX_ATTRIBUTE_BUFFER_ID_COUNT];
  82. #endif
  83. U32 m_indexCount;
  84. U32 m_vertexCount;
  85. Vec3 m_aabbMin;
  86. Vec3 m_aabbMax;
  87. };
  88. const U32 _ANKI_SIZEOF_MeshGpuDescriptor = 4u * ANKI_SIZEOF(UVec2) + 8u * ANKI_SIZEOF(F32);
  89. const U32 _ANKI_ALIGNOF_MeshGpuDescriptor = 8u;
  90. ANKI_SHADER_STATIC_ASSERT(_ANKI_SIZEOF_MeshGpuDescriptor == sizeof(MeshGpuDescriptor));
  91. #if defined(__cplusplus)
  92. enum class TextureChannelId : U8
  93. {
  94. DIFFUSE,
  95. NORMAL,
  96. ROUGHNESS_METALNESS,
  97. EMISSION,
  98. HEIGHT,
  99. AUX_0,
  100. AUX_1,
  101. AUX_2,
  102. COUNT
  103. };
  104. ANKI_ENUM_ALLOW_NUMERIC_OPERATIONS(TextureChannelId)
  105. #else
  106. const U32 TEXTURE_CHANNEL_ID_DIFFUSE = 0u;
  107. const U32 TEXTURE_CHANNEL_ID_NORMAL = 1u;
  108. const U32 TEXTURE_CHANNEL_ID_ROUGHNESS_METALNESS = 2u;
  109. const U32 TEXTURE_CHANNEL_ID_EMISSION = 3u;
  110. const U32 TEXTURE_CHANNEL_ID_HEIGHT = 4u;
  111. const U32 TEXTURE_CHANNEL_ID_AUX_0 = 5u;
  112. const U32 TEXTURE_CHANNEL_ID_AUX_1 = 6u;
  113. const U32 TEXTURE_CHANNEL_ID_AUX_2 = 7u;
  114. const U32 TEXTURE_CHANNEL_ID_COUNT = 8u;
  115. #endif
  116. struct MaterialGpuDescriptor
  117. {
  118. #if defined(__cplusplus)
  119. Array<U16, U(TextureChannelId::COUNT)> m_bindlessTextureIndices;
  120. #else
  121. U16 m_bindlessTextureIndices[TEXTURE_CHANNEL_ID_COUNT];
  122. #endif
  123. Vec3 m_diffuseColor;
  124. Vec3 m_specularColor;
  125. Vec3 m_emissiveColor;
  126. F32 m_roughness;
  127. F32 m_metalness;
  128. };
  129. const U32 _ANKI_SIZEOF_MaterialGpuDescriptor = 8u * ANKI_SIZEOF(U16) + 3u * ANKI_SIZEOF(Vec3) + 2u * ANKI_SIZEOF(F32);
  130. const U32 _ANKI_ALIGNOF_MaterialGpuDescriptor = 4u;
  131. ANKI_SHADER_STATIC_ASSERT(_ANKI_SIZEOF_MaterialGpuDescriptor == sizeof(MaterialGpuDescriptor));
  132. struct ModelGpuDescriptor
  133. {
  134. MeshGpuDescriptor m_mesh;
  135. MaterialGpuDescriptor m_material;
  136. #if defined(__cplusplus)
  137. F32 m_worldTransform[12];
  138. #else
  139. Mat3x4 m_worldTransform;
  140. #endif
  141. Mat3 m_worldRotation;
  142. };
  143. ANKI_END_NAMESPACE