From 2aac984fa3e2459fcca18d5b8f88e648170ee694 Mon Sep 17 00:00:00 2001 From: Steve M Date: Fri, 24 Jan 2025 12:08:29 -0800 Subject: [PATCH] Add gltf metallic-roughness texture type (#5968) * Introduce gltf metallic-roughness texture type * Add to unit test, add doc citation --------- Co-authored-by: Steve M --- include/assimp/GltfMaterial.h | 2 +- include/assimp/material.h | 26 +++++++++++++++++++------- test/unit/utMaterialSystem.cpp | 7 ++++--- 3 files changed, 24 insertions(+), 11 deletions(-) diff --git a/include/assimp/GltfMaterial.h b/include/assimp/GltfMaterial.h index 5e63b9132..6f000d33b 100644 --- a/include/assimp/GltfMaterial.h +++ b/include/assimp/GltfMaterial.h @@ -53,7 +53,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include -#define AI_MATKEY_GLTF_PBRMETALLICROUGHNESS_METALLICROUGHNESS_TEXTURE aiTextureType_UNKNOWN, 0 +#define AI_MATKEY_GLTF_PBRMETALLICROUGHNESS_METALLICROUGHNESS_TEXTURE aiTextureType_GLTF_METALLIC_ROUGHNESS, 0 #define AI_MATKEY_GLTF_ALPHAMODE "$mat.gltf.alphaMode", 0, 0 #define AI_MATKEY_GLTF_ALPHACUTOFF "$mat.gltf.alphaCutoff", 0, 0 diff --git a/include/assimp/material.h b/include/assimp/material.h index 4f30728a6..dd3de1a1e 100644 --- a/include/assimp/material.h +++ b/include/assimp/material.h @@ -336,15 +336,27 @@ enum aiTextureType { /** Anisotropy * Simulates a surface with directional properties - */ + */ aiTextureType_ANISOTROPY = 26, + /** + * gltf material declarations + * Refs: https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html#metallic-roughness-material + * "textures for metalness and roughness properties are packed together in a single + * texture called metallicRoughnessTexture. Its green channel contains roughness + * values and its blue channel contains metalness values..." + * https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html#_material_pbrmetallicroughness_metallicroughnesstexture + * "The metalness values are sampled from the B channel. The roughness values are + * sampled from the G channel..." + */ + aiTextureType_GLTF_METALLIC_ROUGHNESS = 27, + #ifndef SWIG _aiTextureType_Force32Bit = INT_MAX #endif }; -#define AI_TEXTURE_TYPE_MAX aiTextureType_ANISOTROPY +#define AI_TEXTURE_TYPE_MAX aiTextureType_GLTF_METALLIC_ROUGHNESS // ------------------------------------------------------------------------------- /** @@ -443,7 +455,7 @@ enum aiShadingMode { }; // --------------------------------------------------------------------------- -/** +/** * @brief Defines some mixed flags for a particular texture. * * Usually you'll instruct your cg artists how textures have to look like ... @@ -483,7 +495,7 @@ enum aiTextureFlags { }; // --------------------------------------------------------------------------- -/** +/** * @brief Defines alpha-blend flags. * * If you're familiar with OpenGL or D3D, these flags aren't new to you. @@ -528,7 +540,7 @@ enum aiBlendMode { #include "./Compiler/pushpack1.h" // --------------------------------------------------------------------------- -/** +/** * @brief Defines how an UV channel is transformed. * * This is just a helper structure for the #AI_MATKEY_UVTRANSFORM key. @@ -573,7 +585,7 @@ struct aiUVTransform { //! @cond AI_DOX_INCLUDE_INTERNAL // --------------------------------------------------------------------------- -/** +/** * @brief A very primitive RTTI system for the contents of material properties. */ enum aiPropertyTypeInfo { @@ -719,7 +731,7 @@ struct aiMaterial #ifdef __cplusplus public: - /** + /** * @brief The class constructor. */ aiMaterial(); diff --git a/test/unit/utMaterialSystem.cpp b/test/unit/utMaterialSystem.cpp index 7547022c5..90ec5be9c 100644 --- a/test/unit/utMaterialSystem.cpp +++ b/test/unit/utMaterialSystem.cpp @@ -260,14 +260,15 @@ TEST_F(MaterialSystemTest, testMaterialTextureTypeEnum) { case aiTextureType_METALNESS: case aiTextureType_DIFFUSE_ROUGHNESS: case aiTextureType_AMBIENT_OCCLUSION: + case aiTextureType_SHEEN: + case aiTextureType_CLEARCOAT: + case aiTextureType_TRANSMISSION: case aiTextureType_MAYA_BASE: case aiTextureType_MAYA_SPECULAR: case aiTextureType_MAYA_SPECULAR_COLOR: case aiTextureType_MAYA_SPECULAR_ROUGHNESS: - case aiTextureType_SHEEN: - case aiTextureType_CLEARCOAT: - case aiTextureType_TRANSMISSION: case aiTextureType_ANISOTROPY: + case aiTextureType_GLTF_METALLIC_ROUGHNESS: case aiTextureType_UNKNOWN: if (i > maxTextureType) maxTextureType = i;