diff --git a/src/Magnum/Trade/FlatMaterialData.cpp b/src/Magnum/Trade/FlatMaterialData.cpp index def1bb81e..d56efec55 100644 --- a/src/Magnum/Trade/FlatMaterialData.cpp +++ b/src/Magnum/Trade/FlatMaterialData.cpp @@ -49,6 +49,12 @@ bool FlatMaterialData::hasTextureCoordinates() const { attributeOr(MaterialAttribute::TextureCoordinates, 0u); } +bool FlatMaterialData::hasTextureLayer() const { + return (hasAttribute(MaterialAttribute::BaseColorTexture) && attributeOr(MaterialAttribute::BaseColorTextureLayer, 0u)) || + (hasAttribute(MaterialAttribute::DiffuseTexture) && attributeOr(MaterialAttribute::DiffuseTextureLayer, 0u)) || + attributeOr(MaterialAttribute::TextureLayer, 0u); +} + Color4 FlatMaterialData::color() const { /* If the material has a texture, return the color that matches it */ if(hasAttribute(MaterialAttribute::BaseColorTexture)) @@ -104,4 +110,20 @@ UnsignedInt FlatMaterialData::textureCoordinates() const { CORRADE_ASSERT_UNREACHABLE("Trade::FlatMaterialData::textureCoordinates(): the material doesn't have a texture", {}); } +UnsignedInt FlatMaterialData::textureLayer() const { + if(hasAttribute(MaterialAttribute::BaseColorTexture)) { + if(Containers::Optional value = tryAttribute(MaterialAttribute::BaseColorTextureLayer)) + return *value; + return attributeOr(MaterialAttribute::TextureLayer, 0u); + } + + if(hasAttribute(MaterialAttribute::DiffuseTexture)) { + if(Containers::Optional value = tryAttribute(MaterialAttribute::DiffuseTextureLayer)) + return *value; + return attributeOr(MaterialAttribute::TextureLayer, 0u); + } + + CORRADE_ASSERT_UNREACHABLE("Trade::FlatMaterialData::textureLayer(): the material doesn't have a texture", {}); +} + }} diff --git a/src/Magnum/Trade/FlatMaterialData.h b/src/Magnum/Trade/FlatMaterialData.h index 707d16d1a..dab37d2a4 100644 --- a/src/Magnum/Trade/FlatMaterialData.h +++ b/src/Magnum/Trade/FlatMaterialData.h @@ -102,6 +102,21 @@ class MAGNUM_TRADE_EXPORT FlatMaterialData: public MaterialData { */ bool hasTextureCoordinates() const; + /** + * @brief Whether the material uses array texture layers + * + * Returns @cpp true @ce if the material is textured and a + * @ref MaterialAttribute::BaseColorTextureLayer, + * @ref MaterialAttribute::DiffuseTextureLayer or + * @ref MaterialAttribute::TextureLayer attribute matching the texture + * is present and has a non-zero value, @cpp false @ce otherwise. In + * particular, if there's for example a + * @ref MaterialAttribute::BaseColorTexture but only a + * @ref MaterialAttribute::DiffuseTextureLayer, returns @cpp false @ce. + * @see @ref textureLayer() + */ + bool hasTextureLayer() const; + /** * @brief Color * @@ -156,6 +171,21 @@ class MAGNUM_TRADE_EXPORT FlatMaterialData: public MaterialData { * @see @ref hasTexture() */ UnsignedInt textureCoordinates() const; + + /** + * @brief Array texture layer + * + * Convenience access to the @ref MaterialAttribute::DiffuseTextureLayer + * / @ref MaterialAttribute::BaseColorTextureLayer / + * @ref MaterialAttribute::TextureLayer attributes, picking the one + * matching the texture (instead of combining e.g. a + * @ref MaterialAttribute::BaseColorTexture with + * @ref MaterialAttribute::DiffuseTextureLayer). If no matching + * attribute is present, the default is @cpp 0 @ce. Available only if + * the material has a texture. + * @see @ref hasTexture() + */ + UnsignedInt textureLayer() const; }; }} diff --git a/src/Magnum/Trade/Implementation/materialAttributeProperties.hpp b/src/Magnum/Trade/Implementation/materialAttributeProperties.hpp index 8b03a3b4a..5ef1ca3a0 100644 --- a/src/Magnum/Trade/Implementation/materialAttributeProperties.hpp +++ b/src/Magnum/Trade/Implementation/materialAttributeProperties.hpp @@ -33,56 +33,68 @@ _c(AmbientColor,Vector4) _c(AmbientTexture,UnsignedInt) _c(AmbientTextureMatrix,Matrix3x3) _c(AmbientTextureCoordinates,UnsignedInt) +_c(AmbientTextureLayer,UnsignedInt) _c(DiffuseColor,Vector4) _c(DiffuseTexture,UnsignedInt) _c(DiffuseTextureMatrix,Matrix3x3) _c(DiffuseTextureCoordinates,UnsignedInt) +_c(DiffuseTextureLayer,UnsignedInt) _c(SpecularColor,Vector4) _c(SpecularTexture,UnsignedInt) _ct(SpecularTextureSwizzle,TextureSwizzle,MaterialTextureSwizzle) _c(SpecularTextureMatrix,Matrix3x3) _c(SpecularTextureCoordinates,UnsignedInt) +_c(SpecularTextureLayer,UnsignedInt) _c(Shininess,Float) _c(BaseColor,Vector4) _c(BaseColorTexture,UnsignedInt) _c(BaseColorTextureMatrix,Matrix3x3) _c(BaseColorTextureCoordinates,UnsignedInt) +_c(BaseColorTextureLayer,UnsignedInt) _c(Metalness,Float) _c(MetalnessTexture,UnsignedInt) _ct(MetalnessTextureSwizzle,TextureSwizzle,MaterialTextureSwizzle) _c(MetalnessTextureMatrix,Matrix3x3) _c(MetalnessTextureCoordinates,UnsignedInt) +_c(MetalnessTextureLayer,UnsignedInt) _c(Roughness,Float) _c(RoughnessTexture,UnsignedInt) _ct(RoughnessTextureSwizzle,TextureSwizzle,MaterialTextureSwizzle) _c(RoughnessTextureMatrix,Matrix3x3) _c(RoughnessTextureCoordinates,UnsignedInt) +_c(RoughnessTextureLayer,UnsignedInt) _c(NoneRoughnessMetallicTexture,UnsignedInt) _c(Glossiness,Float) _c(GlossinessTexture,UnsignedInt) _ct(GlossinessTextureSwizzle,TextureSwizzle,MaterialTextureSwizzle) _c(GlossinessTextureMatrix,Matrix3x3) _c(GlossinessTextureCoordinates,UnsignedInt) +_c(GlossinessTextureLayer,UnsignedInt) _c(SpecularGlossinessTexture,UnsignedInt) _c(NormalTexture,UnsignedInt) _c(NormalTextureScale,Float) _ct(NormalTextureSwizzle,TextureSwizzle,MaterialTextureSwizzle) _c(NormalTextureMatrix,Matrix3x3) _c(NormalTextureCoordinates,UnsignedInt) +_c(NormalTextureLayer,UnsignedInt) _c(OcclusionTexture,UnsignedInt) _c(OcclusionTextureStrength,Float) _ct(OcclusionTextureSwizzle,TextureSwizzle,MaterialTextureSwizzle) _c(OcclusionTextureMatrix,Matrix3x3) _c(OcclusionTextureCoordinates,UnsignedInt) +_c(OcclusionTextureLayer,UnsignedInt) _c(EmissiveColor,Vector3) _c(EmissiveTexture,UnsignedInt) _c(EmissiveTextureMatrix,Matrix3x3) _c(EmissiveTextureCoordinates,UnsignedInt) +_c(EmissiveTextureLayer,UnsignedInt) _c(LayerFactor,Float) _c(LayerFactorTexture,UnsignedInt) _ct(LayerFactorTextureSwizzle,TextureSwizzle,MaterialTextureSwizzle) _c(LayerFactorTextureMatrix,Matrix3x3) _c(LayerFactorTextureCoordinates,UnsignedInt) +_c(LayerFactorTextureLayer,UnsignedInt) _c(TextureMatrix,Matrix3x3) _c(TextureCoordinates,UnsignedInt) +_c(TextureLayer,UnsignedInt) #endif diff --git a/src/Magnum/Trade/MaterialData.cpp b/src/Magnum/Trade/MaterialData.cpp index 401ac9156..b8b12099f 100644 --- a/src/Magnum/Trade/MaterialData.cpp +++ b/src/Magnum/Trade/MaterialData.cpp @@ -491,6 +491,39 @@ UnsignedInt MaterialData::layerFactorTextureCoordinates(const MaterialLayer laye return layerFactorTextureCoordinates(string); } +UnsignedInt MaterialData::layerFactorTextureLayer(const UnsignedInt layer) const { + CORRADE_ASSERT(layer < layerCount(), + "Trade::MaterialData::layerFactorTextureLayer(): index" << layer << "out of range for" << layerCount() << "layers", {}); + CORRADE_ASSERT(hasAttribute(layer, MaterialAttribute::LayerFactorTexture), + "Trade::MaterialData::layerFactorTextureLayer(): layer" << layer << "doesn't have a factor texture", {}); + if(Containers::Optional value = tryAttribute(layer, MaterialAttribute::LayerFactorTextureLayer)) + return *value; + if(Containers::Optional value = tryAttribute(layer, MaterialAttribute::TextureLayer)) + return *value; + return attributeOr(0, MaterialAttribute::TextureLayer, 0u); +} + +UnsignedInt MaterialData::layerFactorTextureLayer(const Containers::StringView layer) const { + const UnsignedInt layerId = layerFor(layer); + CORRADE_ASSERT(layerId != ~UnsignedInt{}, + "Trade::MaterialData::layerFactorTextureLayer(): layer" << layer << "not found", {}); + CORRADE_ASSERT(hasAttribute(layerId, MaterialAttribute::LayerFactorTexture), + "Trade::MaterialData::layerFactorTextureLayer(): layer" << layer << "doesn't have a factor texture", {}); + /* Not delegating into layerFactorTextureLayer() because we have a + different variant of the assert here */ + if(Containers::Optional value = tryAttribute(layerId, MaterialAttribute::LayerFactorTextureLayer)) + return *value; + if(Containers::Optional value = tryAttribute(layerId, MaterialAttribute::TextureLayer)) + return *value; + return attributeOr(0, MaterialAttribute::TextureLayer, 0u); +} + +UnsignedInt MaterialData::layerFactorTextureLayer(const MaterialLayer layer) const { + const Containers::StringView string = layerString(layer); + CORRADE_ASSERT(string, "Trade::MaterialData::layerFactorTextureLayer(): invalid name" << layer, {}); + return layerFactorTextureLayer(string); +} + UnsignedInt MaterialData::attributeCount(const UnsignedInt layer) const { CORRADE_ASSERT(layer < layerCount(), "Trade::MaterialData::attributeCount(): index" << layer << "out of range for" << layerCount() << "layers", {}); diff --git a/src/Magnum/Trade/MaterialData.h b/src/Magnum/Trade/MaterialData.h index 1022328f3..ca3a9de7f 100644 --- a/src/Magnum/Trade/MaterialData.h +++ b/src/Magnum/Trade/MaterialData.h @@ -186,6 +186,16 @@ enum class MaterialAttribute: UnsignedInt { */ AmbientTextureCoordinates, + /** + * Ambient texture array layer for Phong materials, + * @ref MaterialAttributeType::UnsignedInt. + * + * Has a precedence over @ref MaterialAttribute::TextureLayer if both are + * present. + * @see @ref PhongMaterialData::ambientTextureLayer() + */ + AmbientTextureLayer, + /** * Diffuse color for Phong or PBR specular/glossiness materials, * @ref MaterialAttributeType::Vector4. @@ -234,6 +244,16 @@ enum class MaterialAttribute: UnsignedInt { */ DiffuseTextureCoordinates, + /** + * Diffuse texture array layer for Phong materials, + * @ref MaterialAttributeType::UnsignedInt. + * + * Has a precedence over @ref MaterialAttribute::TextureLayer if both are + * present. + * @see @ref PhongMaterialData::diffuseTextureLayer() + */ + DiffuseTextureLayer, + /** * Specular color for Phong or PBR specular/glossiness materials, * @ref MaterialAttributeType::Vector4. Alpha is commonly zero to not @@ -301,6 +321,17 @@ enum class MaterialAttribute: UnsignedInt { */ SpecularTextureCoordinates, + /** + * Specular texture array layer for Phong materials, + * @ref MaterialAttributeType::UnsignedInt. + * + * Has a precedence over @ref MaterialAttribute::TextureLayer if both are + * present. + * @see @ref PhongMaterialData::specularTextureLayer(), + * @ref PbrSpecularGlossinessMaterialData::specularTextureLayer() + */ + SpecularTextureLayer, + /** * Shininess value for Phong materials, @ref MaterialAttributeType::Float. * @@ -352,6 +383,17 @@ enum class MaterialAttribute: UnsignedInt { */ BaseColorTextureCoordinates, + /** + * Base color texture array layer for PBR metallic/roughness materials, + * @ref MaterialAttributeType::UnsignedInt. + * + * Has a precedence over @ref MaterialAttribute::TextureLayer if both are + * present. + * @see @ref FlatMaterialData::textureLayer(), + * @ref PbrMetallicRoughnessMaterialData::baseColorTextureLayer() + */ + BaseColorTextureLayer, + /** * Metalness for PBR metallic/roughness materials, * @ref MaterialAttributeType::Float. @@ -416,6 +458,16 @@ enum class MaterialAttribute: UnsignedInt { */ MetalnessTextureCoordinates, + /** + * Metalness texture array layer for PBR metallic/roughness materials, + * @ref MaterialAttributeType::UnsignedInt. + * + * Has a precedence over @ref MaterialAttribute::TextureLayer if both are + * present. + * @see @ref PbrMetallicRoughnessMaterialData::metalnessTextureLayer() + */ + MetalnessTextureLayer, + /** * Roughness for PBR metallic/roughness materials, * @ref MaterialAttributeType::Float. @@ -480,6 +532,16 @@ enum class MaterialAttribute: UnsignedInt { */ RoughnessTextureCoordinates, + /** + * Roughness texture array layer for PBR metallic/roughness materials, + * @ref MaterialAttributeType::UnsignedInt. + * + * Has a precedence over @ref MaterialAttribute::TextureLayer if both are + * present. + * @see @ref PbrMetallicRoughnessMaterialData::roughnessTextureLayer() + */ + RoughnessTextureLayer, + /** * Combined roughness/metallic texture index for PBR metallic/roughness * materials with metalness in the blue channel and roughness in the green @@ -513,9 +575,10 @@ enum class MaterialAttribute: UnsignedInt { NoneRoughnessMetallicTexture, /* DiffuseColor, DiffuseTexture, DiffuseTextureMatrix, - DiffuseTextureCoordinates, SpecularColor, SpecularTexture, - SpecularTextureSwizzle, SpecularTextureMatrix, - SpecularTextureCoordinates specified above for Phong already */ + DiffuseTextureCoordinates, DiffuseTextureLayer, SpecularColor, + SpecularTexture, SpecularTextureSwizzle, SpecularTextureMatrix, + SpecularTextureCoordinates, SpecularTextureLayer specified above for + Phong already */ /** * Glossiness for PBR specular/glossiness materials, @@ -577,6 +640,16 @@ enum class MaterialAttribute: UnsignedInt { */ GlossinessTextureCoordinates, + /** + * Metalness texture array layer for PBR specular/glossiness materials, + * @ref MaterialAttributeType::UnsignedInt. + * + * Has a precedence over @ref MaterialAttribute::TextureLayer if both are + * present. + * @see @ref PbrSpecularGlossinessMaterialData::glossinessTextureLayer() + */ + GlossinessTextureLayer, + /** * Combined specular/glossiness texture index for PBR specular/glossiness * materials with specular color in the RGB channels and glossiness in @@ -687,6 +760,17 @@ enum class MaterialAttribute: UnsignedInt { */ NormalTextureCoordinates, + /** + * Normal texture array layer, @ref MaterialAttributeType::UnsignedInt. + * + * Has a precedence over @ref MaterialAttribute::TextureLayer if both are + * present. + * @see @ref PhongMaterialData::normalTextureLayer(), + * @ref PbrMetallicRoughnessMaterialData::normalTextureLayer(), + * @ref PbrSpecularGlossinessMaterialData::normalTextureLayer() + */ + NormalTextureLayer, + /** * Occlusion texture index, * @ref MaterialAttributeType::UnsignedInt. @@ -754,6 +838,16 @@ enum class MaterialAttribute: UnsignedInt { */ OcclusionTextureCoordinates, + /** + * Occlusion texture array layer, @ref MaterialAttributeType::UnsignedInt. + * + * Has a precedence over @ref MaterialAttribute::TextureLayer if both are + * present. + * @see @ref PbrMetallicRoughnessMaterialData::occlusionTextureLayer(), + * @ref PbrSpecularGlossinessMaterialData::occlusionTextureLayer() + */ + OcclusionTextureLayer, + /** * Emissive color, * @ref MaterialAttributeType::Vector3. @@ -801,6 +895,16 @@ enum class MaterialAttribute: UnsignedInt { */ EmissiveTextureCoordinates, + /** + * Emissive texture array layer, @ref MaterialAttributeType::UnsignedInt. + * + * Has a precedence over @ref MaterialAttribute::TextureLayer if both are + * present. + * @see @ref PbrMetallicRoughnessMaterialData::emissiveTextureLayer(), + * @ref PbrSpecularGlossinessMaterialData::emissiveTextureLayer() + */ + EmissiveTextureLayer, + /** * Layer intensity. @ref MaterialAttributeType::Float. * @@ -855,6 +959,17 @@ enum class MaterialAttribute: UnsignedInt { */ LayerFactorTextureCoordinates, + /** + * Layer intensity texture array layer, + * @ref MaterialAttributeType::UnsignedInt. + * + * Expected to be contained in additional layers, not the base material. + * Has a precedence over @ref MaterialAttribute::TextureLayer if both are + * present. + * @see @ref MaterialData::layerFactorTextureLayer() + */ + LayerFactorTextureLayer, + /** * Common texture transformation matrix for all textures, * @ref MaterialAttributeType::Matrix3x3. @@ -908,6 +1023,33 @@ enum class MaterialAttribute: UnsignedInt { * @ref FlatMaterialData::textureCoordinates() */ TextureCoordinates, + + /** + * Common texture array layer for all textures, + * @ref MaterialAttributeType::UnsignedInt. + * + * @ref MaterialAttribute::AmbientTextureLayer / + * @ref MaterialAttribute::DiffuseTextureLayer / + * @ref MaterialAttribute::SpecularTextureLayer / + * @ref MaterialAttribute::MetalnessTextureLayer / + * @ref MaterialAttribute::RoughnessTextureLayer / + * @ref MaterialAttribute::GlossinessTextureLayer / + * @ref MaterialAttribute::NormalTextureLayer / + * @ref MaterialAttribute::OcclusionTextureLayer / + * @ref MaterialAttribute::EmissiveTextureLayer / + * @ref MaterialAttribute::LayerFactorTextureLayer have a precedence over + * this attribute for given texture, if present. + * @see @ref PhongMaterialData::hasCommonTextureLayer(), + * @ref PbrMetallicRoughnessMaterialData::hasCommonTextureLayer(), + * @ref PbrSpecularGlossinessMaterialData::hasCommonTextureLayer(), + * @ref PbrClearCoatMaterialData::hasCommonTextureLayer(), + * @ref PhongMaterialData::commonTextureLayer(), + * @ref PbrMetallicRoughnessMaterialData::commonTextureLayer(), + * @ref PbrSpecularGlossinessMaterialData::commonTextureLayer(), + * @ref PbrClearCoatMaterialData::commonTextureLayer(), + * @ref FlatMaterialData::textureLayer() + */ + TextureLayer, }; /** @@ -2052,6 +2194,34 @@ class MAGNUM_TRADE_EXPORT MaterialData { UnsignedInt layerFactorTextureCoordinates(Containers::StringView layer) const; UnsignedInt layerFactorTextureCoordinates(MaterialLayer layer) const; /**< @overload */ + /** + * @brief Factor array texture layer for given layer + * + * Convenience access to the @ref MaterialAttribute::LayerFactorTextureLayer + * / @ref MaterialAttribute::TextureLayer attributes in given layer or + * a @ref MaterialAttribute::TextureLayer attribute in the base + * material. If neither is present, the default is @cpp 0 @ce. + * Available only if the @ref MaterialAttribute::LayerFactorTexture + * attribute is present. The @p layer is expected to be smaller than + * @ref layerCount(). + * @see @ref hasAttribute() + */ + UnsignedInt layerFactorTextureLayer(UnsignedInt layer) const; + + /** + * @brief Factor array texture layer for a named layer + * + * Convenience access to the @ref MaterialAttribute::LayerFactorTextureLayer + * / @ref MaterialAttribute::TextureLayer attributes in given layer or + * a @ref MaterialAttribute::TextureLayer attribute in the base + * material. If neither is present, the default is @cpp 0 @ce. + * Available only if the @ref MaterialAttribute::LayerFactorTexture + * attribute is present. The @p layer is expected to exist. + * @see @ref hasLayer(), @ref hasAttribute() + */ + UnsignedInt layerFactorTextureLayer(Containers::StringView layer) const; + UnsignedInt layerFactorTextureLayer(MaterialLayer layer) const; /**< @overload */ + /** * @brief Attribute count in given layer * diff --git a/src/Magnum/Trade/MaterialLayerData.h b/src/Magnum/Trade/MaterialLayerData.h index 7e7477b65..7ca98eff1 100644 --- a/src/Magnum/Trade/MaterialLayerData.h +++ b/src/Magnum/Trade/MaterialLayerData.h @@ -110,6 +110,16 @@ template class MaterialLayerData: public MaterialData { return MaterialData::layerFactorTextureCoordinates(layer); } + /** + * @brief Layer factor array texture layer + * + * Same as calling @ref MaterialData::layerFactorTextureLayer() with + * @p layer. + */ + UnsignedInt layerFactorTextureLayer() const { + return MaterialData::layerFactorTextureLayer(layer); + } + /** * @brief Attribute count in this layer * @@ -271,6 +281,7 @@ template class MaterialLayerData: public MaterialData { using MaterialData::layerFactorTextureSwizzle; using MaterialData::layerFactorTextureMatrix; using MaterialData::layerFactorTextureCoordinates; + using MaterialData::layerFactorTextureLayer; /* MSVC is so damn unbelievably stupid it's setting my ass on fire. https://en.cppreference.com/w/cpp/language/using_declaration says that "If the derived class already has a member with the same name, diff --git a/src/Magnum/Trade/PbrClearCoatMaterialData.cpp b/src/Magnum/Trade/PbrClearCoatMaterialData.cpp index e88fd47af..c1160bf04 100644 --- a/src/Magnum/Trade/PbrClearCoatMaterialData.cpp +++ b/src/Magnum/Trade/PbrClearCoatMaterialData.cpp @@ -34,7 +34,8 @@ bool PbrClearCoatMaterialData::hasLayerFactorRoughnessTexture() const { layerFactorTextureSwizzle() == MaterialTextureSwizzle::R && roughnessTextureSwizzle() == MaterialTextureSwizzle::G && layerFactorTextureMatrix() == roughnessTextureMatrix() && - layerFactorTextureCoordinates() == roughnessTextureCoordinates(); + layerFactorTextureCoordinates() == roughnessTextureCoordinates() && + layerFactorTextureLayer() == roughnessTextureLayer(); } bool PbrClearCoatMaterialData::hasTextureTransformation() const { @@ -95,6 +96,35 @@ bool PbrClearCoatMaterialData::hasCommonTextureCoordinates() const { return true; } +bool PbrClearCoatMaterialData::hasTextureLayer() const { + return attributeOr(MaterialAttribute::LayerFactorTextureLayer, 0u) || + attributeOr(MaterialAttribute::RoughnessTextureLayer, 0u) || + attributeOr(MaterialAttribute::NormalTextureLayer, 0u) || + attributeOr(MaterialAttribute::TextureLayer, 0u) || + attributeOr(0, MaterialAttribute::TextureLayer, 0u); +} + +bool PbrClearCoatMaterialData::hasCommonTextureLayer() const { + auto check = [](Containers::Optional& layer, UnsignedInt current) { + if(!layer) { + layer = current; + return true; + } + return layer == current; + }; + + Containers::Optional layer; + /* First one can't fail */ + if(hasAttribute(MaterialAttribute::LayerFactorTexture) && !check(layer, layerFactorTextureLayer())) + CORRADE_INTERNAL_ASSERT_UNREACHABLE(); /* LCOV_EXCL_LINE */ + if(hasAttribute(MaterialAttribute::RoughnessTexture) && !check(layer, roughnessTextureLayer())) + return false; + if(hasAttribute(MaterialAttribute::NormalTexture) && !check(layer, normalTextureLayer())) + return false; + + return true; +} + Float PbrClearCoatMaterialData::roughness() const { return attributeOr(MaterialAttribute::Roughness, 0.0f); } @@ -129,6 +159,16 @@ UnsignedInt PbrClearCoatMaterialData::roughnessTextureCoordinates() const { return attributeOr(0, MaterialAttribute::TextureCoordinates, 0u); } +UnsignedInt PbrClearCoatMaterialData::roughnessTextureLayer() const { + CORRADE_ASSERT(hasAttribute(MaterialAttribute::RoughnessTexture), + "Trade::PbrClearCoatMaterialData::roughnessTextureLayer(): the layer doesn't have a roughness texture", {}); + if(Containers::Optional value = tryAttribute(MaterialAttribute::RoughnessTextureLayer)) + return *value; + if(Containers::Optional value = tryAttribute(MaterialAttribute::TextureLayer)) + return *value; + return attributeOr(0, MaterialAttribute::TextureLayer, 0u); +} + UnsignedInt PbrClearCoatMaterialData::normalTexture() const { return attribute(MaterialAttribute::NormalTexture); } @@ -165,6 +205,16 @@ UnsignedInt PbrClearCoatMaterialData::normalTextureCoordinates() const { return attributeOr(0, MaterialAttribute::TextureCoordinates, 0u); } +UnsignedInt PbrClearCoatMaterialData::normalTextureLayer() const { + CORRADE_ASSERT(hasAttribute(MaterialAttribute::NormalTexture), + "Trade::PbrClearCoatMaterialData::normalTextureLayer(): the layer doesn't have a normal texture", {}); + if(Containers::Optional value = tryAttribute(MaterialAttribute::NormalTextureLayer)) + return *value; + if(Containers::Optional value = tryAttribute(MaterialAttribute::TextureLayer)) + return *value; + return attributeOr(0, MaterialAttribute::TextureLayer, 0u); +} + Matrix3 PbrClearCoatMaterialData::commonTextureMatrix() const { CORRADE_ASSERT(hasCommonTextureTransformation(), "Trade::PbrClearCoatMaterialData::commonTextureMatrix(): the layer doesn't have a common texture coordinate transformation", {}); @@ -193,4 +243,18 @@ UnsignedInt PbrClearCoatMaterialData::commonTextureCoordinates() const { return attributeOr(0, MaterialAttribute::TextureCoordinates, 0u); } +UnsignedInt PbrClearCoatMaterialData::commonTextureLayer() const { + CORRADE_ASSERT(hasCommonTextureLayer(), + "Trade::PbrClearCoatMaterialData::commonTextureLayer(): the layer doesn't have a common array texture layer", {}); + if(hasAttribute(MaterialAttribute::LayerFactorTexture)) + return layerFactorTextureLayer(); + if(hasAttribute(MaterialAttribute::RoughnessTexture)) + return roughnessTextureLayer(); + if(hasAttribute(MaterialAttribute::NormalTexture)) + return normalTextureLayer(); + if(Containers::Optional value = tryAttribute(MaterialAttribute::TextureLayer)) + return *value; + return attributeOr(0, MaterialAttribute::TextureLayer, 0u); +} + }} diff --git a/src/Magnum/Trade/PbrClearCoatMaterialData.h b/src/Magnum/Trade/PbrClearCoatMaterialData.h index df7f526eb..222efa30a 100644 --- a/src/Magnum/Trade/PbrClearCoatMaterialData.h +++ b/src/Magnum/Trade/PbrClearCoatMaterialData.h @@ -69,17 +69,21 @@ class MAGNUM_TRADE_EXPORT PbrClearCoatMaterialData: public MaterialLayerDataroughnessTextureMatrix(); const UnsignedInt roughnessTextureCoordinates = this->roughnessTextureCoordinates(); + const UnsignedInt roughnessTextureLayer = this->roughnessTextureLayer(); return metalnessTextureMatrix() == roughnessTextureMatrix && occlusionTextureMatrix() == roughnessTextureMatrix && metalnessTextureCoordinates() == roughnessTextureCoordinates && - occlusionTextureCoordinates() == roughnessTextureCoordinates; + occlusionTextureCoordinates() == roughnessTextureCoordinates && + metalnessTextureLayer() == roughnessTextureLayer && + occlusionTextureLayer() == roughnessTextureLayer; } bool PbrMetallicRoughnessMaterialData::hasOcclusionRoughnessMetallicTexture() const { @@ -91,10 +95,13 @@ bool PbrMetallicRoughnessMaterialData::hasOcclusionRoughnessMetallicTexture() co const Matrix3 occlusionTextureMatrix = this->occlusionTextureMatrix(); const UnsignedInt occlusionTextureCoordinates = this->occlusionTextureCoordinates(); + const UnsignedInt occlusionTextureLayer = this->occlusionTextureLayer(); return roughnessTextureMatrix() == occlusionTextureMatrix && metalnessTextureMatrix() == occlusionTextureMatrix && roughnessTextureCoordinates() == occlusionTextureCoordinates && - metalnessTextureCoordinates() == occlusionTextureCoordinates; + metalnessTextureCoordinates() == occlusionTextureCoordinates && + roughnessTextureLayer() == occlusionTextureLayer && + metalnessTextureLayer() == occlusionTextureLayer; } bool PbrMetallicRoughnessMaterialData::hasNormalRoughnessMetallicTexture() const { @@ -113,10 +120,13 @@ bool PbrMetallicRoughnessMaterialData::hasNormalRoughnessMetallicTexture() const const Matrix3 normalTextureMatrix = this->normalTextureMatrix(); const UnsignedInt normalTextureCoordinates = this->normalTextureCoordinates(); + const UnsignedInt normalTextureLayer = this->normalTextureLayer(); return roughnessTextureMatrix() == normalTextureMatrix && metalnessTextureMatrix() == normalTextureMatrix && roughnessTextureCoordinates() == normalTextureCoordinates && - metalnessTextureCoordinates() == normalTextureCoordinates; + metalnessTextureCoordinates() == normalTextureCoordinates && + roughnessTextureLayer() == normalTextureLayer && + metalnessTextureLayer() == normalTextureLayer; } bool PbrMetallicRoughnessMaterialData::hasTextureTransformation() const { @@ -193,6 +203,43 @@ bool PbrMetallicRoughnessMaterialData::hasCommonTextureCoordinates() const { return true; } +bool PbrMetallicRoughnessMaterialData::hasTextureLayer() const { + return attributeOr(MaterialAttribute::TextureLayer, 0u) || + attributeOr(MaterialAttribute::BaseColorTextureLayer, 0u) || + attributeOr(MaterialAttribute::MetalnessTextureLayer, 0u) || + attributeOr(MaterialAttribute::RoughnessTextureLayer, 0u) || + attributeOr(MaterialAttribute::NormalTextureLayer, 0u) || + attributeOr(MaterialAttribute::OcclusionTextureLayer, 0u) || + attributeOr(MaterialAttribute::EmissiveTextureLayer, 0u); +} + +bool PbrMetallicRoughnessMaterialData::hasCommonTextureLayer() const { + auto check = [](Containers::Optional& layer, UnsignedInt current) { + if(!layer) { + layer = current; + return true; + } + return layer == current; + }; + + Containers::Optional layer; + /* First one can't fail */ + if(hasAttribute(MaterialAttribute::BaseColorTexture) && !check(layer, baseColorTextureLayer())) + CORRADE_INTERNAL_ASSERT_UNREACHABLE(); /* LCOV_EXCL_LINE */ + if(hasMetalnessTexture() && !check(layer, metalnessTextureLayer())) + return false; + if(hasRoughnessTexture() && !check(layer, roughnessTextureLayer())) + return false; + if(hasAttribute(MaterialAttribute::NormalTexture) && !check(layer, normalTextureLayer())) + return false; + if(hasAttribute(MaterialAttribute::OcclusionTexture) && !check(layer, occlusionTextureLayer())) + return false; + if(hasAttribute(MaterialAttribute::EmissiveTexture) && !check(layer, emissiveTextureLayer())) + return false; + + return true; +} + Color4 PbrMetallicRoughnessMaterialData::baseColor() const { return attributeOr(MaterialAttribute::BaseColor, 0xffffffff_rgbaf); } @@ -217,6 +264,14 @@ UnsignedInt PbrMetallicRoughnessMaterialData::baseColorTextureCoordinates() cons return attributeOr(MaterialAttribute::TextureCoordinates, 0u); } +UnsignedInt PbrMetallicRoughnessMaterialData::baseColorTextureLayer() const { + CORRADE_ASSERT(hasAttribute(MaterialAttribute::BaseColorTexture), + "Trade::PbrMetallicRoughnessMaterialData::baseColorTextureLayer(): the material doesn't have a base color texture", {}); + if(Containers::Optional value = tryAttribute(MaterialAttribute::BaseColorTextureLayer)) + return *value; + return attributeOr(MaterialAttribute::TextureLayer, 0u); +} + Float PbrMetallicRoughnessMaterialData::metalness() const { return attributeOr(MaterialAttribute::Metalness, 1.0f); } @@ -256,6 +311,14 @@ UnsignedInt PbrMetallicRoughnessMaterialData::metalnessTextureCoordinates() cons return attributeOr(MaterialAttribute::TextureCoordinates, 0u); } +UnsignedInt PbrMetallicRoughnessMaterialData::metalnessTextureLayer() const { + CORRADE_ASSERT(hasMetalnessTexture(), + "Trade::PbrMetallicRoughnessMaterialData::metalnessTextureLayer(): the material doesn't have a metalness texture", {}); + if(Containers::Optional value = tryAttribute(MaterialAttribute::MetalnessTextureLayer)) + return *value; + return attributeOr(MaterialAttribute::TextureLayer, 0u); +} + Float PbrMetallicRoughnessMaterialData::roughness() const { return attributeOr(MaterialAttribute::Roughness, 1.0f); } @@ -295,6 +358,14 @@ UnsignedInt PbrMetallicRoughnessMaterialData::roughnessTextureCoordinates() cons return attributeOr(MaterialAttribute::TextureCoordinates, 0u); } +UnsignedInt PbrMetallicRoughnessMaterialData::roughnessTextureLayer() const { + CORRADE_ASSERT(hasRoughnessTexture(), + "Trade::PbrMetallicRoughnessMaterialData::roughnessTextureLayer(): the material doesn't have a roughness texture", {}); + if(Containers::Optional value = tryAttribute(MaterialAttribute::RoughnessTextureLayer)) + return *value; + return attributeOr(MaterialAttribute::TextureLayer, 0u); +} + UnsignedInt PbrMetallicRoughnessMaterialData::normalTexture() const { return attribute(MaterialAttribute::NormalTexture); } @@ -327,6 +398,14 @@ UnsignedInt PbrMetallicRoughnessMaterialData::normalTextureCoordinates() const { return attributeOr(MaterialAttribute::TextureCoordinates, 0u); } +UnsignedInt PbrMetallicRoughnessMaterialData::normalTextureLayer() const { + CORRADE_ASSERT(hasAttribute(MaterialAttribute::NormalTexture), + "Trade::PbrMetallicRoughnessMaterialData::normalTextureLayer(): the material doesn't have a normal texture", {}); + if(Containers::Optional value = tryAttribute(MaterialAttribute::NormalTextureLayer)) + return *value; + return attributeOr(MaterialAttribute::TextureLayer, 0u); +} + UnsignedInt PbrMetallicRoughnessMaterialData::occlusionTexture() const { return attribute(MaterialAttribute::OcclusionTexture); } @@ -359,6 +438,14 @@ UnsignedInt PbrMetallicRoughnessMaterialData::occlusionTextureCoordinates() cons return attributeOr(MaterialAttribute::TextureCoordinates, 0u); } +UnsignedInt PbrMetallicRoughnessMaterialData::occlusionTextureLayer() const { + CORRADE_ASSERT(hasAttribute(MaterialAttribute::OcclusionTexture), + "Trade::PbrMetallicRoughnessMaterialData::occlusionTextureLayer(): the material doesn't have an occlusion texture", {}); + if(Containers::Optional value = tryAttribute(MaterialAttribute::OcclusionTextureLayer)) + return *value; + return attributeOr(MaterialAttribute::TextureLayer, 0u); +} + Color3 PbrMetallicRoughnessMaterialData::emissiveColor() const { return attributeOr(MaterialAttribute::EmissiveColor, 0x000000_srgbf); } @@ -383,6 +470,14 @@ UnsignedInt PbrMetallicRoughnessMaterialData::emissiveTextureCoordinates() const return attributeOr(MaterialAttribute::TextureCoordinates, 0u); } +UnsignedInt PbrMetallicRoughnessMaterialData::emissiveTextureLayer() const { + CORRADE_ASSERT(hasAttribute(MaterialAttribute::EmissiveTexture), + "Trade::PbrMetallicRoughnessMaterialData::emissiveTextureLayer(): the material doesn't have an emissive texture", {}); + if(Containers::Optional value = tryAttribute(MaterialAttribute::EmissiveTextureLayer)) + return *value; + return attributeOr(MaterialAttribute::TextureLayer, 0u); +} + Matrix3 PbrMetallicRoughnessMaterialData::commonTextureMatrix() const { CORRADE_ASSERT(hasCommonTextureTransformation(), "Trade::PbrMetallicRoughnessMaterialData::commonTextureMatrix(): the material doesn't have a common texture coordinate transformation", {}); @@ -419,4 +514,22 @@ UnsignedInt PbrMetallicRoughnessMaterialData::commonTextureCoordinates() const { return attributeOr(MaterialAttribute::TextureCoordinates, 0u); } +UnsignedInt PbrMetallicRoughnessMaterialData::commonTextureLayer() const { + CORRADE_ASSERT(hasCommonTextureLayer(), + "Trade::PbrMetallicRoughnessMaterialData::commonTextureLayer(): the material doesn't have a common array texture layer", {}); + if(hasAttribute(MaterialAttribute::BaseColorTexture)) + return baseColorTextureLayer(); + if(hasMetalnessTexture()) + return metalnessTextureLayer(); + if(hasRoughnessTexture()) + return roughnessTextureLayer(); + if(hasAttribute(MaterialAttribute::NormalTexture)) + return normalTextureLayer(); + if(hasAttribute(MaterialAttribute::OcclusionTexture)) + return occlusionTextureLayer(); + if(hasAttribute(MaterialAttribute::EmissiveTexture)) + return emissiveTextureLayer(); + return attributeOr(MaterialAttribute::TextureLayer, 0u); +} + }} diff --git a/src/Magnum/Trade/PbrMetallicRoughnessMaterialData.h b/src/Magnum/Trade/PbrMetallicRoughnessMaterialData.h index c7fc57ab5..ec3e2d563 100644 --- a/src/Magnum/Trade/PbrMetallicRoughnessMaterialData.h +++ b/src/Magnum/Trade/PbrMetallicRoughnessMaterialData.h @@ -92,19 +92,23 @@ class MAGNUM_TRADE_EXPORT PbrMetallicRoughnessMaterialData: public MaterialData * @ref MaterialTextureSwizzle::B, and ddditionally * @ref MaterialAttribute::RoughnessTextureMatrix and * @ref MaterialAttribute::MetalnessTextureMatrix are both either not - * present or have the same value, and + * present or have the same value, * @ref MaterialAttribute::RoughnessTextureCoordinates and * @ref MaterialAttribute::MetalnessTextureCoordinates are both either - * not present or have the same value; @cpp false @ce otherwise. + * not present or have the same value, and + * @ref MaterialAttribute::RoughnessTextureLayer and + * @ref MaterialAttribute::MetalnessTextureLayer are both either not + * present or have the same value; @cpp false @ce otherwise. * * In other words, if this function returns @cpp true @ce, - * @ref roughnessTexture(), @ref roughnessTextureMatrix() and - * @ref roughnessTextureCoordinates() return values common for both - * metalness and roughness texture, and the two are packed together - * with roughness occupying the G channel and metalness the B channel. - * This packing is common in glTF metallic/roughness materials, which - * in turn is compatible with how UE4 assets are usually packed. - * Original rationale for this [can be seen here](https://github.com/KhronosGroup/glTF/issues/857). + * @ref roughnessTexture(), @ref roughnessTextureMatrix(), + * @ref roughnessTextureCoordinates() and @ref roughnessTextureLayer() + * return values common for both metalness and roughness texture, and + * the two are packed together with roughness occupying the G channel + * and metalness the B channel. This packing is common in glTF + * metallic/roughness materials, which in turn is compatible with how + * UE4 assets are usually packed. Original rationale for this + * [can be seen here](https://github.com/KhronosGroup/glTF/issues/857). * * The red and alpha channels are ignored and can be repurposed for * other maps such as occlusion or transmission. This check is a subset @@ -131,21 +135,25 @@ class MAGNUM_TRADE_EXPORT PbrMetallicRoughnessMaterialData: public MaterialData * @ref MaterialAttribute::OcclusionTextureMatrix, * @ref MaterialAttribute::RoughnessTextureMatrix and * @ref MaterialAttribute::MetalnessTextureMatrix are all other not - * present or have the same value, and + * present or have the same value, * @ref MaterialAttribute::OcclusionTextureCoordinates, * @ref MaterialAttribute::RoughnessTextureCoordinates and * @ref MaterialAttribute::MetalnessTextureCoordinates are all either - * not present or have the same value; @cpp false @ce otherwise. + * not present or have the same value, and + * @ref MaterialAttribute::OcclusionTextureLayer, + * @ref MaterialAttribute::RoughnessTextureLayer and + * @ref MaterialAttribute::MetalnessTextureLayer are all either not + * present or have the same value; @cpp false @ce otherwise. * * In other words, if this function returns @cpp true @ce, - * @ref occlusionTexture(), @ref occlusionTextureMatrix() and - * @ref occlusionTextureCoordinates() return values common for - * occlusion, roughness and metalness textures, and the three are - * packed together with occlusion occupying the R channel, roughness - * the G channel and metalness the B channel. This packing is common in - * glTF metallic/roughness materials, which in turn is compatible with - * how UE4 assets are usually packed. Original rationale for this [can - * be seen here](https://github.com/KhronosGroup/glTF/issues/857), + * @ref occlusionTexture(), @ref occlusionTextureMatrix(), + * @ref occlusionTextureCoordinates() and @ref occlusionTextureLayer() + * return values common for occlusion, roughness and metalness + * textures, and the three are packed together with occlusion occupying + * the R channel, roughness the G channel and metalness the B channel. + * This packing is common in glTF metallic/roughness materials, which + * in turn is compatible with how UE4 assets are usually packed. + * Original rationale for this [can be seen here](https://github.com/KhronosGroup/glTF/issues/857), * there's also a [MSFT_packing_occlusionRoughnessMetallic](https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Vendor/MSFT_packing_occlusionRoughnessMetallic/README.md) * glTF extension using this packing in a more explicit way. * @@ -175,19 +183,23 @@ class MAGNUM_TRADE_EXPORT PbrMetallicRoughnessMaterialData: public MaterialData * @ref MaterialAttribute::RoughnessTextureMatrix, * @ref MaterialAttribute::MetalnessTextureMatrix and * @ref MaterialAttribute::OcclusionTextureMatrix are all other not - * present or have the same value, and + * present or have the same value, * @ref MaterialAttribute::RoughnessTextureCoordinates, * @ref MaterialAttribute::MetalnessTextureCoordinates and * @ref MaterialAttribute::OcclusionTextureCoordinates are all either - * not present or have the same value; @cpp false @ce otherwise. + * not present or have the same value, and + * @ref MaterialAttribute::RoughnessTextureLayer, + * @ref MaterialAttribute::MetalnessTextureLayer and + * @ref MaterialAttribute::OcclusionTextureLayer are all either not + * present or have the same value; @cpp false @ce otherwise. * * In other words, if this function returns @cpp true @ce, - * @ref roughnessTexture(), @ref roughnessTextureMatrix() and - * @ref roughnessTextureCoordinates() return values common for - * roughness, metalness and occlusion textures, and the three are - * packed together with roughness occupying the R channel, metalness - * the G channel and occlusion the B channel. This check is present in - * order to provide support for the [MSFT_packing_occlusionRoughnessMetallic](https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Vendor/MSFT_packing_occlusionRoughnessMetallic/README.md) + * @ref roughnessTexture(), @ref roughnessTextureMatrix(), + * @ref roughnessTextureCoordinates() and @ref roughnessTextureLayer() + * return values common for roughness, metalness and occlusion + * textures, and the three are packed together with roughness occupying + * the R channel, metalness the G channel and occlusion the B channel. + * This check is present in order to provide support for the [MSFT_packing_occlusionRoughnessMetallic](https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Vendor/MSFT_packing_occlusionRoughnessMetallic/README.md) * glTF extension. * * The alpha channel is ignored and can be repurposed for other maps @@ -214,19 +226,24 @@ class MAGNUM_TRADE_EXPORT PbrMetallicRoughnessMaterialData: public MaterialData * @ref MaterialAttribute::NormalTextureMatrix, * @ref MaterialAttribute::RoughnessTextureMatrix and * @ref MaterialAttribute::MetalnessTextureMatrix are all other not - * present or have the same value, and + * present or have the same value, * @ref MaterialAttribute::NormalTextureCoordinates, * @ref MaterialAttribute::RoughnessTextureCoordinates and * @ref MaterialAttribute::MetalnessTextureCoordinates are all either - * not present or have the same value; @cpp false @ce otherwise. + * not present or have the same value, and + * @ref MaterialAttribute::NormalTextureLayer, + * @ref MaterialAttribute::RoughnessTextureLayer and + * @ref MaterialAttribute::MetalnessTextureLayer are all either not + * present or have the same value; @cpp false @ce otherwise. * * In other words, if this function returns @cpp true @ce, - * @ref normalTexture(), @ref normalTextureMatrix() and - * @ref normalTextureCoordinates() return values common for normal, - * roughness and metalness textures, and the three are packed together - * with normals occupying the RG channel, roughness the B channel and - * metalness the A channel. This check is present in order to provide - * support for the [MSFT_packing_normalRoughnessMetallic](https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Vendor/MSFT_packing_normalRoughnessMetallic/README.md) + * @ref normalTexture(), @ref normalTextureMatrix(), + * @ref normalTextureCoordinates() and @ref normalTextureLayer() return + * values common for normal, roughness and metalness textures, and the + * three are packed together with normals occupying the RG channel, + * roughness the B channel and metalness the A channel. This check is + * present in order to provide support for the + * [MSFT_packing_normalRoughnessMetallic](https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Vendor/MSFT_packing_normalRoughnessMetallic/README.md) * glTF extension. * * @see @ref hasMetalnessTexture(), @ref hasRoughnessTexture(), @@ -297,6 +314,36 @@ class MAGNUM_TRADE_EXPORT PbrMetallicRoughnessMaterialData: public MaterialData */ bool hasCommonTextureCoordinates() const; + /** + * @brief Whether the material uses array texture layers + * + * Returns @cpp true @ce if any of the + * @ref MaterialAttribute::BaseColorTextureLayer, + * @ref MaterialAttribute::MetalnessTextureLayer, + * @ref MaterialAttribute::RoughnessTextureLayer, + * @ref MaterialAttribute::NormalTextureLayer, + * @ref MaterialAttribute::OcclusionTextureLayer, + * @ref MaterialAttribute::EmissiveTextureLayer or + * @ref MaterialAttribute::TextureLayer attributes is present and has a + * non-zero value, @cpp false @ce otherwise. + * @see @ref hasCommonTextureLayer() + */ + bool hasTextureLayer() const; + + /** + * @brief Whether the material has a common array texture layer for all textures + * + * Returns @cpp true @ce if, for each texture that is present, + * @ref baseColorTextureLayer(), @ref metalnessTextureLayer(), + * @ref roughnessTextureLayer(), @ref normalTextureLayer(), + * @ref occlusionTextureLayer() and @ref emissiveTextureLayer() have + * the same value, @cpp false @ce otherwise. In particular, returns + * @cpp true @ce also if there's no array texture layer used at all. + * Use @ref hasTextureLayer() to distinguish that case. + * @see @ref commonTextureLayer() + */ + bool hasCommonTextureLayer() const; + /** * @brief Base color * @@ -339,6 +386,17 @@ class MAGNUM_TRADE_EXPORT PbrMetallicRoughnessMaterialData: public MaterialData */ UnsignedInt baseColorTextureCoordinates() const; + /** + * @brief Base color array texture layer + * + * Convenience access to the @ref MaterialAttribute::BaseColorTextureLayer + * / @ref MaterialAttribute::TextureLayer attributes. If neither is + * present, the default is @cpp 0 @ce. Available only if the material + * has @ref MaterialAttribute::BaseColorTexture. + * @see @ref hasAttribute() + */ + UnsignedInt baseColorTextureLayer() const; + /** * @brief Metalness factor * @@ -395,6 +453,17 @@ class MAGNUM_TRADE_EXPORT PbrMetallicRoughnessMaterialData: public MaterialData */ UnsignedInt metalnessTextureCoordinates() const; + /** + * @brief Metalness array texture layer + * + * Convenience access to the @ref MaterialAttribute::MetalnessTextureLayer + * / @ref MaterialAttribute::TextureLayer attributes. If neither is + * present, the default is @cpp 0 @ce. Available only if the material + * has a metalness texture. + * @see @ref hasMetalnessTexture() + */ + UnsignedInt metalnessTextureLayer() const; + /** * @brief Roughness factor * @@ -451,6 +520,17 @@ class MAGNUM_TRADE_EXPORT PbrMetallicRoughnessMaterialData: public MaterialData */ UnsignedInt roughnessTextureCoordinates() const; + /** + * @brief Roughness array texture layer + * + * Convenience access to the @ref MaterialAttribute::RoughnessTextureLayer + * / @ref MaterialAttribute::TextureLayer attributes. If neither is + * present, the default is @cpp 0 @ce. Available only if the material + * has a roughness texture. + * @see @ref hasRoughnessTexture() + */ + UnsignedInt roughnessTextureLayer() const; + /** * @brief Normal texture ID * @@ -503,6 +583,17 @@ class MAGNUM_TRADE_EXPORT PbrMetallicRoughnessMaterialData: public MaterialData */ UnsignedInt normalTextureCoordinates() const; + /** + * @brief Normal array texture layer + * + * Convenience access to the @ref MaterialAttribute::NormalTextureLayer + * / @ref MaterialAttribute::TextureLayer attributes. If neither is + * present, the default is @cpp 0 @ce. Available only if the material + * has @ref MaterialAttribute::NormalTexture. + * @see @ref hasAttribute() + */ + UnsignedInt normalTextureLayer() const; + /** * @brief Occlusion texture ID * @@ -555,6 +646,17 @@ class MAGNUM_TRADE_EXPORT PbrMetallicRoughnessMaterialData: public MaterialData */ UnsignedInt occlusionTextureCoordinates() const; + /** + * @brief Occlusion array texture layer + * + * Convenience access to the @ref MaterialAttribute::OcclusionTextureLayer + * / @ref MaterialAttribute::TextureLayer attributes. If neither is + * present, the default is @cpp 0 @ce. Available only if the material + * has @ref MaterialAttribute::OcclusionTexture. + * @see @ref hasAttribute() + */ + UnsignedInt occlusionTextureLayer() const; + /** * @brief Emissive color * @@ -600,6 +702,17 @@ class MAGNUM_TRADE_EXPORT PbrMetallicRoughnessMaterialData: public MaterialData */ UnsignedInt emissiveTextureCoordinates() const; + /** + * @brief Emissive array texture layer + * + * Convenience access to the @ref MaterialAttribute::EmissiveTextureLayer + * / @ref MaterialAttribute::TextureLayer attributes. If neither is + * present, the default is @cpp 0 @ce. Available only if the material + * has @ref MaterialAttribute::EmissiveTexture. + * @see @ref hasAttribute() + */ + UnsignedInt emissiveTextureLayer() const; + /** * @brief Common texture coordinate transformation matrix for all textures * @@ -625,6 +738,18 @@ class MAGNUM_TRADE_EXPORT PbrMetallicRoughnessMaterialData: public MaterialData * @cpp 0 @ce. */ UnsignedInt commonTextureCoordinates() const; + + /** + * @brief Common array texture layer for all textures + * + * Expects that @ref hasCommonTextureLayer() is @cpp true @ce; returns + * a layer that's the same for all of @ref baseColorTextureLayer(), + * @ref metalnessTextureLayer(), @ref roughnessTextureLayer(), + * @ref normalTextureLayer(), @ref occlusionTextureLayer() and + * @ref emissiveTextureLayer() where a texture is present. If no + * texture is present, returns @cpp 0 @ce. + */ + UnsignedInt commonTextureLayer() const; }; }} diff --git a/src/Magnum/Trade/PbrSpecularGlossinessMaterialData.cpp b/src/Magnum/Trade/PbrSpecularGlossinessMaterialData.cpp index 32f53f820..7f4e7a92d 100644 --- a/src/Magnum/Trade/PbrSpecularGlossinessMaterialData.cpp +++ b/src/Magnum/Trade/PbrSpecularGlossinessMaterialData.cpp @@ -50,7 +50,8 @@ bool PbrSpecularGlossinessMaterialData::hasSpecularGlossinessTexture() const { specularTextureSwizzle() == MaterialTextureSwizzle::RGB && glossinessTextureSwizzle() == MaterialTextureSwizzle::A)) && specularTextureMatrix() == glossinessTextureMatrix() && - specularTextureCoordinates() == glossinessTextureCoordinates(); + specularTextureCoordinates() == glossinessTextureCoordinates() && + specularTextureLayer() == glossinessTextureLayer(); } bool PbrSpecularGlossinessMaterialData::hasTextureTransformation() const { @@ -127,6 +128,43 @@ bool PbrSpecularGlossinessMaterialData::hasCommonTextureCoordinates() const { return true; } +bool PbrSpecularGlossinessMaterialData::hasTextureLayer() const { + return attributeOr(MaterialAttribute::TextureLayer, 0u) || + attributeOr(MaterialAttribute::DiffuseTextureLayer, 0u) || + attributeOr(MaterialAttribute::SpecularTextureLayer, 0u) || + attributeOr(MaterialAttribute::GlossinessTextureLayer, 0u) || + attributeOr(MaterialAttribute::NormalTextureLayer, 0u) || + attributeOr(MaterialAttribute::OcclusionTextureLayer, 0u) || + attributeOr(MaterialAttribute::EmissiveTextureLayer, 0u); +} + +bool PbrSpecularGlossinessMaterialData::hasCommonTextureLayer() const { + auto check = [](Containers::Optional& layer, UnsignedInt current) { + if(!layer) { + layer = current; + return true; + } + return layer == current; + }; + + Containers::Optional layer; + /* First one can't fail */ + if(hasAttribute(MaterialAttribute::DiffuseTexture) && !check(layer, diffuseTextureLayer())) + CORRADE_INTERNAL_ASSERT_UNREACHABLE(); /* LCOV_EXCL_LINE */ + if(hasSpecularTexture() && !check(layer, specularTextureLayer())) + return false; + if(hasGlossinessTexture() && !check(layer, glossinessTextureLayer())) + return false; + if(hasAttribute(MaterialAttribute::NormalTexture) && !check(layer, normalTextureLayer())) + return false; + if(hasAttribute(MaterialAttribute::OcclusionTexture) && !check(layer, occlusionTextureLayer())) + return false; + if(hasAttribute(MaterialAttribute::EmissiveTexture) && !check(layer, emissiveTextureLayer())) + return false; + + return true; +} + Color4 PbrSpecularGlossinessMaterialData::diffuseColor() const { return attributeOr(MaterialAttribute::DiffuseColor, 0xffffffff_srgbaf); } @@ -151,6 +189,14 @@ UnsignedInt PbrSpecularGlossinessMaterialData::diffuseTextureCoordinates() const return attributeOr(MaterialAttribute::TextureCoordinates, 0u); } +UnsignedInt PbrSpecularGlossinessMaterialData::diffuseTextureLayer() const { + CORRADE_ASSERT(hasAttribute(MaterialAttribute::DiffuseTexture), + "Trade::PbrSpecularGlossinessMaterialData::diffuseTextureLayer(): the material doesn't have a diffuse texture", {}); + if(Containers::Optional value = tryAttribute(MaterialAttribute::DiffuseTextureLayer)) + return *value; + return attributeOr(MaterialAttribute::TextureLayer, 0u); +} + Color4 PbrSpecularGlossinessMaterialData::specularColor() const { return attributeOr(MaterialAttribute::SpecularColor, 0xffffff00_srgbaf); } @@ -190,6 +236,14 @@ UnsignedInt PbrSpecularGlossinessMaterialData::specularTextureCoordinates() cons return attributeOr(MaterialAttribute::TextureCoordinates, 0u); } +UnsignedInt PbrSpecularGlossinessMaterialData::specularTextureLayer() const { + CORRADE_ASSERT(hasSpecularTexture(), + "Trade::PbrSpecularGlossinessMaterialData::specularTextureLayer(): the material doesn't have a specular texture", {}); + if(Containers::Optional value = tryAttribute(MaterialAttribute::SpecularTextureLayer)) + return *value; + return attributeOr(MaterialAttribute::TextureLayer, 0u); +} + Float PbrSpecularGlossinessMaterialData::glossiness() const { return attributeOr(MaterialAttribute::Glossiness, 1.0f); } @@ -229,6 +283,14 @@ UnsignedInt PbrSpecularGlossinessMaterialData::glossinessTextureCoordinates() co return attributeOr(MaterialAttribute::TextureCoordinates, 0u); } +UnsignedInt PbrSpecularGlossinessMaterialData::glossinessTextureLayer() const { + CORRADE_ASSERT(hasGlossinessTexture(), + "Trade::PbrSpecularGlossinessMaterialData::glossinessTextureLayer(): the material doesn't have a glossiness texture", {}); + if(Containers::Optional value = tryAttribute(MaterialAttribute::GlossinessTextureLayer)) + return *value; + return attributeOr(MaterialAttribute::TextureLayer, 0u); +} + UnsignedInt PbrSpecularGlossinessMaterialData::normalTexture() const { return attribute(MaterialAttribute::NormalTexture); } @@ -261,6 +323,14 @@ UnsignedInt PbrSpecularGlossinessMaterialData::normalTextureCoordinates() const return attributeOr(MaterialAttribute::TextureCoordinates, 0u); } +UnsignedInt PbrSpecularGlossinessMaterialData::normalTextureLayer() const { + CORRADE_ASSERT(hasAttribute(MaterialAttribute::NormalTexture), + "Trade::PbrSpecularGlossinessMaterialData::normalTextureLayer(): the material doesn't have a normal texture", {}); + if(Containers::Optional value = tryAttribute(MaterialAttribute::NormalTextureLayer)) + return *value; + return attributeOr(MaterialAttribute::TextureLayer, 0u); +} + UnsignedInt PbrSpecularGlossinessMaterialData::occlusionTexture() const { return attribute(MaterialAttribute::OcclusionTexture); } @@ -293,6 +363,14 @@ UnsignedInt PbrSpecularGlossinessMaterialData::occlusionTextureCoordinates() con return attributeOr(MaterialAttribute::TextureCoordinates, 0u); } +UnsignedInt PbrSpecularGlossinessMaterialData::occlusionTextureLayer() const { + CORRADE_ASSERT(hasAttribute(MaterialAttribute::OcclusionTexture), + "Trade::PbrSpecularGlossinessMaterialData::occlusionTextureLayer(): the material doesn't have an occlusion texture", {}); + if(Containers::Optional value = tryAttribute(MaterialAttribute::OcclusionTextureLayer)) + return *value; + return attributeOr(MaterialAttribute::TextureLayer, 0u); +} + Color3 PbrSpecularGlossinessMaterialData::emissiveColor() const { return attributeOr(MaterialAttribute::EmissiveColor, 0x000000_srgbf); } @@ -317,6 +395,14 @@ UnsignedInt PbrSpecularGlossinessMaterialData::emissiveTextureCoordinates() cons return attributeOr(MaterialAttribute::TextureCoordinates, 0u); } +UnsignedInt PbrSpecularGlossinessMaterialData::emissiveTextureLayer() const { + CORRADE_ASSERT(hasAttribute(MaterialAttribute::EmissiveTexture), + "Trade::PbrSpecularGlossinessMaterialData::emissiveTextureLayer(): the material doesn't have an emissive texture", {}); + if(Containers::Optional value = tryAttribute(MaterialAttribute::EmissiveTextureLayer)) + return *value; + return attributeOr(MaterialAttribute::TextureLayer, 0u); +} + Matrix3 PbrSpecularGlossinessMaterialData::commonTextureMatrix() const { CORRADE_ASSERT(hasCommonTextureTransformation(), "Trade::PbrSpecularGlossinessMaterialData::commonTextureMatrix(): the material doesn't have a common texture coordinate transformation", {}); @@ -353,4 +439,22 @@ UnsignedInt PbrSpecularGlossinessMaterialData::commonTextureCoordinates() const return attributeOr(MaterialAttribute::TextureCoordinates, 0u); } +UnsignedInt PbrSpecularGlossinessMaterialData::commonTextureLayer() const { + CORRADE_ASSERT(hasCommonTextureLayer(), + "Trade::PbrSpecularGlossinessMaterialData::commonTextureLayer(): the material doesn't have a common array texture layer", {}); + if(hasAttribute(MaterialAttribute::DiffuseTexture)) + return diffuseTextureLayer(); + if(hasSpecularTexture()) + return specularTextureLayer(); + if(hasGlossinessTexture()) + return glossinessTextureLayer(); + if(hasAttribute(MaterialAttribute::NormalTexture)) + return normalTextureLayer(); + if(hasAttribute(MaterialAttribute::OcclusionTexture)) + return occlusionTextureLayer(); + if(hasAttribute(MaterialAttribute::EmissiveTexture)) + return emissiveTextureLayer(); + return attributeOr(MaterialAttribute::TextureLayer, 0u); +} + }} diff --git a/src/Magnum/Trade/PbrSpecularGlossinessMaterialData.h b/src/Magnum/Trade/PbrSpecularGlossinessMaterialData.h index 650edb298..e3753fb12 100644 --- a/src/Magnum/Trade/PbrSpecularGlossinessMaterialData.h +++ b/src/Magnum/Trade/PbrSpecularGlossinessMaterialData.h @@ -90,16 +90,20 @@ class MAGNUM_TRADE_EXPORT PbrSpecularGlossinessMaterialData: public MaterialData * is set to @ref MaterialTextureSwizzle::A, and ddditionally * @ref MaterialAttribute::SpecularTextureMatrix and * @ref MaterialAttribute::GlossinessTextureMatrix are both either not - * present or have the same value, and + * present or have the same value, * @ref MaterialAttribute::SpecularTextureCoordinates and * @ref MaterialAttribute::GlossinessTextureCoordinates are both either - * not present or have the same value; @cpp false @ce otherwise. + * not present or have the same value, and + * @ref MaterialAttribute::SpecularTextureLayer and + * @ref MaterialAttribute::GlossinessTextureLayer are both either not + * present or have the same value; @cpp false @ce otherwise. * * In other words, if this function returns @cpp true @ce, - * @ref specularTexture(), @ref specularTextureMatrix() and - * @ref specularTextureCoordinates() return values common for both - * specular and glossiness texture, and the two are packed together - * with specular occupying the RGB channels and glossiness the alpha. + * @ref specularTexture(), @ref specularTextureMatrix(), + * @ref specularTextureCoordinates() and @ref specularTextureLayer() + * return values common for both specular and glossiness texture, and + * the two are packed together with specular occupying the RGB channels + * and glossiness the alpha. * @see @ref hasSpecularTexture(), @ref hasGlossinessTexture() */ bool hasSpecularGlossinessTexture() const; @@ -165,6 +169,36 @@ class MAGNUM_TRADE_EXPORT PbrSpecularGlossinessMaterialData: public MaterialData */ bool hasCommonTextureCoordinates() const; + /** + * @brief Whether the material uses array texture layers + * + * Returns @cpp true @ce if any of the + * @ref MaterialAttribute::DiffuseTextureLayer, + * @ref MaterialAttribute::SpecularTextureLayer, + * @ref MaterialAttribute::GlossinessTextureLayer, + * @ref MaterialAttribute::NormalTextureLayer, + * @ref MaterialAttribute::OcclusionTextureLayer, + * @ref MaterialAttribute::EmissiveTextureLayer or + * @ref MaterialAttribute::TextureLayer attributes is present and has a + * non-zero value, @cpp false @ce otherwise. + * @see @ref hasCommonTextureLayer() + */ + bool hasTextureLayer() const; + + /** + * @brief Whether the material has a common array texture layer for all textures + * + * Returns @cpp true @ce if, for each texture that is present, + * @ref diffuseTextureLayer(), @ref specularTextureLayer(), + * @ref glossinessTextureLayer(), @ref normalTextureLayer(), + * @ref occlusionTextureLayer() and @ref emissiveTextureLayer() have + * the same value, @cpp false @ce otherwise. In particular, returns + * @cpp true @ce also if there's no array texture layer used at all. + * Use @ref hasTextureLayer() to distinguish that case. + * @see @ref commonTextureLayer() + */ + bool hasCommonTextureLayer() const; + /** * @brief Diffuse color * @@ -207,6 +241,17 @@ class MAGNUM_TRADE_EXPORT PbrSpecularGlossinessMaterialData: public MaterialData */ UnsignedInt diffuseTextureCoordinates() const; + /** + * @brief Diffuse array texture layer + * + * Convenience access to the @ref MaterialAttribute::DiffuseTextureLayer + * / @ref MaterialAttribute::TextureLayer attributes. If neither is + * present, the default is @cpp 0 @ce. Available only if the material + * has @ref MaterialAttribute::DiffuseTexture. + * @see @ref hasAttribute() + */ + UnsignedInt diffuseTextureLayer() const; + /** * @brief Specular color * @@ -263,6 +308,17 @@ class MAGNUM_TRADE_EXPORT PbrSpecularGlossinessMaterialData: public MaterialData */ UnsignedInt specularTextureCoordinates() const; + /** + * @brief Specular array texture layer + * + * Convenience access to the @ref MaterialAttribute::SpecularTextureLayer + * / @ref MaterialAttribute::TextureLayer attributes. If neither is + * present, the default is @cpp 0 @ce. Available only if the material + * has a specular texture. + * @see @ref hasSpecularTexture() + */ + UnsignedInt specularTextureLayer() const; + /** * @brief Glossiness factor * @@ -319,6 +375,17 @@ class MAGNUM_TRADE_EXPORT PbrSpecularGlossinessMaterialData: public MaterialData */ UnsignedInt glossinessTextureCoordinates() const; + /** + * @brief Glossiness array texture layer + * + * Convenience access to the @ref MaterialAttribute::GlossinessTextureLayer + * / @ref MaterialAttribute::TextureLayer attributes. If neither is + * present, the default is @cpp 0 @ce. Available only if the material + * has a glossiness texture. + * @see @ref hasGlossinessTexture() + */ + UnsignedInt glossinessTextureLayer() const; + /** * @brief Normal texture ID * @@ -370,6 +437,17 @@ class MAGNUM_TRADE_EXPORT PbrSpecularGlossinessMaterialData: public MaterialData */ UnsignedInt normalTextureCoordinates() const; + /** + * @brief Normal array texture layer + * + * Convenience access to the @ref MaterialAttribute::NormalTextureLayer + * / @ref MaterialAttribute::TextureLayer attributes. If neither is + * present, the default is @cpp 0 @ce. Available only if the material + * has @ref MaterialAttribute::NormalTexture. + * @see @ref hasAttribute() + */ + UnsignedInt normalTextureLayer() const; + /** * @brief Occlusion texture ID * @@ -422,6 +500,17 @@ class MAGNUM_TRADE_EXPORT PbrSpecularGlossinessMaterialData: public MaterialData */ UnsignedInt occlusionTextureCoordinates() const; + /** + * @brief Occlusion array texture layer + * + * Convenience access to the @ref MaterialAttribute::OcclusionTextureLayer + * / @ref MaterialAttribute::TextureLayer attributes. If neither is + * present, the default is @cpp 0 @ce. Available only if the material + * has @ref MaterialAttribute::OcclusionTexture. + * @see @ref hasAttribute() + */ + UnsignedInt occlusionTextureLayer() const; + /** * @brief Emissive color * @@ -467,6 +556,17 @@ class MAGNUM_TRADE_EXPORT PbrSpecularGlossinessMaterialData: public MaterialData */ UnsignedInt emissiveTextureCoordinates() const; + /** + * @brief Emissive array texture layer + * + * Convenience access to the @ref MaterialAttribute::EmissiveTextureLayer + * / @ref MaterialAttribute::TextureLayer attributes. If neither is + * present, the default is @cpp 0 @ce. Available only if the + * material has @ref MaterialAttribute::EmissiveTexture. + * @see @ref hasAttribute() + */ + UnsignedInt emissiveTextureLayer() const; + /** * @brief Common texture coordinate transformation matrix for all textures * @@ -492,6 +592,18 @@ class MAGNUM_TRADE_EXPORT PbrSpecularGlossinessMaterialData: public MaterialData * no texture is present, returns @cpp 0 @ce. */ UnsignedInt commonTextureCoordinates() const; + + /** + * @brief Common array texture layer for all textures + * + * Expects that @ref hasCommonTextureLayer() is @cpp true @ce; returns + * a layer that's the same for all of @ref diffuseTextureLayer(), + * @ref specularTextureLayer(), @ref glossinessTextureLayer(), + * @ref normalTextureLayer(), @ref occlusionTextureLayer() and + * @ref emissiveTextureLayer() where a texture is present. If no + * texture is present, returns @cpp 0 @ce. + */ + UnsignedInt commonTextureLayer() const; }; }} diff --git a/src/Magnum/Trade/PhongMaterialData.cpp b/src/Magnum/Trade/PhongMaterialData.cpp index 9dbba317c..0c0eb576b 100644 --- a/src/Magnum/Trade/PhongMaterialData.cpp +++ b/src/Magnum/Trade/PhongMaterialData.cpp @@ -196,6 +196,37 @@ bool PhongMaterialData::hasCommonTextureCoordinates() const { return true; } +bool PhongMaterialData::hasTextureLayer() const { + return attributeOr(MaterialAttribute::AmbientTextureLayer, 0u) || + attributeOr(MaterialAttribute::DiffuseTextureLayer, 0u) || + attributeOr(MaterialAttribute::SpecularTextureLayer, 0u) || + attributeOr(MaterialAttribute::NormalTextureLayer, 0u) || + attributeOr(MaterialAttribute::TextureLayer, 0u); +} + +bool PhongMaterialData::hasCommonTextureLayer() const { + auto check = [](Containers::Optional& layer, UnsignedInt current) { + if(!layer) { + layer = current; + return true; + } + return layer == current; + }; + + Containers::Optional layer; + /* First one can't fail */ + if(hasAttribute(MaterialAttribute::AmbientTexture) && !check(layer, ambientTextureLayer())) + CORRADE_INTERNAL_ASSERT_UNREACHABLE(); /* LCOV_EXCL_LINE */ + if(hasAttribute(MaterialAttribute::DiffuseTexture) && !check(layer, diffuseTextureLayer())) + return false; + if(hasSpecularTexture() && !check(layer, specularTextureLayer())) + return false; + if(hasAttribute(MaterialAttribute::NormalTexture) && !check(layer, normalTextureLayer())) + return false; + + return true; +} + Color4 PhongMaterialData::ambientColor() const { return attributeOr(MaterialAttribute::AmbientColor, hasAttribute(MaterialAttribute::AmbientTexture) ? 0xffffffff_rgbaf : 0x000000ff_rgbaf); @@ -221,6 +252,14 @@ UnsignedInt PhongMaterialData::ambientTextureCoordinates() const { return attributeOr(MaterialAttribute::TextureCoordinates, 0u); } +UnsignedInt PhongMaterialData::ambientTextureLayer() const { + CORRADE_ASSERT(hasAttribute(MaterialAttribute::AmbientTexture), + "Trade::PhongMaterialData::ambientTextureLayer(): the material doesn't have an ambient texture", {}); + if(Containers::Optional set = tryAttribute(MaterialAttribute::AmbientTextureLayer)) + return *set; + return attributeOr(MaterialAttribute::TextureLayer, 0u); +} + Color4 PhongMaterialData::diffuseColor() const { return attributeOr(MaterialAttribute::DiffuseColor, 0xffffffff_rgbaf); } @@ -245,6 +284,14 @@ UnsignedInt PhongMaterialData::diffuseTextureCoordinates() const { return attributeOr(MaterialAttribute::TextureCoordinates, 0u); } +UnsignedInt PhongMaterialData::diffuseTextureLayer() const { + CORRADE_ASSERT(hasAttribute(MaterialAttribute::DiffuseTexture), + "Trade::PhongMaterialData::diffuseTextureLayer(): the material doesn't have a diffuse texture", {}); + if(Containers::Optional set = tryAttribute(MaterialAttribute::DiffuseTextureLayer)) + return *set; + return attributeOr(MaterialAttribute::TextureLayer, 0u); +} + Color4 PhongMaterialData::specularColor() const { return attributeOr(MaterialAttribute::SpecularColor, 0xffffff00_rgbaf); } @@ -284,6 +331,14 @@ UnsignedInt PhongMaterialData::specularTextureCoordinates() const { return attributeOr(MaterialAttribute::TextureCoordinates, 0u); } +UnsignedInt PhongMaterialData::specularTextureLayer() const { + CORRADE_ASSERT(hasSpecularTexture(), + "Trade::PhongMaterialData::specularTextureLayer(): the material doesn't have a specular texture", {}); + if(Containers::Optional set = tryAttribute(MaterialAttribute::SpecularTextureLayer)) + return *set; + return attributeOr(MaterialAttribute::TextureLayer, 0u); +} + UnsignedInt PhongMaterialData::normalTexture() const { return attribute(MaterialAttribute::NormalTexture); } @@ -316,6 +371,14 @@ UnsignedInt PhongMaterialData::normalTextureCoordinates() const { return attributeOr(MaterialAttribute::TextureCoordinates, 0u); } +UnsignedInt PhongMaterialData::normalTextureLayer() const { + CORRADE_ASSERT(hasAttribute(MaterialAttribute::NormalTexture), + "Trade::PhongMaterialData::normalTextureLayer(): the material doesn't have a normal texture", {}); + if(Containers::Optional set = tryAttribute(MaterialAttribute::NormalTextureLayer)) + return *set; + return attributeOr(MaterialAttribute::TextureLayer, 0u); +} + Matrix3 PhongMaterialData::commonTextureMatrix() const { CORRADE_ASSERT(hasCommonTextureTransformation(), "Trade::PhongMaterialData::commonTextureMatrix(): the material doesn't have a common texture coordinate transformation", {}); @@ -351,6 +414,20 @@ UnsignedInt PhongMaterialData::commonTextureCoordinates() const { return attributeOr(MaterialAttribute::TextureCoordinates, 0u); } +UnsignedInt PhongMaterialData::commonTextureLayer() const { + CORRADE_ASSERT(hasCommonTextureLayer(), + "Trade::PhongMaterialData::commonTextureLayer(): the material doesn't have a common array texture layer", {}); + if(hasAttribute(MaterialAttribute::AmbientTexture)) + return ambientTextureLayer(); + if(hasAttribute(MaterialAttribute::DiffuseTexture)) + return diffuseTextureLayer(); + if(hasSpecularTexture()) + return specularTextureLayer(); + if(hasAttribute(MaterialAttribute::NormalTexture)) + return normalTextureLayer(); + return attributeOr(MaterialAttribute::TextureLayer, 0u); +} + Float PhongMaterialData::shininess() const { return attributeOr(MaterialAttribute::Shininess, 80.0f); } diff --git a/src/Magnum/Trade/PhongMaterialData.h b/src/Magnum/Trade/PhongMaterialData.h index 5bdfdff88..c373fa2d0 100644 --- a/src/Magnum/Trade/PhongMaterialData.h +++ b/src/Magnum/Trade/PhongMaterialData.h @@ -301,6 +301,35 @@ class MAGNUM_TRADE_EXPORT PhongMaterialData: public MaterialData { */ bool hasCommonTextureCoordinates() const; + /** + * @brief Whether the material uses array texture layers + * @m_since_latest + * + * Returns @cpp true @ce if any of the + * @ref MaterialAttribute::AmbientTextureLayer, + * @ref MaterialAttribute::DiffuseTextureLayer, + * @ref MaterialAttribute::SpecularTextureLayer, + * @ref MaterialAttribute::NormalTextureLayer or + * @ref MaterialAttribute::TextureLayer attributes is present and has a + * non-zero value, @cpp false @ce otherwise. + * @see @ref hasCommonTextureLayer() + */ + bool hasTextureLayer() const; + + /** + * @brief Whether the material has a common array texture layer for all textures + * @m_since_latest + * + * Returns @cpp true @ce if, for each texture that is present, + * @ref ambientTextureLayer(), @ref diffuseTextureLayer(), + * @ref specularTextureLayer() and @ref normalTextureLayer() have the + * same value, @cpp false @ce otherwise. In particular, returns + * @cpp true @ce also if there's no extra texture coordinate set used + * at all. Use @ref hasTextureLayer() to distinguish that case. + * @see @ref commonTextureLayer() + */ + bool hasCommonTextureLayer() const; + #ifdef MAGNUM_BUILD_DEPRECATED /** * @brief Material flags @@ -376,6 +405,18 @@ class MAGNUM_TRADE_EXPORT PhongMaterialData: public MaterialData { } #endif + /** + * @brief Ambient array texture layer + * @m_since_latest + * + * Convenience access to the @ref MaterialAttribute::AmbientTextureLayer + * / @ref MaterialAttribute::TextureLayer attributes. If neither is + * present, the default is @cpp 0 @ce. Available only if the material + * has @ref MaterialAttribute::AmbientTexture. + * @see @ref hasAttribute() + */ + UnsignedInt ambientTextureLayer() const; + /** * @brief Diffuse color * @@ -432,6 +473,18 @@ class MAGNUM_TRADE_EXPORT PhongMaterialData: public MaterialData { } #endif + /** + * @brief Diffuse array texture layer + * @m_since_latest + * + * Convenience access to the @ref MaterialAttribute::DiffuseTextureLayer + * / @ref MaterialAttribute::TextureLayer attributes. If neither is + * present, the default is @cpp 0 @ce. Available only if the material + * has @ref MaterialAttribute::DiffuseTexture. + * @see @ref hasAttribute() + */ + UnsignedInt diffuseTextureLayer() const; + /** * @brief Specular color * @@ -502,6 +555,18 @@ class MAGNUM_TRADE_EXPORT PhongMaterialData: public MaterialData { } #endif + /** + * @brief Specular array texture layer + * @m_since_latest + * + * Convenience access to the @ref MaterialAttribute::SpecularTextureLayer + * / @ref MaterialAttribute::TextureLayer attributes. If neither is + * present, the default is @cpp 0 @ce. Available only if the material + * has a specular texture. + * @see @ref hasSpecularTexture() + */ + UnsignedInt specularTextureLayer() const; + /** * @brief Normal texture ID * @m_since{2020,06} @@ -569,6 +634,18 @@ class MAGNUM_TRADE_EXPORT PhongMaterialData: public MaterialData { } #endif + /** + * @brief Normal array texture layer + * @m_since_latest + * + * Convenience access to the @ref MaterialAttribute::NormalTextureLayer + * / @ref MaterialAttribute::TextureLayer attributes. If neither is + * present, the default is @cpp 0 @ce. Available only if the material + * has @ref MaterialAttribute::NormalTexture. + * @see @ref hasAttribute() + */ + UnsignedInt normalTextureLayer() const; + /** * @brief Common texture coordinate transformation matrix for all textures * @m_since_latest @@ -609,6 +686,18 @@ class MAGNUM_TRADE_EXPORT PhongMaterialData: public MaterialData { */ UnsignedInt commonTextureCoordinates() const; + /** + * @brief Common array texture layer for all textures + * @m_since_latest + * + * Expects that @ref hasCommonTextureLayer() is @cpp true @ce; returns + * a layer that's the same for all of @ref ambientTextureLayer(), + * @ref diffuseTextureLayer(), @ref specularTextureLayer() and + * @ref normalTextureLayer() where a texture is present. If no texture + * is present, returns @cpp 0 @ce. + */ + UnsignedInt commonTextureLayer() const; + /** * @brief Shininess * diff --git a/src/Magnum/Trade/Test/FlatMaterialDataTest.cpp b/src/Magnum/Trade/Test/FlatMaterialDataTest.cpp index 999b9b9d3..b25d3bd0c 100644 --- a/src/Magnum/Trade/Test/FlatMaterialDataTest.cpp +++ b/src/Magnum/Trade/Test/FlatMaterialDataTest.cpp @@ -43,10 +43,10 @@ class FlatMaterialDataTest: public TestSuite::Tester { void texturedBaseColor(); void texturedDiffuseColor(); void texturedDefaults(); - void texturedBaseColorSingleMatrixCoordinates(); - void texturedDiffuseColorSingleMatrixCoordinates(); - void texturedMismatchedMatrixCoordinates(); - void texturedImplicitCoordinates(); + void texturedBaseColorSingleMatrixCoordinatesLayer(); + void texturedDiffuseColorSingleMatrixCoordinatesLayer(); + void texturedMismatchedMatrixCoordinatesLayer(); + void texturedImplicitCoordinatesLayer(); void invalidTextures(); }; @@ -57,10 +57,10 @@ FlatMaterialDataTest::FlatMaterialDataTest() { &FlatMaterialDataTest::texturedBaseColor, &FlatMaterialDataTest::texturedDiffuseColor, &FlatMaterialDataTest::texturedDefaults, - &FlatMaterialDataTest::texturedBaseColorSingleMatrixCoordinates, - &FlatMaterialDataTest::texturedDiffuseColorSingleMatrixCoordinates, - &FlatMaterialDataTest::texturedMismatchedMatrixCoordinates, - &FlatMaterialDataTest::texturedImplicitCoordinates, + &FlatMaterialDataTest::texturedBaseColorSingleMatrixCoordinatesLayer, + &FlatMaterialDataTest::texturedDiffuseColorSingleMatrixCoordinatesLayer, + &FlatMaterialDataTest::texturedMismatchedMatrixCoordinatesLayer, + &FlatMaterialDataTest::texturedImplicitCoordinatesLayer, &FlatMaterialDataTest::invalidTextures}); } @@ -78,6 +78,7 @@ void FlatMaterialDataTest::baseColor() { CORRADE_VERIFY(!data.hasTexture()); CORRADE_VERIFY(!data.hasTextureTransformation()); CORRADE_VERIFY(!data.hasTextureCoordinates()); + CORRADE_VERIFY(!data.hasTextureLayer()); CORRADE_COMPARE(data.color(), 0xccffbb_rgbf); } @@ -92,6 +93,7 @@ void FlatMaterialDataTest::diffuseColor() { CORRADE_VERIFY(!data.hasTexture()); CORRADE_VERIFY(!data.hasTextureTransformation()); CORRADE_VERIFY(!data.hasTextureCoordinates()); + CORRADE_VERIFY(!data.hasTextureLayer()); CORRADE_COMPARE(data.color(), 0xccffbb_rgbf); } @@ -105,6 +107,7 @@ void FlatMaterialDataTest::defaults() { CORRADE_VERIFY(!data.hasTexture()); CORRADE_VERIFY(!data.hasTextureTransformation()); CORRADE_VERIFY(!data.hasTextureCoordinates()); + CORRADE_VERIFY(!data.hasTextureLayer()); CORRADE_COMPARE(data.color(), 0xffffff_rgbf); } @@ -114,21 +117,25 @@ void FlatMaterialDataTest::texturedBaseColor() { {MaterialAttribute::BaseColorTexture, 5u}, {MaterialAttribute::BaseColorTextureMatrix, Matrix3::scaling({0.5f, 1.0f})}, {MaterialAttribute::BaseColorTextureCoordinates, 2u}, + {MaterialAttribute::BaseColorTextureLayer, 17u}, /* All this is ignored */ {MaterialAttribute::DiffuseColor, 0x33556600_rgbaf}, {MaterialAttribute::DiffuseTexture, 6u}, {MaterialAttribute::DiffuseTextureMatrix, Matrix3::translation({0.5f, 1.0f})}, - {MaterialAttribute::DiffuseTextureCoordinates, 3u} + {MaterialAttribute::DiffuseTextureCoordinates, 3u}, + {MaterialAttribute::DiffuseTextureLayer, 66u}, }}; CORRADE_VERIFY(data.hasTexture()); CORRADE_VERIFY(data.hasTextureTransformation()); CORRADE_VERIFY(data.hasTextureCoordinates()); + CORRADE_VERIFY(data.hasTextureLayer()); CORRADE_COMPARE(data.color(), 0xccffbb_rgbf); CORRADE_COMPARE(data.texture(), 5); CORRADE_COMPARE(data.textureMatrix(), Matrix3::scaling({0.5f, 1.0f})); CORRADE_COMPARE(data.textureCoordinates(), 2); + CORRADE_COMPARE(data.textureLayer(), 17); } void FlatMaterialDataTest::texturedDiffuseColor() { @@ -137,6 +144,7 @@ void FlatMaterialDataTest::texturedDiffuseColor() { {MaterialAttribute::DiffuseTexture, 5u}, {MaterialAttribute::DiffuseTextureMatrix, Matrix3::scaling({0.5f, 1.0f})}, {MaterialAttribute::DiffuseTextureCoordinates, 2u}, + {MaterialAttribute::DiffuseTextureLayer, 17u}, /* Ignored, as we have a diffuse texture */ {MaterialAttribute::BaseColor, 0x33556600_rgbaf} @@ -145,10 +153,12 @@ void FlatMaterialDataTest::texturedDiffuseColor() { CORRADE_VERIFY(data.hasTexture()); CORRADE_VERIFY(data.hasTextureTransformation()); CORRADE_VERIFY(data.hasTextureCoordinates()); + CORRADE_VERIFY(data.hasTextureLayer()); CORRADE_COMPARE(data.color(), 0xccffbb_rgbf); CORRADE_COMPARE(data.texture(), 5); CORRADE_COMPARE(data.textureMatrix(), Matrix3::scaling({0.5f, 1.0f})); CORRADE_COMPARE(data.textureCoordinates(), 2); + CORRADE_COMPARE(data.textureLayer(), 17); } void FlatMaterialDataTest::texturedDefaults() { @@ -159,55 +169,65 @@ void FlatMaterialDataTest::texturedDefaults() { CORRADE_VERIFY(data.hasTexture()); CORRADE_VERIFY(!data.hasTextureTransformation()); CORRADE_VERIFY(!data.hasTextureCoordinates()); + CORRADE_VERIFY(!data.hasTextureLayer()); CORRADE_COMPARE(data.color(), 0xffffff_rgbf); CORRADE_COMPARE(data.texture(), 5); CORRADE_COMPARE(data.textureMatrix(), Matrix3{}); CORRADE_COMPARE(data.textureCoordinates(), 0); + CORRADE_COMPARE(data.textureLayer(), 0); } -void FlatMaterialDataTest::texturedBaseColorSingleMatrixCoordinates() { +void FlatMaterialDataTest::texturedBaseColorSingleMatrixCoordinatesLayer() { FlatMaterialData data{{}, { {MaterialAttribute::BaseColor, 0xccffbbff_rgbaf}, {MaterialAttribute::BaseColorTexture, 5u}, {MaterialAttribute::TextureMatrix, Matrix3::scaling({0.5f, 1.0f})}, {MaterialAttribute::TextureCoordinates, 2u}, + {MaterialAttribute::TextureLayer, 17u}, /* This is ignored because it doesn't match the texture */ {MaterialAttribute::DiffuseTextureMatrix, Matrix3::translation({0.5f, 1.0f})}, - {MaterialAttribute::DiffuseTextureCoordinates, 3u} + {MaterialAttribute::DiffuseTextureCoordinates, 3u}, + {MaterialAttribute::DiffuseTextureLayer, 66u}, }}; CORRADE_VERIFY(data.hasTexture()); CORRADE_VERIFY(data.hasTextureTransformation()); CORRADE_VERIFY(data.hasTextureCoordinates()); + CORRADE_VERIFY(data.hasTextureLayer()); CORRADE_COMPARE(data.color(), 0xccffbb_rgbf); CORRADE_COMPARE(data.texture(), 5); CORRADE_COMPARE(data.textureMatrix(), Matrix3::scaling({0.5f, 1.0f})); CORRADE_COMPARE(data.textureCoordinates(), 2); + CORRADE_COMPARE(data.textureLayer(), 17); } -void FlatMaterialDataTest::texturedDiffuseColorSingleMatrixCoordinates() { +void FlatMaterialDataTest::texturedDiffuseColorSingleMatrixCoordinatesLayer() { FlatMaterialData data{{}, { {MaterialAttribute::DiffuseColor, 0xccffbbff_rgbaf}, {MaterialAttribute::DiffuseTexture, 5u}, {MaterialAttribute::TextureMatrix, Matrix3::scaling({0.5f, 1.0f})}, {MaterialAttribute::TextureCoordinates, 2u}, + {MaterialAttribute::TextureLayer, 17u}, /* This is ignored because it doesn't match the texture */ {MaterialAttribute::BaseColorTextureMatrix, Matrix3::translation({0.5f, 1.0f})}, - {MaterialAttribute::BaseColorTextureCoordinates, 3u} + {MaterialAttribute::BaseColorTextureCoordinates, 3u}, + {MaterialAttribute::BaseColorTextureLayer, 66u} }}; CORRADE_VERIFY(data.hasTexture()); CORRADE_VERIFY(data.hasTextureTransformation()); CORRADE_VERIFY(data.hasTextureCoordinates()); + CORRADE_VERIFY(data.hasTextureLayer()); CORRADE_COMPARE(data.color(), 0xccffbb_rgbf); CORRADE_COMPARE(data.texture(), 5); CORRADE_COMPARE(data.textureMatrix(), Matrix3::scaling({0.5f, 1.0f})); CORRADE_COMPARE(data.textureCoordinates(), 2); + CORRADE_COMPARE(data.textureLayer(), 17); } -void FlatMaterialDataTest::texturedMismatchedMatrixCoordinates() { +void FlatMaterialDataTest::texturedMismatchedMatrixCoordinatesLayer() { { FlatMaterialData data{{}, { {MaterialAttribute::BaseColorTexture, 5u}, @@ -216,15 +236,18 @@ void FlatMaterialDataTest::texturedMismatchedMatrixCoordinates() { {MaterialAttribute::DiffuseColor, 0x33556600_rgbaf}, {MaterialAttribute::DiffuseTextureMatrix, Matrix3::scaling({0.5f, 1.0f})}, {MaterialAttribute::DiffuseTextureCoordinates, 2u}, + {MaterialAttribute::DiffuseTextureLayer, 17u}, }}; CORRADE_VERIFY(data.hasTexture()); CORRADE_VERIFY(!data.hasTextureTransformation()); CORRADE_VERIFY(!data.hasTextureCoordinates()); + CORRADE_VERIFY(!data.hasTextureLayer()); CORRADE_COMPARE(data.color(), 0xffffff_rgbf); CORRADE_COMPARE(data.texture(), 5); CORRADE_COMPARE(data.textureMatrix(), Matrix3{}); CORRADE_COMPARE(data.textureCoordinates(), 0); + CORRADE_COMPARE(data.textureLayer(), 0); } { FlatMaterialData data{{}, { {MaterialAttribute::DiffuseTexture, 5u}, @@ -233,43 +256,54 @@ void FlatMaterialDataTest::texturedMismatchedMatrixCoordinates() { {MaterialAttribute::BaseColor, 0x33556600_rgbaf}, {MaterialAttribute::BaseColorTextureMatrix, Matrix3::scaling({0.5f, 1.0f})}, {MaterialAttribute::BaseColorTextureCoordinates, 2u}, + {MaterialAttribute::BaseColorTextureLayer, 17u}, }}; CORRADE_VERIFY(data.hasTexture()); CORRADE_VERIFY(!data.hasTextureTransformation()); CORRADE_VERIFY(!data.hasTextureCoordinates()); + CORRADE_VERIFY(!data.hasTextureLayer()); CORRADE_COMPARE(data.color(), 0xffffff_rgbf); CORRADE_COMPARE(data.texture(), 5); CORRADE_COMPARE(data.textureMatrix(), Matrix3{}); CORRADE_COMPARE(data.textureCoordinates(), 0); + CORRADE_COMPARE(data.textureLayer(), 0); } } -void FlatMaterialDataTest::texturedImplicitCoordinates() { +void FlatMaterialDataTest::texturedImplicitCoordinatesLayer() { { FlatMaterialData data{{}, { {MaterialAttribute::BaseColorTexture, 5u}, {MaterialAttribute::BaseColorTextureCoordinates, 0u}, + {MaterialAttribute::BaseColorTextureLayer, 0u}, /* This is ignored because it doesn't match the texture */ {MaterialAttribute::DiffuseTextureCoordinates, 2u}, + {MaterialAttribute::DiffuseTextureLayer, 17u}, }}; CORRADE_VERIFY(data.hasTexture()); CORRADE_VERIFY(!data.hasTextureCoordinates()); + CORRADE_VERIFY(!data.hasTextureLayer()); CORRADE_COMPARE(data.textureCoordinates(), 0); + CORRADE_COMPARE(data.textureLayer(), 0); } { FlatMaterialData data{{}, { {MaterialAttribute::DiffuseTexture, 5u}, {MaterialAttribute::DiffuseTextureCoordinates, 0u}, + {MaterialAttribute::DiffuseTextureLayer, 0u}, /* This is ignored because it doesn't match the texture */ {MaterialAttribute::BaseColorTextureCoordinates, 2u}, + {MaterialAttribute::BaseColorTextureLayer, 17u}, }}; CORRADE_VERIFY(data.hasTexture()); CORRADE_VERIFY(!data.hasTextureCoordinates()); + CORRADE_VERIFY(!data.hasTextureLayer()); CORRADE_COMPARE(data.textureCoordinates(), 0); + CORRADE_COMPARE(data.textureLayer(), 0); } } @@ -285,10 +319,12 @@ void FlatMaterialDataTest::invalidTextures() { data.texture(); data.textureMatrix(); data.textureCoordinates(); + data.textureLayer(); CORRADE_COMPARE(out.str(), "Trade::FlatMaterialData::texture(): the material doesn't have a texture\n" "Trade::FlatMaterialData::textureMatrix(): the material doesn't have a texture\n" - "Trade::FlatMaterialData::textureCoordinates(): the material doesn't have a texture\n"); + "Trade::FlatMaterialData::textureCoordinates(): the material doesn't have a texture\n" + "Trade::FlatMaterialData::textureLayer(): the material doesn't have a texture\n"); } }}}} diff --git a/src/Magnum/Trade/Test/MaterialDataTest.cpp b/src/Magnum/Trade/Test/MaterialDataTest.cpp index 18d33b997..179ffdba0 100644 --- a/src/Magnum/Trade/Test/MaterialDataTest.cpp +++ b/src/Magnum/Trade/Test/MaterialDataTest.cpp @@ -124,8 +124,8 @@ class MaterialDataTest: public TestSuite::Tester { void accessLayersDefaults(); void accessLayersTextured(); void accessLayersTexturedDefault(); - void accessLayersTexturedSingleMatrixCoordinates(); - void accessLayersTexturedBaseMaterialMatrixCoordinates(); + void accessLayersTexturedSingleMatrixCoordinatesLayer(); + void accessLayersTexturedBaseMaterialMatrixCoordinatesLayer(); void accessLayersInvalidTextures(); void accessLayerLayerNameInBaseMaterial(); @@ -277,8 +277,8 @@ MaterialDataTest::MaterialDataTest() { &MaterialDataTest::accessLayersDefaults, &MaterialDataTest::accessLayersTextured, &MaterialDataTest::accessLayersTexturedDefault, - &MaterialDataTest::accessLayersTexturedSingleMatrixCoordinates, - &MaterialDataTest::accessLayersTexturedBaseMaterialMatrixCoordinates, + &MaterialDataTest::accessLayersTexturedSingleMatrixCoordinatesLayer, + &MaterialDataTest::accessLayersTexturedBaseMaterialMatrixCoordinatesLayer, &MaterialDataTest::accessLayersInvalidTextures, &MaterialDataTest::accessLayerLayerNameInBaseMaterial, @@ -1984,8 +1984,9 @@ void MaterialDataTest::accessLayersTextured() { {MaterialAttribute::LayerFactorTextureSwizzle, MaterialTextureSwizzle::A}, {MaterialAttribute::LayerFactorTextureMatrix, Matrix3::scaling({0.5f, 1.0f})}, {MaterialAttribute::LayerFactorTextureCoordinates, 2u}, + {MaterialAttribute::LayerFactorTextureLayer, 3u}, }, { - 0, 1, 7 + 0, 1, 8 }}; CORRADE_COMPARE(data.layerCount(), 3); @@ -2009,6 +2010,10 @@ void MaterialDataTest::accessLayersTextured() { CORRADE_COMPARE(data.layerFactorTextureCoordinates(2), 2u); CORRADE_COMPARE(data.layerFactorTextureCoordinates("ClearCoat"), 2u); CORRADE_COMPARE(data.layerFactorTextureCoordinates(MaterialLayer::ClearCoat), 2u); + + CORRADE_COMPARE(data.layerFactorTextureLayer(2), 3u); + CORRADE_COMPARE(data.layerFactorTextureLayer("ClearCoat"), 3u); + CORRADE_COMPARE(data.layerFactorTextureLayer(MaterialLayer::ClearCoat), 3u); } void MaterialDataTest::accessLayersTexturedDefault() { @@ -2042,16 +2047,21 @@ void MaterialDataTest::accessLayersTexturedDefault() { CORRADE_COMPARE(data.layerFactorTextureCoordinates(2), 0); CORRADE_COMPARE(data.layerFactorTextureCoordinates("ClearCoat"), 0); CORRADE_COMPARE(data.layerFactorTextureCoordinates(MaterialLayer::ClearCoat), 0); + + CORRADE_COMPARE(data.layerFactorTextureLayer(2), 0); + CORRADE_COMPARE(data.layerFactorTextureLayer("ClearCoat"), 0); + CORRADE_COMPARE(data.layerFactorTextureLayer(MaterialLayer::ClearCoat), 0); } -void MaterialDataTest::accessLayersTexturedSingleMatrixCoordinates() { +void MaterialDataTest::accessLayersTexturedSingleMatrixCoordinatesLayer() { MaterialData data{{}, { {MaterialAttribute::LayerName, "ClearCoat"}, {MaterialAttribute::LayerFactorTexture, 4u}, {MaterialAttribute::TextureMatrix, Matrix3::scaling({0.5f, 1.0f})}, {MaterialAttribute::TextureCoordinates, 2u}, + {MaterialAttribute::TextureLayer, 3u}, }, { - 0, 4 + 0, 5 }}; CORRADE_COMPARE(data.layerFactorTextureMatrix(1), Matrix3::scaling({0.5f, 1.0f})); @@ -2061,17 +2071,22 @@ void MaterialDataTest::accessLayersTexturedSingleMatrixCoordinates() { CORRADE_COMPARE(data.layerFactorTextureCoordinates(1), 2u); CORRADE_COMPARE(data.layerFactorTextureCoordinates("ClearCoat"), 2u); CORRADE_COMPARE(data.layerFactorTextureCoordinates(MaterialLayer::ClearCoat), 2u); + + CORRADE_COMPARE(data.layerFactorTextureLayer(1), 3u); + CORRADE_COMPARE(data.layerFactorTextureLayer("ClearCoat"), 3u); + CORRADE_COMPARE(data.layerFactorTextureLayer(MaterialLayer::ClearCoat), 3u); } -void MaterialDataTest::accessLayersTexturedBaseMaterialMatrixCoordinates() { +void MaterialDataTest::accessLayersTexturedBaseMaterialMatrixCoordinatesLayer() { MaterialData data{{}, { {MaterialAttribute::TextureMatrix, Matrix3::scaling({0.5f, 1.0f})}, {MaterialAttribute::TextureCoordinates, 2u}, + {MaterialAttribute::TextureLayer, 3u}, {MaterialAttribute::LayerName, "ClearCoat"}, {MaterialAttribute::LayerFactorTexture, 4u}, }, { - 2, 4 + 3, 5 }}; CORRADE_COMPARE(data.layerFactorTextureMatrix(1), Matrix3::scaling({0.5f, 1.0f})); @@ -2081,6 +2096,10 @@ void MaterialDataTest::accessLayersTexturedBaseMaterialMatrixCoordinates() { CORRADE_COMPARE(data.layerFactorTextureCoordinates(1), 2u); CORRADE_COMPARE(data.layerFactorTextureCoordinates("ClearCoat"), 2u); CORRADE_COMPARE(data.layerFactorTextureCoordinates(MaterialLayer::ClearCoat), 2u); + + CORRADE_COMPARE(data.layerFactorTextureLayer(1), 3u); + CORRADE_COMPARE(data.layerFactorTextureLayer("ClearCoat"), 3u); + CORRADE_COMPARE(data.layerFactorTextureLayer(MaterialLayer::ClearCoat), 3u); } void MaterialDataTest::accessLayersInvalidTextures() { @@ -2106,6 +2125,9 @@ void MaterialDataTest::accessLayersInvalidTextures() { data.layerFactorTextureCoordinates(1); data.layerFactorTextureCoordinates("ClearCoat"); data.layerFactorTextureCoordinates(MaterialLayer::ClearCoat); + data.layerFactorTextureLayer(1); + data.layerFactorTextureLayer("ClearCoat"); + data.layerFactorTextureLayer(MaterialLayer::ClearCoat); CORRADE_COMPARE(out.str(), "Trade::MaterialData::attribute(): attribute LayerFactorTexture not found in layer 1\n" "Trade::MaterialData::attribute(): attribute LayerFactorTexture not found in layer ClearCoat\n" @@ -2118,7 +2140,10 @@ void MaterialDataTest::accessLayersInvalidTextures() { "Trade::MaterialData::layerFactorTextureMatrix(): layer ClearCoat doesn't have a factor texture\n" "Trade::MaterialData::layerFactorTextureCoordinates(): layer 1 doesn't have a factor texture\n" "Trade::MaterialData::layerFactorTextureCoordinates(): layer ClearCoat doesn't have a factor texture\n" - "Trade::MaterialData::layerFactorTextureCoordinates(): layer ClearCoat doesn't have a factor texture\n"); + "Trade::MaterialData::layerFactorTextureCoordinates(): layer ClearCoat doesn't have a factor texture\n" + "Trade::MaterialData::layerFactorTextureLayer(): layer 1 doesn't have a factor texture\n" + "Trade::MaterialData::layerFactorTextureLayer(): layer ClearCoat doesn't have a factor texture\n" + "Trade::MaterialData::layerFactorTextureLayer(): layer ClearCoat doesn't have a factor texture\n"); } void MaterialDataTest::accessLayerLayerNameInBaseMaterial() { @@ -2359,6 +2384,7 @@ void MaterialDataTest::accessLayerOutOfBounds() { data.layerFactorTextureSwizzle(2); data.layerFactorTextureMatrix(2); data.layerFactorTextureCoordinates(2); + data.layerFactorTextureLayer(2); data.attributeCount(2); data.hasAttribute(2, "AlphaMask"); data.hasAttribute(2, MaterialAttribute::AlphaMask); @@ -2395,6 +2421,7 @@ void MaterialDataTest::accessLayerOutOfBounds() { "Trade::MaterialData::layerFactorTextureSwizzle(): index 2 out of range for 2 layers\n" "Trade::MaterialData::layerFactorTextureMatrix(): index 2 out of range for 2 layers\n" "Trade::MaterialData::layerFactorTextureCoordinates(): index 2 out of range for 2 layers\n" + "Trade::MaterialData::layerFactorTextureLayer(): index 2 out of range for 2 layers\n" "Trade::MaterialData::attributeCount(): index 2 out of range for 2 layers\n" "Trade::MaterialData::hasAttribute(): index 2 out of range for 2 layers\n" "Trade::MaterialData::hasAttribute(): index 2 out of range for 2 layers\n" @@ -2444,6 +2471,7 @@ void MaterialDataTest::accessLayerNotFound() { data.layerFactorTextureSwizzle("ClearCoat"); data.layerFactorTextureMatrix("ClearCoat"); data.layerFactorTextureCoordinates("ClearCoat"); + data.layerFactorTextureLayer("ClearCoat"); data.attributeCount("ClearCoat"); data.hasAttribute("ClearCoat", "AlphaMask"); data.hasAttribute("ClearCoat", MaterialAttribute::AlphaMask); @@ -2480,6 +2508,7 @@ void MaterialDataTest::accessLayerNotFound() { "Trade::MaterialData::layerFactorTextureSwizzle(): layer ClearCoat not found\n" "Trade::MaterialData::layerFactorTextureMatrix(): layer ClearCoat not found\n" "Trade::MaterialData::layerFactorTextureCoordinates(): layer ClearCoat not found\n" + "Trade::MaterialData::layerFactorTextureLayer(): layer ClearCoat not found\n" "Trade::MaterialData::attributeCount(): layer ClearCoat not found\n" "Trade::MaterialData::hasAttribute(): layer ClearCoat not found\n" "Trade::MaterialData::hasAttribute(): layer ClearCoat not found\n" @@ -2527,6 +2556,7 @@ void MaterialDataTest::accessInvalidLayerName() { data.layerFactorTextureSwizzle(MaterialLayer(0xfefe)); data.layerFactorTextureMatrix(MaterialLayer(0xfefe)); data.layerFactorTextureCoordinates(MaterialLayer(0xfefe)); + data.layerFactorTextureLayer(MaterialLayer(0xfefe)); data.attributeCount(MaterialLayer(0xfefe)); data.hasAttribute(MaterialLayer(0xfefe), "AlphaMask"); data.hasAttribute(MaterialLayer(0xfefe), MaterialAttribute::AlphaMask); @@ -2564,6 +2594,7 @@ void MaterialDataTest::accessInvalidLayerName() { "Trade::MaterialData::layerFactorTextureSwizzle(): invalid name Trade::MaterialLayer(0xfefe)\n" "Trade::MaterialData::layerFactorTextureMatrix(): invalid name Trade::MaterialLayer(0xfefe)\n" "Trade::MaterialData::layerFactorTextureCoordinates(): invalid name Trade::MaterialLayer(0xfefe)\n" + "Trade::MaterialData::layerFactorTextureLayer(): invalid name Trade::MaterialLayer(0xfefe)\n" "Trade::MaterialData::attributeCount(): invalid name Trade::MaterialLayer(0xfefe)\n" "Trade::MaterialData::hasAttribute(): invalid name Trade::MaterialLayer(0xfefe)\n" "Trade::MaterialData::hasAttribute(): invalid name Trade::MaterialLayer(0xfefe)\n" @@ -2910,7 +2941,8 @@ void MaterialDataTest::templateLayerAccess() { {MaterialAttribute::LayerFactorTextureSwizzle, MaterialTextureSwizzle::B}, {MaterialAttribute::LayerFactorTextureMatrix, Matrix3::scaling({0.5f, 1.0f})}, {MaterialAttribute::LayerFactorTextureCoordinates, 4u}, - }, {1, 7}}; + {MaterialAttribute::LayerFactorTextureLayer, 5u}, + }, {1, 8}}; CORRADE_COMPARE(data.layerName(), "ClearCoat"); CORRADE_COMPARE(data.layerFactor(), 0.35f); @@ -2918,8 +2950,9 @@ void MaterialDataTest::templateLayerAccess() { CORRADE_COMPARE(data.layerFactorTextureSwizzle(), MaterialTextureSwizzle::B); CORRADE_COMPARE(data.layerFactorTextureMatrix(), Matrix3::scaling({0.5f, 1.0f})); CORRADE_COMPARE(data.layerFactorTextureCoordinates(), 4u); + CORRADE_COMPARE(data.layerFactorTextureLayer(), 5u); - CORRADE_COMPARE(data.attributeCount(), 6); + CORRADE_COMPARE(data.attributeCount(), 7); CORRADE_VERIFY(data.hasAttribute(MaterialAttribute::LayerFactor)); CORRADE_VERIFY(data.hasAttribute("LayerFactorTexture")); CORRADE_VERIFY(!data.hasAttribute(MaterialAttribute::BaseColor)); diff --git a/src/Magnum/Trade/Test/PbrClearCoatMaterialDataTest.cpp b/src/Magnum/Trade/Test/PbrClearCoatMaterialDataTest.cpp index 3add83e02..6390fc61b 100644 --- a/src/Magnum/Trade/Test/PbrClearCoatMaterialDataTest.cpp +++ b/src/Magnum/Trade/Test/PbrClearCoatMaterialDataTest.cpp @@ -41,14 +41,14 @@ class PbrClearCoatMaterialDataTest: public TestSuite::Tester { void textured(); void texturedDefaults(); void texturedExplicitPackedLayerFactorRoughness(); - void texturedSingleMatrixCoordinates(); - void texturedBaseMaterialMatrixCoordinates(); + void texturedSingleMatrixCoordinatesLayer(); + void texturedBaseMaterialMatrixCoordinatesLayer(); void invalidTextures(); - void commonTransformationCoordinatesNoTextures(); - void commonTransformationCoordinatesOneTexture(); - void commonTransformationCoordinatesOneDifferentTexture(); - void commonCoordinatesImplicit(); - void noCommonTransformationCoordinates(); + void commonTransformationCoordinatesLayerNoTextures(); + void commonTransformationCoordinatesLayerOneTexture(); + void commonTransformationCoordinatesLayerOneDifferentTexture(); + void commonCoordinatesLayerImplicit(); + void noCommonTransformationCoordinatesLayer(); }; const Containers::StringView PbrClearCoatTextureData[] { @@ -63,18 +63,18 @@ PbrClearCoatMaterialDataTest::PbrClearCoatMaterialDataTest() { &PbrClearCoatMaterialDataTest::textured, &PbrClearCoatMaterialDataTest::texturedDefaults, &PbrClearCoatMaterialDataTest::texturedExplicitPackedLayerFactorRoughness, - &PbrClearCoatMaterialDataTest::texturedSingleMatrixCoordinates, - &PbrClearCoatMaterialDataTest::texturedBaseMaterialMatrixCoordinates, + &PbrClearCoatMaterialDataTest::texturedSingleMatrixCoordinatesLayer, + &PbrClearCoatMaterialDataTest::texturedBaseMaterialMatrixCoordinatesLayer, &PbrClearCoatMaterialDataTest::invalidTextures, - &PbrClearCoatMaterialDataTest::commonTransformationCoordinatesNoTextures}); + &PbrClearCoatMaterialDataTest::commonTransformationCoordinatesLayerNoTextures}); addInstancedTests({ - &PbrClearCoatMaterialDataTest::commonTransformationCoordinatesOneTexture, - &PbrClearCoatMaterialDataTest::commonTransformationCoordinatesOneDifferentTexture, - &PbrClearCoatMaterialDataTest::commonCoordinatesImplicit}, + &PbrClearCoatMaterialDataTest::commonTransformationCoordinatesLayerOneTexture, + &PbrClearCoatMaterialDataTest::commonTransformationCoordinatesLayerOneDifferentTexture, + &PbrClearCoatMaterialDataTest::commonCoordinatesLayerImplicit}, Containers::arraySize(PbrClearCoatTextureData)); - addTests({&PbrClearCoatMaterialDataTest::noCommonTransformationCoordinates}); + addTests({&PbrClearCoatMaterialDataTest::noCommonTransformationCoordinatesLayer}); } using namespace Math::Literals; @@ -90,6 +90,7 @@ void PbrClearCoatMaterialDataTest::basics() { CORRADE_VERIFY(!data.hasTextureTransformation()); CORRADE_VERIFY(!data.hasTextureCoordinates()); + CORRADE_VERIFY(!data.hasTextureLayer()); CORRADE_COMPARE(data.roughness(), 0.7f); } @@ -105,6 +106,7 @@ void PbrClearCoatMaterialDataTest::defaults() { CORRADE_VERIFY(!data.hasTextureTransformation()); CORRADE_VERIFY(!data.hasTextureCoordinates()); + CORRADE_VERIFY(!data.hasTextureLayer()); CORRADE_COMPARE(data.layerFactor(), 1.0f); CORRADE_COMPARE(data.roughness(), 0.0f); } @@ -117,25 +119,30 @@ void PbrClearCoatMaterialDataTest::textured() { {MaterialAttribute::RoughnessTextureSwizzle, MaterialTextureSwizzle::A}, {MaterialAttribute::RoughnessTextureMatrix, Matrix3::translation({2.0f, 1.5f})}, {MaterialAttribute::RoughnessTextureCoordinates, 6u}, + {MaterialAttribute::RoughnessTextureLayer, 17u}, {MaterialAttribute::NormalTexture, 3u}, {MaterialAttribute::NormalTextureScale, 0.5f}, {MaterialAttribute::NormalTextureSwizzle, MaterialTextureSwizzle::B}, {MaterialAttribute::NormalTextureMatrix, Matrix3::translation({0.0f, 0.5f})}, {MaterialAttribute::NormalTextureCoordinates, 7u}, - }, {0, 11}}; + {MaterialAttribute::NormalTextureLayer, 66u}, + }, {0, 13}}; CORRADE_VERIFY(data.hasTextureTransformation()); CORRADE_VERIFY(data.hasTextureCoordinates()); + CORRADE_VERIFY(data.hasTextureLayer()); CORRADE_COMPARE(data.roughness(), 0.7f); CORRADE_COMPARE(data.roughnessTexture(), 2u); CORRADE_COMPARE(data.roughnessTextureSwizzle(), MaterialTextureSwizzle::A); CORRADE_COMPARE(data.roughnessTextureMatrix(), Matrix3::translation({2.0f, 1.5f})); CORRADE_COMPARE(data.roughnessTextureCoordinates(), 6u); + CORRADE_COMPARE(data.roughnessTextureLayer(), 17u); CORRADE_COMPARE(data.normalTexture(), 3u); CORRADE_COMPARE(data.normalTextureScale(), 0.5f); CORRADE_COMPARE(data.normalTextureSwizzle(), MaterialTextureSwizzle::B); CORRADE_COMPARE(data.normalTextureMatrix(), Matrix3::translation({0.0f, 0.5f})); CORRADE_COMPARE(data.normalTextureCoordinates(), 7u); + CORRADE_COMPARE(data.normalTextureLayer(), 66u); } void PbrClearCoatMaterialDataTest::texturedDefaults() { @@ -147,16 +154,19 @@ void PbrClearCoatMaterialDataTest::texturedDefaults() { CORRADE_VERIFY(!data.hasTextureTransformation()); CORRADE_VERIFY(!data.hasTextureCoordinates()); + CORRADE_VERIFY(!data.hasTextureLayer()); CORRADE_COMPARE(data.roughness(), 0.0f); CORRADE_COMPARE(data.roughnessTexture(), 2u); CORRADE_COMPARE(data.roughnessTextureSwizzle(), MaterialTextureSwizzle::R); CORRADE_COMPARE(data.roughnessTextureMatrix(), Matrix3{}); CORRADE_COMPARE(data.roughnessTextureCoordinates(), 0u); + CORRADE_COMPARE(data.roughnessTextureLayer(), 0u); CORRADE_COMPARE(data.normalTexture(), 3u); CORRADE_COMPARE(data.normalTextureScale(), 1.0f); CORRADE_COMPARE(data.normalTextureSwizzle(), MaterialTextureSwizzle::RGB); CORRADE_COMPARE(data.normalTextureMatrix(), Matrix3{}); CORRADE_COMPARE(data.normalTextureCoordinates(), 0u); + CORRADE_COMPARE(data.normalTextureLayer(), 0u); } void PbrClearCoatMaterialDataTest::texturedExplicitPackedLayerFactorRoughness() { @@ -176,6 +186,7 @@ void PbrClearCoatMaterialDataTest::texturedExplicitPackedLayerFactorRoughness() CORRADE_COMPARE(data.roughnessTextureSwizzle(), MaterialTextureSwizzle::G); CORRADE_COMPARE(data.roughnessTextureMatrix(), Matrix3{}); CORRADE_COMPARE(data.roughnessTextureCoordinates(), 0); + CORRADE_COMPARE(data.roughnessTextureLayer(), 0); /* Explicit parameters for everything, but all the same */ } { @@ -185,19 +196,23 @@ void PbrClearCoatMaterialDataTest::texturedExplicitPackedLayerFactorRoughness() {MaterialAttribute::LayerFactorTextureSwizzle, MaterialTextureSwizzle::R}, {MaterialAttribute::LayerFactorTextureMatrix, Matrix3::scaling({0.5f, 0.5f})}, {MaterialAttribute::LayerFactorTextureCoordinates, 3u}, + {MaterialAttribute::LayerFactorTextureLayer, 17u}, {MaterialAttribute::RoughnessTexture, 2u}, {MaterialAttribute::RoughnessTextureSwizzle, MaterialTextureSwizzle::G}, {MaterialAttribute::RoughnessTextureMatrix, Matrix3::scaling({0.5f, 0.5f})}, - {MaterialAttribute::RoughnessTextureCoordinates, 3u} - }, {0, 9}}; + {MaterialAttribute::RoughnessTextureCoordinates, 3u}, + {MaterialAttribute::RoughnessTextureLayer, 17u} + }, {0, 11}}; CORRADE_VERIFY(data.hasLayerFactorRoughnessTexture()); CORRADE_COMPARE(data.layerFactorTexture(), 2); CORRADE_COMPARE(data.layerFactorTextureMatrix(), Matrix3::scaling({0.5f, 0.5f})); CORRADE_COMPARE(data.layerFactorTextureCoordinates(), 3); + CORRADE_COMPARE(data.layerFactorTextureLayer(), 17); CORRADE_COMPARE(data.roughnessTexture(), 2); CORRADE_COMPARE(data.roughnessTextureSwizzle(), MaterialTextureSwizzle::G); CORRADE_COMPARE(data.roughnessTextureMatrix(), Matrix3::scaling({0.5f, 0.5f})); CORRADE_COMPARE(data.roughnessTextureCoordinates(), 3); + CORRADE_COMPARE(data.roughnessTextureLayer(), 17); /* Different texture ID */ } { @@ -251,47 +266,68 @@ void PbrClearCoatMaterialDataTest::texturedExplicitPackedLayerFactorRoughness() {MaterialAttribute::RoughnessTextureCoordinates, 1u} }, {0, 5}}; CORRADE_VERIFY(!data.hasLayerFactorRoughnessTexture()); + + /* Unexpected array texture layer */ + } { + PbrClearCoatMaterialData data{{}, { + {MaterialLayer::ClearCoat}, + {MaterialAttribute::LayerFactorTexture, 2u}, + {MaterialAttribute::LayerFactorTextureLayer, 1u}, + {MaterialAttribute::RoughnessTexture, 2u}, + {MaterialAttribute::RoughnessTextureSwizzle, MaterialTextureSwizzle::G}, + }, {0, 5}}; + CORRADE_VERIFY(!data.hasLayerFactorRoughnessTexture()); } } -void PbrClearCoatMaterialDataTest::texturedSingleMatrixCoordinates() { +void PbrClearCoatMaterialDataTest::texturedSingleMatrixCoordinatesLayer() { PbrClearCoatMaterialData data{{}, { {MaterialLayer::ClearCoat}, {MaterialAttribute::RoughnessTexture, 2u}, {MaterialAttribute::NormalTexture, 3u}, {MaterialAttribute::TextureMatrix, Matrix3::translation({0.0f, 0.5f})}, {MaterialAttribute::TextureCoordinates, 7u}, - }, {0, 5}}; + {MaterialAttribute::TextureLayer, 17u}, + }, {0, 6}}; CORRADE_VERIFY(data.hasTextureTransformation()); CORRADE_VERIFY(data.hasTextureCoordinates()); + CORRADE_VERIFY(data.hasTextureLayer()); CORRADE_COMPARE(data.roughnessTextureMatrix(), Matrix3::translation({0.0f, 0.5f})); CORRADE_COMPARE(data.roughnessTextureCoordinates(), 7u); + CORRADE_COMPARE(data.roughnessTextureLayer(), 17u); CORRADE_COMPARE(data.normalTextureMatrix(), Matrix3::translation({0.0f, 0.5f})); CORRADE_COMPARE(data.normalTextureCoordinates(), 7u); + CORRADE_COMPARE(data.normalTextureLayer(), 17u); } -void PbrClearCoatMaterialDataTest::texturedBaseMaterialMatrixCoordinates() { +void PbrClearCoatMaterialDataTest::texturedBaseMaterialMatrixCoordinatesLayer() { PbrClearCoatMaterialData data{{}, { {MaterialAttribute::TextureMatrix, Matrix3::translation({0.0f, 0.5f})}, {MaterialAttribute::TextureCoordinates, 7u}, + {MaterialAttribute::TextureLayer, 17u}, {MaterialLayer::ClearCoat}, {MaterialAttribute::RoughnessTexture, 2u}, {MaterialAttribute::NormalTexture, 3u}, - }, {2, 5}}; + }, {3, 6}}; CORRADE_VERIFY(data.hasTextureTransformation()); CORRADE_VERIFY(data.hasTextureCoordinates()); + CORRADE_VERIFY(data.hasTextureLayer()); CORRADE_COMPARE(data.roughnessTextureMatrix(), Matrix3::translation({0.0f, 0.5f})); CORRADE_COMPARE(data.roughnessTextureCoordinates(), 7u); + CORRADE_COMPARE(data.roughnessTextureLayer(), 17u); CORRADE_COMPARE(data.normalTextureMatrix(), Matrix3::translation({0.0f, 0.5f})); CORRADE_COMPARE(data.normalTextureCoordinates(), 7u); + CORRADE_COMPARE(data.normalTextureLayer(), 17u); CORRADE_VERIFY(data.hasCommonTextureTransformation()); CORRADE_VERIFY(data.hasCommonTextureCoordinates()); + CORRADE_VERIFY(data.hasCommonTextureLayer()); CORRADE_COMPARE(data.commonTextureMatrix(), Matrix3::translation({0.0f, 0.5f})); CORRADE_COMPARE(data.commonTextureCoordinates(), 7); + CORRADE_COMPARE(data.commonTextureLayer(), 17); } void PbrClearCoatMaterialDataTest::invalidTextures() { @@ -309,55 +345,67 @@ void PbrClearCoatMaterialDataTest::invalidTextures() { data.roughnessTextureSwizzle(); data.roughnessTextureMatrix(); data.roughnessTextureCoordinates(); + data.roughnessTextureLayer(); data.normalTexture(); data.normalTextureScale(); data.normalTextureSwizzle(); data.normalTextureMatrix(); data.normalTextureCoordinates(); + data.normalTextureLayer(); CORRADE_COMPARE(out.str(), "Trade::MaterialData::attribute(): attribute RoughnessTexture not found in layer ClearCoat\n" "Trade::PbrClearCoatMaterialData::roughnessTextureSwizzle(): the layer doesn't have a roughness texture\n" "Trade::PbrClearCoatMaterialData::roughnessTextureMatrix(): the layer doesn't have a roughness texture\n" "Trade::PbrClearCoatMaterialData::roughnessTextureCoordinates(): the layer doesn't have a roughness texture\n" + "Trade::PbrClearCoatMaterialData::roughnessTextureLayer(): the layer doesn't have a roughness texture\n" "Trade::MaterialData::attribute(): attribute NormalTexture not found in layer ClearCoat\n" "Trade::PbrClearCoatMaterialData::normalTextureScale(): the layer doesn't have a normal texture\n" "Trade::PbrClearCoatMaterialData::normalTextureSwizzle(): the layer doesn't have a normal texture\n" "Trade::PbrClearCoatMaterialData::normalTextureMatrix(): the layer doesn't have a normal texture\n" - "Trade::PbrClearCoatMaterialData::normalTextureCoordinates(): the layer doesn't have a normal texture\n"); + "Trade::PbrClearCoatMaterialData::normalTextureCoordinates(): the layer doesn't have a normal texture\n" + "Trade::PbrClearCoatMaterialData::normalTextureLayer(): the layer doesn't have a normal texture\n"); } -void PbrClearCoatMaterialDataTest::commonTransformationCoordinatesNoTextures() { +void PbrClearCoatMaterialDataTest::commonTransformationCoordinatesLayerNoTextures() { PbrClearCoatMaterialData a{{}, { {MaterialLayer::ClearCoat}, }, {0, 1}}; CORRADE_VERIFY(a.hasCommonTextureTransformation()); CORRADE_VERIFY(a.hasCommonTextureCoordinates()); + CORRADE_VERIFY(a.hasCommonTextureLayer()); CORRADE_COMPARE(a.commonTextureMatrix(), Matrix3{}); CORRADE_COMPARE(a.commonTextureCoordinates(), 0); + CORRADE_COMPARE(a.commonTextureLayer(), 0); PbrClearCoatMaterialData b{{}, { {MaterialAttribute::TextureMatrix, Matrix3::scaling({0.5f, 0.5f})}, {MaterialAttribute::TextureCoordinates, 7u}, + {MaterialAttribute::TextureLayer, 17u}, {MaterialLayer::ClearCoat} - }, {2, 3}}; + }, {3, 4}}; CORRADE_VERIFY(b.hasCommonTextureTransformation()); CORRADE_VERIFY(b.hasCommonTextureCoordinates()); + CORRADE_VERIFY(b.hasCommonTextureLayer()); CORRADE_COMPARE(b.commonTextureMatrix(), Matrix3::scaling({0.5f, 0.5f})); CORRADE_COMPARE(b.commonTextureCoordinates(), 7); + CORRADE_COMPARE(b.commonTextureLayer(), 17); PbrClearCoatMaterialData c{{}, { {MaterialLayer::ClearCoat}, {MaterialAttribute::TextureMatrix, Matrix3::scaling({0.5f, 0.5f})}, {MaterialAttribute::TextureCoordinates, 7u}, - }, {0, 3}}; + {MaterialAttribute::TextureLayer, 17u}, + }, {0, 4}}; CORRADE_VERIFY(c.hasCommonTextureTransformation()); CORRADE_VERIFY(c.hasCommonTextureCoordinates()); + CORRADE_VERIFY(c.hasCommonTextureLayer()); CORRADE_COMPARE(c.commonTextureMatrix(), Matrix3::scaling({0.5f, 0.5f})); CORRADE_COMPARE(c.commonTextureCoordinates(), 7); + CORRADE_COMPARE(c.commonTextureLayer(), 17); } -void PbrClearCoatMaterialDataTest::commonTransformationCoordinatesOneTexture() { +void PbrClearCoatMaterialDataTest::commonTransformationCoordinatesLayerOneTexture() { Containers::StringView textureName = PbrClearCoatTextureData[testCaseInstanceId()]; setTestCaseDescription(textureName); @@ -365,20 +413,24 @@ void PbrClearCoatMaterialDataTest::commonTransformationCoordinatesOneTexture() { /* These shouldn't affect the below */ {MaterialAttribute::TextureMatrix, Matrix3::translation({0.5f, 0.0f})}, {MaterialAttribute::TextureCoordinates, 3u}, + {MaterialAttribute::TextureLayer, 22u}, {MaterialLayer::ClearCoat}, {textureName, 5u}, {textureName + "Matrix", Matrix3::scaling({0.5f, 1.0f})}, {textureName + "Coordinates", 17u}, - }, {2, 6}}; + {textureName + "Layer", 66u}, + }, {3, 8}}; CORRADE_VERIFY(data.hasCommonTextureTransformation()); CORRADE_COMPARE(data.commonTextureMatrix(), Matrix3::scaling({0.5f, 1.0f})); CORRADE_VERIFY(data.hasCommonTextureCoordinates()); CORRADE_COMPARE(data.commonTextureCoordinates(), 17u); + CORRADE_VERIFY(data.hasCommonTextureLayer()); + CORRADE_COMPARE(data.commonTextureLayer(), 66u); } -void PbrClearCoatMaterialDataTest::commonTransformationCoordinatesOneDifferentTexture() { +void PbrClearCoatMaterialDataTest::commonTransformationCoordinatesLayerOneDifferentTexture() { Containers::StringView textureName = PbrClearCoatTextureData[testCaseInstanceId()]; setTestCaseDescription(textureName); @@ -387,20 +439,23 @@ void PbrClearCoatMaterialDataTest::commonTransformationCoordinatesOneDifferentTe check */ {MaterialAttribute::TextureMatrix, Matrix3::translation({0.5f, 0.0f})}, {MaterialAttribute::TextureCoordinates, 3u}, + {MaterialAttribute::TextureLayer, 22u}, {MaterialLayer::ClearCoat}, {MaterialAttribute::LayerFactorTexture, 2u}, {MaterialAttribute::RoughnessTexture, 3u}, {MaterialAttribute::NormalTexture, 5u}, {textureName + "Matrix", Matrix3::scaling({0.5f, 1.0f})}, - {textureName + "Coordinates", 17u} - }, {2, 8}}; + {textureName + "Coordinates", 17u}, + {textureName + "Layer", 66u}, + }, {3, 10}}; CORRADE_VERIFY(!data.hasCommonTextureTransformation()); CORRADE_VERIFY(!data.hasCommonTextureCoordinates()); + CORRADE_VERIFY(!data.hasCommonTextureLayer()); } -void PbrClearCoatMaterialDataTest::commonCoordinatesImplicit() { +void PbrClearCoatMaterialDataTest::commonCoordinatesLayerImplicit() { Containers::StringView textureName = PbrClearCoatTextureData[testCaseInstanceId()]; setTestCaseDescription(textureName); @@ -410,16 +465,20 @@ void PbrClearCoatMaterialDataTest::commonCoordinatesImplicit() { PbrClearCoatMaterialData data{{}, { {MaterialLayer::ClearCoat}, {textureName, 5u}, - {textureName + "Coordinates", 0u} + {textureName + "Coordinates", 0u}, + {textureName + "Layer", 0u}, }, {0, 3}}; /* Zero is treated same as if there would be no attribute at all */ CORRADE_VERIFY(!data.hasTextureCoordinates()); + CORRADE_VERIFY(!data.hasTextureLayer()); CORRADE_VERIFY(data.hasCommonTextureCoordinates()); + CORRADE_VERIFY(data.hasCommonTextureLayer()); CORRADE_COMPARE(data.commonTextureCoordinates(), 0u); + CORRADE_COMPARE(data.commonTextureLayer(), 0u); } -void PbrClearCoatMaterialDataTest::noCommonTransformationCoordinates() { +void PbrClearCoatMaterialDataTest::noCommonTransformationCoordinatesLayer() { #ifdef CORRADE_NO_ASSERT CORRADE_SKIP("CORRADE_NO_ASSERT defined, can't test assertions"); #endif @@ -431,9 +490,10 @@ void PbrClearCoatMaterialDataTest::noCommonTransformationCoordinates() { {MaterialAttribute::LayerFactorTextureCoordinates, 3u}, {MaterialAttribute::RoughnessTexture, 4u}, {MaterialAttribute::RoughnessTextureMatrix, Matrix3::scaling({0.5f, 1.0f})}, + {MaterialAttribute::RoughnessTextureLayer, 22u}, {MaterialAttribute::NormalTexture, 5u}, {MaterialAttribute::NormalTextureCoordinates, 17u} - }, {0, 8}}; + }, {0, 9}}; CORRADE_VERIFY(!data.hasCommonTextureTransformation()); CORRADE_VERIFY(!data.hasCommonTextureCoordinates()); @@ -442,9 +502,11 @@ void PbrClearCoatMaterialDataTest::noCommonTransformationCoordinates() { Error redirectError{&out}; data.commonTextureMatrix(); data.commonTextureCoordinates(); + data.commonTextureLayer(); CORRADE_COMPARE(out.str(), "Trade::PbrClearCoatMaterialData::commonTextureMatrix(): the layer doesn't have a common texture coordinate transformation\n" - "Trade::PbrClearCoatMaterialData::commonTextureCoordinates(): the layer doesn't have a common texture coordinate set\n"); + "Trade::PbrClearCoatMaterialData::commonTextureCoordinates(): the layer doesn't have a common texture coordinate set\n" + "Trade::PbrClearCoatMaterialData::commonTextureLayer(): the layer doesn't have a common array texture layer\n"); } }}}} diff --git a/src/Magnum/Trade/Test/PbrMetallicRoughnessMaterialDataTest.cpp b/src/Magnum/Trade/Test/PbrMetallicRoughnessMaterialDataTest.cpp index e8b93e1f0..d5ab2c420 100644 --- a/src/Magnum/Trade/Test/PbrMetallicRoughnessMaterialDataTest.cpp +++ b/src/Magnum/Trade/Test/PbrMetallicRoughnessMaterialDataTest.cpp @@ -47,13 +47,13 @@ class PbrMetallicRoughnessMaterialDataTest: public TestSuite::Tester { void texturedExplicitPackedRoughnessMetallicOcclusion(); void texturedExplicitPackedOcclusionRoughnessMetallic(); void texturedExplicitPackedNormalRoughnessMetallic(); - void texturedSingleMatrixCoordinates(); + void texturedSingleMatrixCoordinatesLayer(); void invalidTextures(); - void commonTransformationCoordinatesNoTextures(); - void commonTransformationCoordinatesOneTexture(); - void commonTransformationCoordinatesOneDifferentTexture(); - void commonCoordinatesImplicit(); - void noCommonTransformationCoordinates(); + void commonTransformationCoordinatesLayerNoTextures(); + void commonTransformationCoordinatesLayerOneTexture(); + void commonTransformationCoordinatesLayerOneDifferentTexture(); + void commonCoordinatesLayerImplicit(); + void noCommonTransformationCoordinatesLayer(); }; const Containers::StringView PbrMetallicRoughnessTextureData[] { @@ -75,17 +75,17 @@ PbrMetallicRoughnessMaterialDataTest::PbrMetallicRoughnessMaterialDataTest() { &PbrMetallicRoughnessMaterialDataTest::texturedExplicitPackedRoughnessMetallicOcclusion, &PbrMetallicRoughnessMaterialDataTest::texturedExplicitPackedOcclusionRoughnessMetallic, &PbrMetallicRoughnessMaterialDataTest::texturedExplicitPackedNormalRoughnessMetallic, - &PbrMetallicRoughnessMaterialDataTest::texturedSingleMatrixCoordinates, + &PbrMetallicRoughnessMaterialDataTest::texturedSingleMatrixCoordinatesLayer, &PbrMetallicRoughnessMaterialDataTest::invalidTextures, - &PbrMetallicRoughnessMaterialDataTest::commonTransformationCoordinatesNoTextures}); + &PbrMetallicRoughnessMaterialDataTest::commonTransformationCoordinatesLayerNoTextures}); addInstancedTests({ - &PbrMetallicRoughnessMaterialDataTest::commonTransformationCoordinatesOneTexture, - &PbrMetallicRoughnessMaterialDataTest::commonTransformationCoordinatesOneDifferentTexture, - &PbrMetallicRoughnessMaterialDataTest::commonCoordinatesImplicit}, + &PbrMetallicRoughnessMaterialDataTest::commonTransformationCoordinatesLayerOneTexture, + &PbrMetallicRoughnessMaterialDataTest::commonTransformationCoordinatesLayerOneDifferentTexture, + &PbrMetallicRoughnessMaterialDataTest::commonCoordinatesLayerImplicit}, Containers::arraySize(PbrMetallicRoughnessTextureData)); - addTests({&PbrMetallicRoughnessMaterialDataTest::noCommonTransformationCoordinates}); + addTests({&PbrMetallicRoughnessMaterialDataTest::noCommonTransformationCoordinatesLayer}); } using namespace Math::Literals; @@ -109,6 +109,7 @@ void PbrMetallicRoughnessMaterialDataTest::basics() { CORRADE_VERIFY(!data.hasNormalRoughnessMetallicTexture()); CORRADE_VERIFY(!data.hasTextureTransformation()); CORRADE_VERIFY(!data.hasTextureCoordinates()); + CORRADE_VERIFY(!data.hasTextureLayer()); CORRADE_COMPARE(data.baseColor(), 0xccffbbff_rgbaf); CORRADE_COMPARE(data.metalness(), 0.5f); CORRADE_COMPARE(data.roughness(), 0.79f); @@ -130,6 +131,7 @@ void PbrMetallicRoughnessMaterialDataTest::defaults() { CORRADE_VERIFY(!data.hasNormalRoughnessMetallicTexture()); CORRADE_VERIFY(!data.hasTextureTransformation()); CORRADE_VERIFY(!data.hasTextureCoordinates()); + CORRADE_VERIFY(!data.hasTextureLayer()); CORRADE_COMPARE(data.baseColor(), 0xffffffff_rgbaf); CORRADE_COMPARE(data.metalness(), 1.0f); CORRADE_COMPARE(data.roughness(), 1.0f); @@ -142,30 +144,36 @@ void PbrMetallicRoughnessMaterialDataTest::textured() { {MaterialAttribute::BaseColorTexture, 0u}, {MaterialAttribute::BaseColorTextureMatrix, Matrix3::scaling({0.5f, 1.0f})}, {MaterialAttribute::BaseColorTextureCoordinates, 2u}, + {MaterialAttribute::BaseColorTextureLayer, 8u}, {MaterialAttribute::Metalness, 0.5f}, {MaterialAttribute::MetalnessTexture, 1u}, {MaterialAttribute::MetalnessTextureSwizzle, MaterialTextureSwizzle::G}, {MaterialAttribute::MetalnessTextureMatrix, Matrix3::scaling({0.5f, 0.5f})}, {MaterialAttribute::MetalnessTextureCoordinates, 3u}, + {MaterialAttribute::MetalnessTextureLayer, 9u}, {MaterialAttribute::Roughness, 0.79f}, {MaterialAttribute::RoughnessTexture, 2u}, {MaterialAttribute::RoughnessTextureSwizzle, MaterialTextureSwizzle::A}, {MaterialAttribute::RoughnessTextureMatrix, Matrix3::scaling({1.0f, 1.0f})}, {MaterialAttribute::RoughnessTextureCoordinates, 4u}, + {MaterialAttribute::RoughnessTextureLayer, 10u}, {MaterialAttribute::NormalTexture, 3u}, {MaterialAttribute::NormalTextureScale, 0.35f}, {MaterialAttribute::NormalTextureSwizzle, MaterialTextureSwizzle::BA}, {MaterialAttribute::NormalTextureMatrix, Matrix3::scaling({1.0f, 0.5f})}, {MaterialAttribute::NormalTextureCoordinates, 5u}, + {MaterialAttribute::NormalTextureLayer, 11u}, {MaterialAttribute::OcclusionTexture, 4u}, {MaterialAttribute::OcclusionTextureStrength, 0.66f}, {MaterialAttribute::OcclusionTextureSwizzle, MaterialTextureSwizzle::B}, {MaterialAttribute::OcclusionTextureMatrix, Matrix3::scaling({1.0f, 0.75f})}, {MaterialAttribute::OcclusionTextureCoordinates, 6u}, + {MaterialAttribute::OcclusionTextureLayer, 12u}, {MaterialAttribute::EmissiveColor, 0x111111_rgbf}, {MaterialAttribute::EmissiveTexture, 5u}, {MaterialAttribute::EmissiveTextureMatrix, Matrix3::scaling({0.75f, 0.5f})}, - {MaterialAttribute::EmissiveTextureCoordinates, 7u} + {MaterialAttribute::EmissiveTextureCoordinates, 7u}, + {MaterialAttribute::EmissiveTextureLayer, 13u} }}; CORRADE_VERIFY(data.hasMetalnessTexture()); @@ -176,34 +184,41 @@ void PbrMetallicRoughnessMaterialDataTest::textured() { CORRADE_VERIFY(!data.hasNormalRoughnessMetallicTexture()); CORRADE_VERIFY(data.hasTextureTransformation()); CORRADE_VERIFY(data.hasTextureCoordinates()); + CORRADE_VERIFY(data.hasTextureLayer()); CORRADE_COMPARE(data.baseColor(), 0xccffbbff_rgbaf); CORRADE_COMPARE(data.baseColorTexture(), 0); CORRADE_COMPARE(data.baseColorTextureMatrix(), Matrix3::scaling({0.5f, 1.0f})); CORRADE_COMPARE(data.baseColorTextureCoordinates(), 2); + CORRADE_COMPARE(data.baseColorTextureLayer(), 8); CORRADE_COMPARE(data.metalness(), 0.5f); CORRADE_COMPARE(data.metalnessTexture(), 1); CORRADE_COMPARE(data.metalnessTextureSwizzle(), MaterialTextureSwizzle::G); CORRADE_COMPARE(data.metalnessTextureMatrix(), Matrix3::scaling({0.5f, 0.5f})); CORRADE_COMPARE(data.metalnessTextureCoordinates(), 3); + CORRADE_COMPARE(data.metalnessTextureLayer(), 9); CORRADE_COMPARE(data.roughness(), 0.79f); CORRADE_COMPARE(data.roughnessTexture(), 2); CORRADE_COMPARE(data.roughnessTextureSwizzle(), MaterialTextureSwizzle::A); CORRADE_COMPARE(data.roughnessTextureMatrix(), Matrix3::scaling({1.0f, 1.0f})); CORRADE_COMPARE(data.roughnessTextureCoordinates(), 4); + CORRADE_COMPARE(data.roughnessTextureLayer(), 10); CORRADE_COMPARE(data.normalTexture(), 3); CORRADE_COMPARE(data.normalTextureScale(), 0.35f); CORRADE_COMPARE(data.normalTextureSwizzle(), MaterialTextureSwizzle::BA); CORRADE_COMPARE(data.normalTextureMatrix(), Matrix3::scaling({1.0f, 0.5f})); CORRADE_COMPARE(data.normalTextureCoordinates(), 5); + CORRADE_COMPARE(data.normalTextureLayer(), 11); CORRADE_COMPARE(data.occlusionTexture(), 4); CORRADE_COMPARE(data.occlusionTextureStrength(), 0.66f); CORRADE_COMPARE(data.occlusionTextureMatrix(), Matrix3::scaling({1.0f, 0.75f})); CORRADE_COMPARE(data.occlusionTextureSwizzle(), MaterialTextureSwizzle::B); CORRADE_COMPARE(data.occlusionTextureCoordinates(), 6); + CORRADE_COMPARE(data.occlusionTextureLayer(), 12); CORRADE_COMPARE(data.emissiveColor(), 0x111111_rgbf); CORRADE_COMPARE(data.emissiveTextureMatrix(), Matrix3::scaling({0.75f, 0.5f})); CORRADE_COMPARE(data.emissiveTexture(), 5); CORRADE_COMPARE(data.emissiveTextureCoordinates(), 7); + CORRADE_COMPARE(data.emissiveTextureLayer(), 13); } void PbrMetallicRoughnessMaterialDataTest::texturedDefaults() { @@ -224,37 +239,44 @@ void PbrMetallicRoughnessMaterialDataTest::texturedDefaults() { CORRADE_VERIFY(!data.hasNormalRoughnessMetallicTexture()); CORRADE_VERIFY(!data.hasTextureTransformation()); CORRADE_VERIFY(!data.hasTextureCoordinates()); + CORRADE_VERIFY(!data.hasTextureLayer()); CORRADE_COMPARE(data.baseColor(), 0xffffffff_rgbaf); CORRADE_COMPARE(data.baseColorTexture(), 1); CORRADE_COMPARE(data.baseColorTextureMatrix(), Matrix3{}); CORRADE_COMPARE(data.baseColorTextureCoordinates(), 0); + CORRADE_COMPARE(data.baseColorTextureLayer(), 0); CORRADE_COMPARE(data.metalness(), 1.0f); CORRADE_COMPARE(data.metalnessTexture(), 2); CORRADE_COMPARE(data.metalnessTextureSwizzle(), MaterialTextureSwizzle::R); CORRADE_COMPARE(data.metalnessTextureMatrix(), Matrix3{}); CORRADE_COMPARE(data.metalnessTextureCoordinates(), 0); + CORRADE_COMPARE(data.metalnessTextureLayer(), 0); CORRADE_COMPARE(data.roughness(), 1.0f); CORRADE_COMPARE(data.roughnessTexture(), 3); CORRADE_COMPARE(data.roughnessTextureSwizzle(), MaterialTextureSwizzle::R); CORRADE_COMPARE(data.roughnessTextureMatrix(), Matrix3{}); CORRADE_COMPARE(data.roughnessTextureCoordinates(), 0); + CORRADE_COMPARE(data.roughnessTextureLayer(), 0); CORRADE_COMPARE(data.normalTexture(), 4); CORRADE_COMPARE(data.normalTextureScale(), 1.0f); CORRADE_COMPARE(data.normalTextureSwizzle(), MaterialTextureSwizzle::RGB); CORRADE_COMPARE(data.normalTextureMatrix(), Matrix3{}); CORRADE_COMPARE(data.normalTextureCoordinates(), 0); + CORRADE_COMPARE(data.normalTextureLayer(), 0); CORRADE_COMPARE(data.occlusionTexture(), 5); CORRADE_COMPARE(data.occlusionTextureStrength(), 1.0f); CORRADE_COMPARE(data.occlusionTextureSwizzle(), MaterialTextureSwizzle::R); CORRADE_COMPARE(data.occlusionTextureMatrix(), Matrix3{}); CORRADE_COMPARE(data.occlusionTextureCoordinates(), 0); + CORRADE_COMPARE(data.occlusionTextureLayer(), 0); CORRADE_COMPARE(data.emissiveColor(), 0x000000_rgbf); CORRADE_COMPARE(data.emissiveTexture(), 6); CORRADE_COMPARE(data.emissiveTextureMatrix(), Matrix3{}); CORRADE_COMPARE(data.emissiveTextureCoordinates(), 0); + CORRADE_COMPARE(data.emissiveTextureLayer(), 0); } -void PbrMetallicRoughnessMaterialDataTest::texturedSingleMatrixCoordinates() { +void PbrMetallicRoughnessMaterialDataTest::texturedSingleMatrixCoordinatesLayer() { PbrMetallicRoughnessMaterialData data{{}, { {MaterialAttribute::BaseColorTexture, 1u}, {MaterialAttribute::MetalnessTexture, 2u}, @@ -263,21 +285,28 @@ void PbrMetallicRoughnessMaterialDataTest::texturedSingleMatrixCoordinates() { {MaterialAttribute::OcclusionTexture, 5u}, {MaterialAttribute::EmissiveTexture, 6u}, {MaterialAttribute::TextureMatrix, Matrix3::scaling({0.5f, 0.5f})}, - {MaterialAttribute::TextureCoordinates, 7u} + {MaterialAttribute::TextureCoordinates, 7u}, + {MaterialAttribute::TextureLayer, 8u}, }}; CORRADE_COMPARE(data.baseColorTextureMatrix(), Matrix3::scaling({0.5f, 0.5f})); CORRADE_COMPARE(data.baseColorTextureCoordinates(), 7); + CORRADE_COMPARE(data.baseColorTextureLayer(), 8); CORRADE_COMPARE(data.metalnessTextureMatrix(), Matrix3::scaling({0.5f, 0.5f})); CORRADE_COMPARE(data.metalnessTextureCoordinates(), 7); + CORRADE_COMPARE(data.metalnessTextureLayer(), 8); CORRADE_COMPARE(data.roughnessTextureMatrix(), Matrix3::scaling({0.5f, 0.5f})); CORRADE_COMPARE(data.roughnessTextureCoordinates(), 7); + CORRADE_COMPARE(data.roughnessTextureLayer(), 8); CORRADE_COMPARE(data.normalTextureMatrix(), Matrix3::scaling({0.5f, 0.5f})); CORRADE_COMPARE(data.normalTextureCoordinates(), 7); + CORRADE_COMPARE(data.normalTextureLayer(), 8); CORRADE_COMPARE(data.occlusionTextureMatrix(), Matrix3::scaling({0.5f, 0.5f})); CORRADE_COMPARE(data.occlusionTextureCoordinates(), 7); + CORRADE_COMPARE(data.occlusionTextureLayer(), 8); CORRADE_COMPARE(data.emissiveTextureMatrix(), Matrix3::scaling({0.5f, 0.5f})); CORRADE_COMPARE(data.emissiveTextureCoordinates(), 7); + CORRADE_COMPARE(data.emissiveTextureLayer(), 8); } void PbrMetallicRoughnessMaterialDataTest::texturedImplicitPackedMetallicRoughness() { @@ -291,10 +320,12 @@ void PbrMetallicRoughnessMaterialDataTest::texturedImplicitPackedMetallicRoughne CORRADE_COMPARE(data.roughnessTextureSwizzle(), MaterialTextureSwizzle::G); CORRADE_COMPARE(data.roughnessTextureMatrix(), Matrix3{}); CORRADE_COMPARE(data.roughnessTextureCoordinates(), 0); + CORRADE_COMPARE(data.roughnessTextureLayer(), 0); CORRADE_COMPARE(data.metalnessTexture(), 2); CORRADE_COMPARE(data.metalnessTextureSwizzle(), MaterialTextureSwizzle::B); CORRADE_COMPARE(data.metalnessTextureMatrix(), Matrix3{}); CORRADE_COMPARE(data.metalnessTextureCoordinates(), 0); + CORRADE_COMPARE(data.metalnessTextureLayer(), 0); /* Explicit parameters for everything, but all the same */ } { @@ -303,19 +334,23 @@ void PbrMetallicRoughnessMaterialDataTest::texturedImplicitPackedMetallicRoughne {MaterialAttribute::RoughnessTextureSwizzle, MaterialTextureSwizzle::G}, {MaterialAttribute::RoughnessTextureMatrix, Matrix3::scaling({0.5f, 0.5f})}, {MaterialAttribute::RoughnessTextureCoordinates, 3u}, + {MaterialAttribute::RoughnessTextureLayer, 17u}, {MaterialAttribute::MetalnessTextureMatrix, Matrix3::scaling({0.5f, 0.5f})}, {MaterialAttribute::MetalnessTextureSwizzle, MaterialTextureSwizzle::B}, - {MaterialAttribute::MetalnessTextureCoordinates, 3u} + {MaterialAttribute::MetalnessTextureCoordinates, 3u}, + {MaterialAttribute::MetalnessTextureLayer, 17u}, }}; CORRADE_VERIFY(data.hasNoneRoughnessMetallicTexture()); CORRADE_COMPARE(data.roughnessTexture(), 2); CORRADE_COMPARE(data.roughnessTextureSwizzle(), MaterialTextureSwizzle::G); CORRADE_COMPARE(data.roughnessTextureMatrix(), Matrix3::scaling({0.5f, 0.5f})); CORRADE_COMPARE(data.roughnessTextureCoordinates(), 3); + CORRADE_COMPARE(data.roughnessTextureLayer(), 17); CORRADE_COMPARE(data.metalnessTexture(), 2); CORRADE_COMPARE(data.metalnessTextureSwizzle(), MaterialTextureSwizzle::B); CORRADE_COMPARE(data.metalnessTextureMatrix(), Matrix3::scaling({0.5f, 0.5f})); CORRADE_COMPARE(data.metalnessTextureCoordinates(), 3); + CORRADE_COMPARE(data.metalnessTextureLayer(), 17); /* Swizzle is ignored when the combined texture is specified, so this is fine */ @@ -341,6 +376,14 @@ void PbrMetallicRoughnessMaterialDataTest::texturedImplicitPackedMetallicRoughne {MaterialAttribute::RoughnessTextureCoordinates, 1u}, }}; CORRADE_VERIFY(!data.hasNoneRoughnessMetallicTexture()); + + /* Unexpected array texture layer */ + } { + PbrMetallicRoughnessMaterialData data{{}, { + {MaterialAttribute::NoneRoughnessMetallicTexture, 2u}, + {MaterialAttribute::MetalnessTextureLayer, 1u}, + }}; + CORRADE_VERIFY(!data.hasNoneRoughnessMetallicTexture()); } } @@ -362,10 +405,12 @@ void PbrMetallicRoughnessMaterialDataTest::texturedExplicitPackedMetallicRoughne {MaterialAttribute::RoughnessTextureSwizzle, MaterialTextureSwizzle::G}, {MaterialAttribute::RoughnessTextureMatrix, Matrix3::scaling({0.5f, 0.5f})}, {MaterialAttribute::RoughnessTextureCoordinates, 3u}, + {MaterialAttribute::RoughnessTextureLayer, 7u}, {MaterialAttribute::MetalnessTexture, 2u}, {MaterialAttribute::MetalnessTextureMatrix, Matrix3::scaling({0.5f, 0.5f})}, {MaterialAttribute::MetalnessTextureSwizzle, MaterialTextureSwizzle::B}, - {MaterialAttribute::MetalnessTextureCoordinates, 3u} + {MaterialAttribute::MetalnessTextureCoordinates, 3u}, + {MaterialAttribute::MetalnessTextureLayer, 7u} }}; CORRADE_VERIFY(data.hasNoneRoughnessMetallicTexture()); @@ -418,6 +463,17 @@ void PbrMetallicRoughnessMaterialDataTest::texturedExplicitPackedMetallicRoughne {MaterialAttribute::MetalnessTextureSwizzle, MaterialTextureSwizzle::B}, }}; CORRADE_VERIFY(!data.hasNoneRoughnessMetallicTexture()); + + /* Unexpected array texture layer */ + } { + PbrMetallicRoughnessMaterialData data{{}, { + {MaterialAttribute::RoughnessTexture, 2u}, + {MaterialAttribute::RoughnessTextureSwizzle, MaterialTextureSwizzle::G}, + {MaterialAttribute::MetalnessTexture, 2u}, + {MaterialAttribute::MetalnessTextureSwizzle, MaterialTextureSwizzle::B}, + {MaterialAttribute::MetalnessTextureLayer, 1u}, + }}; + CORRADE_VERIFY(!data.hasNoneRoughnessMetallicTexture()); } } @@ -442,14 +498,17 @@ void PbrMetallicRoughnessMaterialDataTest::texturedExplicitPackedRoughnessMetall {MaterialAttribute::RoughnessTextureSwizzle, MaterialTextureSwizzle::R}, {MaterialAttribute::RoughnessTextureMatrix, Matrix3::scaling({0.5f, 0.5f})}, {MaterialAttribute::RoughnessTextureCoordinates, 3u}, + {MaterialAttribute::RoughnessTextureLayer, 7u}, {MaterialAttribute::MetalnessTexture, 2u}, {MaterialAttribute::MetalnessTextureMatrix, Matrix3::scaling({0.5f, 0.5f})}, {MaterialAttribute::MetalnessTextureSwizzle, MaterialTextureSwizzle::G}, {MaterialAttribute::MetalnessTextureCoordinates, 3u}, + {MaterialAttribute::MetalnessTextureLayer, 7u}, {MaterialAttribute::OcclusionTexture, 2u}, {MaterialAttribute::OcclusionTextureSwizzle, MaterialTextureSwizzle::B}, {MaterialAttribute::OcclusionTextureMatrix, Matrix3::scaling({0.5f, 0.5f})}, - {MaterialAttribute::OcclusionTextureCoordinates, 3u} + {MaterialAttribute::OcclusionTextureCoordinates, 3u}, + {MaterialAttribute::OcclusionTextureLayer, 7u}, }}; CORRADE_VERIFY(data.hasRoughnessMetallicOcclusionTexture()); /* This isn't a superset */ @@ -506,9 +565,21 @@ void PbrMetallicRoughnessMaterialDataTest::texturedExplicitPackedRoughnessMetall {MaterialAttribute::RoughnessTexture, 2u}, {MaterialAttribute::MetalnessTexture, 2u}, {MaterialAttribute::MetalnessTextureSwizzle, MaterialTextureSwizzle::G}, + {MaterialAttribute::MetalnessTextureCoordinates, 1u}, + {MaterialAttribute::OcclusionTexture, 2u}, + {MaterialAttribute::OcclusionTextureSwizzle, MaterialTextureSwizzle::B}, + }}; + CORRADE_VERIFY(!data.hasRoughnessMetallicOcclusionTexture()); + + /* Unexpected array texture layer */ + } { + PbrMetallicRoughnessMaterialData data{{}, { + {MaterialAttribute::RoughnessTexture, 2u}, + {MaterialAttribute::RoughnessTextureLayer, 1u}, + {MaterialAttribute::MetalnessTexture, 2u}, + {MaterialAttribute::MetalnessTextureSwizzle, MaterialTextureSwizzle::G}, {MaterialAttribute::OcclusionTexture, 2u}, {MaterialAttribute::OcclusionTextureSwizzle, MaterialTextureSwizzle::B}, - {MaterialAttribute::MetalnessTextureCoordinates, 1u}, }}; CORRADE_VERIFY(!data.hasRoughnessMetallicOcclusionTexture()); } @@ -604,6 +675,18 @@ void PbrMetallicRoughnessMaterialDataTest::texturedExplicitPackedOcclusionRoughn {MaterialAttribute::MetalnessTextureCoordinates, 1u}, }}; CORRADE_VERIFY(!data.hasOcclusionRoughnessMetallicTexture()); + + /* Unexpected array texture layer */ + } { + PbrMetallicRoughnessMaterialData data{{}, { + {MaterialAttribute::OcclusionTexture, 2u}, + {MaterialAttribute::OcclusionTextureLayer, 1u}, + {MaterialAttribute::RoughnessTexture, 2u}, + {MaterialAttribute::RoughnessTextureSwizzle, MaterialTextureSwizzle::G}, + {MaterialAttribute::MetalnessTexture, 2u}, + {MaterialAttribute::MetalnessTextureSwizzle, MaterialTextureSwizzle::B}, + }}; + CORRADE_VERIFY(!data.hasOcclusionRoughnessMetallicTexture()); } } @@ -697,6 +780,19 @@ void PbrMetallicRoughnessMaterialDataTest::texturedExplicitPackedNormalRoughness {MaterialAttribute::MetalnessTextureCoordinates, 1u}, }}; CORRADE_VERIFY(!data.hasNormalRoughnessMetallicTexture()); + + /* Unexpected array texture layer */ + } { + PbrMetallicRoughnessMaterialData data{{}, { + {MaterialAttribute::NormalTexture, 2u}, + {MaterialAttribute::NormalTextureSwizzle, MaterialTextureSwizzle::RG}, + {MaterialAttribute::RoughnessTexture, 2u}, + {MaterialAttribute::RoughnessTextureSwizzle, MaterialTextureSwizzle::B}, + {MaterialAttribute::RoughnessTextureLayer, 1u}, + {MaterialAttribute::MetalnessTexture, 2u}, + {MaterialAttribute::MetalnessTextureSwizzle, MaterialTextureSwizzle::A}, + }}; + CORRADE_VERIFY(!data.hasNormalRoughnessMetallicTexture()); } } @@ -712,72 +808,89 @@ void PbrMetallicRoughnessMaterialDataTest::invalidTextures() { data.baseColorTexture(); data.baseColorTextureMatrix(); data.baseColorTextureCoordinates(); + data.baseColorTextureLayer(); data.metalnessTexture(); data.metalnessTextureSwizzle(); data.metalnessTextureMatrix(); data.metalnessTextureCoordinates(); + data.metalnessTextureLayer(); data.roughnessTexture(); data.roughnessTextureSwizzle(); data.roughnessTextureMatrix(); data.roughnessTextureCoordinates(); + data.roughnessTextureLayer(); data.normalTexture(); data.normalTextureScale(); data.normalTextureSwizzle(); data.normalTextureMatrix(); data.normalTextureCoordinates(); + data.normalTextureLayer(); data.occlusionTexture(); data.occlusionTextureStrength(); data.occlusionTextureSwizzle(); data.occlusionTextureMatrix(); data.occlusionTextureCoordinates(); + data.occlusionTextureLayer(); data.emissiveTexture(); data.emissiveTextureMatrix(); data.emissiveTextureCoordinates(); + data.emissiveTextureLayer(); CORRADE_COMPARE(out.str(), "Trade::MaterialData::attribute(): attribute BaseColorTexture not found in layer 0\n" "Trade::PbrMetallicRoughnessMaterialData::baseColorTextureMatrix(): the material doesn't have a base color texture\n" "Trade::PbrMetallicRoughnessMaterialData::baseColorTextureCoordinates(): the material doesn't have a base color texture\n" + "Trade::PbrMetallicRoughnessMaterialData::baseColorTextureLayer(): the material doesn't have a base color texture\n" "Trade::PbrMetallicRoughnessMaterialData::metalnessTexture(): the material doesn't have a metalness texture\n" "Trade::PbrMetallicRoughnessMaterialData::metalnessTextureSwizzle(): the material doesn't have a metalness texture\n" "Trade::PbrMetallicRoughnessMaterialData::metalnessTextureMatrix(): the material doesn't have a metalness texture\n" "Trade::PbrMetallicRoughnessMaterialData::metalnessTextureCoordinates(): the material doesn't have a metalness texture\n" + "Trade::PbrMetallicRoughnessMaterialData::metalnessTextureLayer(): the material doesn't have a metalness texture\n" "Trade::PbrMetallicRoughnessMaterialData::roughnessTexture(): the material doesn't have a roughness texture\n" "Trade::PbrMetallicRoughnessMaterialData::roughnessTextureSwizzle(): the material doesn't have a roughness texture\n" "Trade::PbrMetallicRoughnessMaterialData::roughnessTextureMatrix(): the material doesn't have a roughness texture\n" "Trade::PbrMetallicRoughnessMaterialData::roughnessTextureCoordinates(): the material doesn't have a roughness texture\n" + "Trade::PbrMetallicRoughnessMaterialData::roughnessTextureLayer(): the material doesn't have a roughness texture\n" "Trade::MaterialData::attribute(): attribute NormalTexture not found in layer 0\n" "Trade::PbrMetallicRoughnessMaterialData::normalTextureScale(): the material doesn't have a normal texture\n" "Trade::PbrMetallicRoughnessMaterialData::normalTextureSwizzle(): the material doesn't have a normal texture\n" "Trade::PbrMetallicRoughnessMaterialData::normalTextureMatrix(): the material doesn't have a normal texture\n" "Trade::PbrMetallicRoughnessMaterialData::normalTextureCoordinates(): the material doesn't have a normal texture\n" + "Trade::PbrMetallicRoughnessMaterialData::normalTextureLayer(): the material doesn't have a normal texture\n" "Trade::MaterialData::attribute(): attribute OcclusionTexture not found in layer 0\n" "Trade::PbrMetallicRoughnessMaterialData::occlusionTextureStrength(): the material doesn't have an occlusion texture\n" "Trade::PbrMetallicRoughnessMaterialData::occlusionTextureSwizzle(): the material doesn't have an occlusion texture\n" "Trade::PbrMetallicRoughnessMaterialData::occlusionTextureMatrix(): the material doesn't have an occlusion texture\n" "Trade::PbrMetallicRoughnessMaterialData::occlusionTextureCoordinates(): the material doesn't have an occlusion texture\n" + "Trade::PbrMetallicRoughnessMaterialData::occlusionTextureLayer(): the material doesn't have an occlusion texture\n" "Trade::MaterialData::attribute(): attribute EmissiveTexture not found in layer 0\n" "Trade::PbrMetallicRoughnessMaterialData::emissiveTextureMatrix(): the material doesn't have an emissive texture\n" - "Trade::PbrMetallicRoughnessMaterialData::emissiveTextureCoordinates(): the material doesn't have an emissive texture\n"); + "Trade::PbrMetallicRoughnessMaterialData::emissiveTextureCoordinates(): the material doesn't have an emissive texture\n" + "Trade::PbrMetallicRoughnessMaterialData::emissiveTextureLayer(): the material doesn't have an emissive texture\n"); } -void PbrMetallicRoughnessMaterialDataTest::commonTransformationCoordinatesNoTextures() { +void PbrMetallicRoughnessMaterialDataTest::commonTransformationCoordinatesLayerNoTextures() { PbrMetallicRoughnessMaterialData a{{}, {}}; CORRADE_VERIFY(a.hasCommonTextureTransformation()); CORRADE_VERIFY(a.hasCommonTextureCoordinates()); + CORRADE_VERIFY(a.hasCommonTextureLayer()); CORRADE_COMPARE(a.commonTextureMatrix(), Matrix3{}); CORRADE_COMPARE(a.commonTextureCoordinates(), 0); + CORRADE_COMPARE(a.commonTextureLayer(), 0); PbrMetallicRoughnessMaterialData b{{}, { {MaterialAttribute::TextureMatrix, Matrix3::scaling({0.5f, 0.5f})}, - {MaterialAttribute::TextureCoordinates, 7u} + {MaterialAttribute::TextureCoordinates, 7u}, + {MaterialAttribute::TextureLayer, 22u} }}; CORRADE_VERIFY(b.hasCommonTextureTransformation()); CORRADE_VERIFY(b.hasCommonTextureCoordinates()); + CORRADE_VERIFY(b.hasCommonTextureLayer()); CORRADE_COMPARE(b.commonTextureMatrix(), Matrix3::scaling({0.5f, 0.5f})); CORRADE_COMPARE(b.commonTextureCoordinates(), 7); + CORRADE_COMPARE(b.commonTextureLayer(), 22); } -void PbrMetallicRoughnessMaterialDataTest::commonTransformationCoordinatesOneTexture() { +void PbrMetallicRoughnessMaterialDataTest::commonTransformationCoordinatesLayerOneTexture() { Containers::StringView textureName = PbrMetallicRoughnessTextureData[testCaseInstanceId()]; setTestCaseDescription(textureName); @@ -785,19 +898,23 @@ void PbrMetallicRoughnessMaterialDataTest::commonTransformationCoordinatesOneTex {textureName, 5u}, {textureName + "Matrix", Matrix3::scaling({0.5f, 1.0f})}, {textureName + "Coordinates", 17u}, + {textureName + "Layer", 22u}, /* These shouldn't affect the above */ {MaterialAttribute::TextureMatrix, Matrix3::translation({0.5f, 0.0f})}, - {MaterialAttribute::TextureCoordinates, 3u} + {MaterialAttribute::TextureCoordinates, 3u}, + {MaterialAttribute::TextureLayer, 66u}, }}; CORRADE_VERIFY(data.hasCommonTextureTransformation()); CORRADE_COMPARE(data.commonTextureMatrix(), Matrix3::scaling({0.5f, 1.0f})); CORRADE_VERIFY(data.hasCommonTextureCoordinates()); CORRADE_COMPARE(data.commonTextureCoordinates(), 17u); + CORRADE_VERIFY(data.hasCommonTextureLayer()); + CORRADE_COMPARE(data.commonTextureLayer(), 22u); } -void PbrMetallicRoughnessMaterialDataTest::commonTransformationCoordinatesOneDifferentTexture() { +void PbrMetallicRoughnessMaterialDataTest::commonTransformationCoordinatesLayerOneDifferentTexture() { Containers::StringView textureName = PbrMetallicRoughnessTextureData[testCaseInstanceId()]; setTestCaseDescription(textureName); @@ -810,18 +927,21 @@ void PbrMetallicRoughnessMaterialDataTest::commonTransformationCoordinatesOneDif {MaterialAttribute::EmissiveTexture, 7u}, {textureName + "Matrix", Matrix3::scaling({0.5f, 1.0f})}, {textureName + "Coordinates", 17u}, + {textureName + "Layer", 22u}, /* These are used by all textures except the one above, failing the check */ {MaterialAttribute::TextureMatrix, Matrix3::translation({0.5f, 0.0f})}, - {MaterialAttribute::TextureCoordinates, 3u} + {MaterialAttribute::TextureCoordinates, 3u}, + {MaterialAttribute::TextureLayer, 66u}, }}; CORRADE_VERIFY(!data.hasCommonTextureTransformation()); CORRADE_VERIFY(!data.hasCommonTextureCoordinates()); + CORRADE_VERIFY(!data.hasCommonTextureLayer()); } -void PbrMetallicRoughnessMaterialDataTest::commonCoordinatesImplicit() { +void PbrMetallicRoughnessMaterialDataTest::commonCoordinatesLayerImplicit() { Containers::StringView textureName = PbrMetallicRoughnessTextureData[testCaseInstanceId()]; setTestCaseDescription(textureName); @@ -830,16 +950,20 @@ void PbrMetallicRoughnessMaterialDataTest::commonCoordinatesImplicit() { PbrMetallicRoughnessMaterialData data{{}, { {textureName, 5u}, - {textureName + "Coordinates", 0u} + {textureName + "Coordinates", 0u}, + {textureName + "Layer", 0u}, }}; /* Zero is treated same as if there would be no attribute at all */ CORRADE_VERIFY(!data.hasTextureCoordinates()); + CORRADE_VERIFY(!data.hasTextureLayer()); CORRADE_VERIFY(data.hasCommonTextureCoordinates()); + CORRADE_VERIFY(data.hasCommonTextureLayer()); CORRADE_COMPARE(data.commonTextureCoordinates(), 0u); + CORRADE_COMPARE(data.commonTextureLayer(), 0u); } -void PbrMetallicRoughnessMaterialDataTest::noCommonTransformationCoordinates() { +void PbrMetallicRoughnessMaterialDataTest::noCommonTransformationCoordinatesLayer() { #ifdef CORRADE_NO_ASSERT CORRADE_SKIP("CORRADE_NO_ASSERT defined, can't test assertions"); #endif @@ -850,20 +974,24 @@ void PbrMetallicRoughnessMaterialDataTest::noCommonTransformationCoordinates() { {MaterialAttribute::BaseColorTextureCoordinates, 3u}, {MaterialAttribute::MetalnessTexture, 4u}, {MaterialAttribute::MetalnessTextureMatrix, Matrix3::scaling({0.5f, 1.0f})}, + {MaterialAttribute::MetalnessTextureLayer, 22u}, {MaterialAttribute::RoughnessTexture, 5u}, {MaterialAttribute::RoughnessTextureCoordinates, 17u} }}; CORRADE_VERIFY(!data.hasCommonTextureTransformation()); CORRADE_VERIFY(!data.hasCommonTextureCoordinates()); + CORRADE_VERIFY(!data.hasCommonTextureLayer()); std::ostringstream out; Error redirectError{&out}; data.commonTextureMatrix(); data.commonTextureCoordinates(); + data.commonTextureLayer(); CORRADE_COMPARE(out.str(), "Trade::PbrMetallicRoughnessMaterialData::commonTextureMatrix(): the material doesn't have a common texture coordinate transformation\n" - "Trade::PbrMetallicRoughnessMaterialData::commonTextureCoordinates(): the material doesn't have a common texture coordinate set\n"); + "Trade::PbrMetallicRoughnessMaterialData::commonTextureCoordinates(): the material doesn't have a common texture coordinate set\n" + "Trade::PbrMetallicRoughnessMaterialData::commonTextureLayer(): the material doesn't have a common array texture layer\n"); } }}}} diff --git a/src/Magnum/Trade/Test/PbrSpecularGlossinessMaterialDataTest.cpp b/src/Magnum/Trade/Test/PbrSpecularGlossinessMaterialDataTest.cpp index bd5c59189..d9eb1649f 100644 --- a/src/Magnum/Trade/Test/PbrSpecularGlossinessMaterialDataTest.cpp +++ b/src/Magnum/Trade/Test/PbrSpecularGlossinessMaterialDataTest.cpp @@ -44,13 +44,13 @@ class PbrSpecularGlossinessMaterialDataTest: public TestSuite::Tester { void texturedDefaults(); void texturedImplicitPackedSpecularGlossiness(); void texturedExplicitPackedSpecularGlossiness(); - void texturedSingleMatrixCoordinates(); + void texturedSingleMatrixCoordinatesLayer(); void invalidTextures(); - void commonTransformationCoordinatesNoTextures(); - void commonTransformationCoordinatesOneTexture(); - void commonTransformationCoordinatesOneDifferentTexture(); - void commonCoordinatesImplicit(); - void noCommonTransformationCoordinates(); + void commonTransformationCoordinatesLayerNoTextures(); + void commonTransformationCoordinatesLayerOneTexture(); + void commonTransformationCoordinatesLayerOneDifferentTexture(); + void commonCoordinatesLayerImplicit(); + void noCommonTransformationCoordinatesLayer(); }; const Containers::StringView PbrSpecularGlossinessTextureData[] { @@ -69,17 +69,17 @@ PbrSpecularGlossinessMaterialDataTest::PbrSpecularGlossinessMaterialDataTest() { &PbrSpecularGlossinessMaterialDataTest::texturedDefaults, &PbrSpecularGlossinessMaterialDataTest::texturedImplicitPackedSpecularGlossiness, &PbrSpecularGlossinessMaterialDataTest::texturedExplicitPackedSpecularGlossiness, - &PbrSpecularGlossinessMaterialDataTest::texturedSingleMatrixCoordinates, + &PbrSpecularGlossinessMaterialDataTest::texturedSingleMatrixCoordinatesLayer, &PbrSpecularGlossinessMaterialDataTest::invalidTextures, - &PbrSpecularGlossinessMaterialDataTest::commonTransformationCoordinatesNoTextures}); + &PbrSpecularGlossinessMaterialDataTest::commonTransformationCoordinatesLayerNoTextures}); addInstancedTests({ - &PbrSpecularGlossinessMaterialDataTest::commonTransformationCoordinatesOneTexture, - &PbrSpecularGlossinessMaterialDataTest::commonTransformationCoordinatesOneDifferentTexture, - &PbrSpecularGlossinessMaterialDataTest::commonCoordinatesImplicit}, + &PbrSpecularGlossinessMaterialDataTest::commonTransformationCoordinatesLayerOneTexture, + &PbrSpecularGlossinessMaterialDataTest::commonTransformationCoordinatesLayerOneDifferentTexture, + &PbrSpecularGlossinessMaterialDataTest::commonCoordinatesLayerImplicit}, Containers::arraySize(PbrSpecularGlossinessTextureData)); - addTests({&PbrSpecularGlossinessMaterialDataTest::noCommonTransformationCoordinates}); + addTests({&PbrSpecularGlossinessMaterialDataTest::noCommonTransformationCoordinatesLayer}); } using namespace Math::Literals; @@ -100,6 +100,7 @@ void PbrSpecularGlossinessMaterialDataTest::basics() { CORRADE_VERIFY(!data.hasSpecularGlossinessTexture()); CORRADE_VERIFY(!data.hasTextureTransformation()); CORRADE_VERIFY(!data.hasTextureCoordinates()); + CORRADE_VERIFY(!data.hasTextureLayer()); CORRADE_COMPARE(data.diffuseColor(), 0xccffbbff_rgbaf); CORRADE_COMPARE(data.specularColor(), 0xff336600_rgbaf); CORRADE_COMPARE(data.glossiness(), 0.79f); @@ -117,6 +118,7 @@ void PbrSpecularGlossinessMaterialDataTest::defaults() { CORRADE_VERIFY(!data.hasSpecularGlossinessTexture()); CORRADE_VERIFY(!data.hasTextureTransformation()); CORRADE_VERIFY(!data.hasTextureCoordinates()); + CORRADE_VERIFY(!data.hasTextureLayer()); CORRADE_COMPARE(data.diffuseColor(), 0xffffffff_rgbaf); CORRADE_COMPARE(data.specularColor(), 0xffffff00_rgbaf); CORRADE_COMPARE(data.glossiness(), 1.0f); @@ -128,30 +130,36 @@ void PbrSpecularGlossinessMaterialDataTest::textured() { {MaterialAttribute::DiffuseTexture, 0u}, {MaterialAttribute::DiffuseTextureMatrix, Matrix3::scaling({0.5f, 1.0f})}, {MaterialAttribute::DiffuseTextureCoordinates, 2u}, + {MaterialAttribute::DiffuseTextureLayer, 8u}, {MaterialAttribute::SpecularColor, 0x33556600_rgbaf}, {MaterialAttribute::SpecularTexture, 1u}, {MaterialAttribute::SpecularTextureSwizzle, MaterialTextureSwizzle::RGBA}, {MaterialAttribute::SpecularTextureMatrix, Matrix3::scaling({0.5f, 0.5f})}, {MaterialAttribute::SpecularTextureCoordinates, 3u}, + {MaterialAttribute::SpecularTextureLayer, 9u}, {MaterialAttribute::Glossiness, 0.79f}, {MaterialAttribute::GlossinessTexture, 2u}, {MaterialAttribute::GlossinessTextureSwizzle, MaterialTextureSwizzle::A}, {MaterialAttribute::GlossinessTextureMatrix, Matrix3::scaling({1.0f, 1.0f})}, {MaterialAttribute::GlossinessTextureCoordinates, 4u}, + {MaterialAttribute::GlossinessTextureLayer, 10u}, {MaterialAttribute::NormalTexture, 3u}, {MaterialAttribute::NormalTextureScale, 0.35f}, {MaterialAttribute::NormalTextureSwizzle, MaterialTextureSwizzle::BA}, {MaterialAttribute::NormalTextureMatrix, Matrix3::scaling({1.0f, 0.5f})}, {MaterialAttribute::NormalTextureCoordinates, 5u}, + {MaterialAttribute::NormalTextureLayer, 11u}, {MaterialAttribute::OcclusionTexture, 4u}, {MaterialAttribute::OcclusionTextureStrength, 0.66f}, {MaterialAttribute::OcclusionTextureSwizzle, MaterialTextureSwizzle::B}, {MaterialAttribute::OcclusionTextureMatrix, Matrix3::scaling({1.0f, 0.75f})}, {MaterialAttribute::OcclusionTextureCoordinates, 6u}, + {MaterialAttribute::OcclusionTextureLayer, 12u}, {MaterialAttribute::EmissiveColor, 0x111111_rgbf}, {MaterialAttribute::EmissiveTexture, 5u}, {MaterialAttribute::EmissiveTextureMatrix, Matrix3::scaling({0.75f, 0.5f})}, - {MaterialAttribute::EmissiveTextureCoordinates, 7u} + {MaterialAttribute::EmissiveTextureCoordinates, 7u}, + {MaterialAttribute::EmissiveTextureLayer, 13u}, }}; CORRADE_VERIFY(data.hasSpecularTexture()); @@ -159,34 +167,41 @@ void PbrSpecularGlossinessMaterialDataTest::textured() { CORRADE_VERIFY(!data.hasSpecularGlossinessTexture()); CORRADE_VERIFY(data.hasTextureTransformation()); CORRADE_VERIFY(data.hasTextureCoordinates()); + CORRADE_VERIFY(data.hasTextureLayer()); CORRADE_COMPARE(data.diffuseColor(), 0xccffbbff_rgbaf); CORRADE_COMPARE(data.diffuseTexture(), 0); CORRADE_COMPARE(data.diffuseTextureMatrix(), Matrix3::scaling({0.5f, 1.0f})); CORRADE_COMPARE(data.diffuseTextureCoordinates(), 2); + CORRADE_COMPARE(data.diffuseTextureLayer(), 8); CORRADE_COMPARE(data.specularColor(), 0x33556600_rgbaf); CORRADE_COMPARE(data.specularTexture(), 1); CORRADE_COMPARE(data.specularTextureSwizzle(), MaterialTextureSwizzle::RGBA); CORRADE_COMPARE(data.specularTextureMatrix(), Matrix3::scaling({0.5f, 0.5f})); CORRADE_COMPARE(data.specularTextureCoordinates(), 3); + CORRADE_COMPARE(data.specularTextureLayer(), 9); CORRADE_COMPARE(data.glossiness(), 0.79f); CORRADE_COMPARE(data.glossinessTexture(), 2); CORRADE_COMPARE(data.glossinessTextureSwizzle(), MaterialTextureSwizzle::A); CORRADE_COMPARE(data.glossinessTextureMatrix(), Matrix3::scaling({1.0f, 1.0f})); CORRADE_COMPARE(data.glossinessTextureCoordinates(), 4); + CORRADE_COMPARE(data.glossinessTextureLayer(), 10); CORRADE_COMPARE(data.normalTexture(), 3); CORRADE_COMPARE(data.normalTextureScale(), 0.35f); CORRADE_COMPARE(data.normalTextureSwizzle(), MaterialTextureSwizzle::BA); CORRADE_COMPARE(data.normalTextureMatrix(), Matrix3::scaling({1.0f, 0.5f})); CORRADE_COMPARE(data.normalTextureCoordinates(), 5); + CORRADE_COMPARE(data.normalTextureLayer(), 11); CORRADE_COMPARE(data.occlusionTexture(), 4); CORRADE_COMPARE(data.occlusionTextureStrength(), 0.66f); CORRADE_COMPARE(data.occlusionTextureMatrix(), Matrix3::scaling({1.0f, 0.75f})); CORRADE_COMPARE(data.occlusionTextureSwizzle(), MaterialTextureSwizzle::B); CORRADE_COMPARE(data.occlusionTextureCoordinates(), 6); + CORRADE_COMPARE(data.occlusionTextureLayer(), 12); CORRADE_COMPARE(data.emissiveColor(), 0x111111_rgbf); CORRADE_COMPARE(data.emissiveTextureMatrix(), Matrix3::scaling({0.75f, 0.5f})); CORRADE_COMPARE(data.emissiveTexture(), 5); CORRADE_COMPARE(data.emissiveTextureCoordinates(), 7); + CORRADE_COMPARE(data.emissiveTextureLayer(), 13); } void PbrSpecularGlossinessMaterialDataTest::texturedDefaults() { @@ -204,37 +219,44 @@ void PbrSpecularGlossinessMaterialDataTest::texturedDefaults() { CORRADE_VERIFY(!data.hasSpecularGlossinessTexture()); CORRADE_VERIFY(!data.hasTextureTransformation()); CORRADE_VERIFY(!data.hasTextureCoordinates()); + CORRADE_VERIFY(!data.hasTextureLayer()); CORRADE_COMPARE(data.diffuseColor(), 0xffffffff_rgbaf); CORRADE_COMPARE(data.diffuseTexture(), 1); CORRADE_COMPARE(data.diffuseTextureMatrix(), Matrix3{}); CORRADE_COMPARE(data.diffuseTextureCoordinates(), 0); + CORRADE_COMPARE(data.diffuseTextureLayer(), 0); CORRADE_COMPARE(data.specularColor(), 0xffffff00_rgbaf); CORRADE_COMPARE(data.specularTexture(), 2); CORRADE_COMPARE(data.specularTextureSwizzle(), MaterialTextureSwizzle::RGB); CORRADE_COMPARE(data.specularTextureMatrix(), Matrix3{}); CORRADE_COMPARE(data.specularTextureCoordinates(), 0); + CORRADE_COMPARE(data.specularTextureLayer(), 0); CORRADE_COMPARE(data.glossiness(), 1.0f); CORRADE_COMPARE(data.glossinessTexture(), 3); CORRADE_COMPARE(data.glossinessTextureSwizzle(), MaterialTextureSwizzle::R); CORRADE_COMPARE(data.glossinessTextureMatrix(), Matrix3{}); CORRADE_COMPARE(data.glossinessTextureCoordinates(), 0); + CORRADE_COMPARE(data.glossinessTextureLayer(), 0); CORRADE_COMPARE(data.normalTexture(), 4); CORRADE_COMPARE(data.normalTextureScale(), 1.0f); CORRADE_COMPARE(data.normalTextureSwizzle(), MaterialTextureSwizzle::RGB); CORRADE_COMPARE(data.normalTextureMatrix(), Matrix3{}); CORRADE_COMPARE(data.normalTextureCoordinates(), 0); + CORRADE_COMPARE(data.normalTextureLayer(), 0); CORRADE_COMPARE(data.occlusionTexture(), 5); CORRADE_COMPARE(data.occlusionTextureStrength(), 1.0f); CORRADE_COMPARE(data.occlusionTextureMatrix(), Matrix3{}); CORRADE_COMPARE(data.occlusionTextureSwizzle(), MaterialTextureSwizzle::R); CORRADE_COMPARE(data.occlusionTextureCoordinates(), 0); + CORRADE_COMPARE(data.occlusionTextureLayer(), 0); CORRADE_COMPARE(data.emissiveColor(), 0x000000_rgbf); CORRADE_COMPARE(data.emissiveTextureMatrix(), Matrix3{}); CORRADE_COMPARE(data.emissiveTexture(), 6); CORRADE_COMPARE(data.emissiveTextureCoordinates(), 0); + CORRADE_COMPARE(data.emissiveTextureLayer(), 0); } -void PbrSpecularGlossinessMaterialDataTest::texturedSingleMatrixCoordinates() { +void PbrSpecularGlossinessMaterialDataTest::texturedSingleMatrixCoordinatesLayer() { PbrSpecularGlossinessMaterialData data{{}, { {MaterialAttribute::DiffuseTexture, 1u}, {MaterialAttribute::SpecularTexture, 2u}, @@ -243,23 +265,31 @@ void PbrSpecularGlossinessMaterialDataTest::texturedSingleMatrixCoordinates() { {MaterialAttribute::OcclusionTexture, 5u}, {MaterialAttribute::EmissiveTexture, 6u}, {MaterialAttribute::TextureMatrix, Matrix3::scaling({0.5f, 0.5f})}, - {MaterialAttribute::TextureCoordinates, 7u} + {MaterialAttribute::TextureCoordinates, 7u}, + {MaterialAttribute::TextureLayer, 22u}, }}; CORRADE_VERIFY(data.hasTextureTransformation()); CORRADE_VERIFY(data.hasTextureCoordinates()); + CORRADE_VERIFY(data.hasTextureLayer()); CORRADE_COMPARE(data.diffuseTextureMatrix(), Matrix3::scaling({0.5f, 0.5f})); CORRADE_COMPARE(data.diffuseTextureCoordinates(), 7); + CORRADE_COMPARE(data.diffuseTextureLayer(), 22); CORRADE_COMPARE(data.specularTextureMatrix(), Matrix3::scaling({0.5f, 0.5f})); CORRADE_COMPARE(data.specularTextureCoordinates(), 7); + CORRADE_COMPARE(data.specularTextureLayer(), 22); CORRADE_COMPARE(data.glossinessTextureMatrix(), Matrix3::scaling({0.5f, 0.5f})); CORRADE_COMPARE(data.glossinessTextureCoordinates(), 7); + CORRADE_COMPARE(data.glossinessTextureLayer(), 22); CORRADE_COMPARE(data.normalTextureMatrix(), Matrix3::scaling({0.5f, 0.5f})); CORRADE_COMPARE(data.normalTextureCoordinates(), 7); + CORRADE_COMPARE(data.normalTextureLayer(), 22); CORRADE_COMPARE(data.occlusionTextureMatrix(), Matrix3::scaling({0.5f, 0.5f})); CORRADE_COMPARE(data.occlusionTextureCoordinates(), 7); + CORRADE_COMPARE(data.occlusionTextureLayer(), 22); CORRADE_COMPARE(data.emissiveTextureMatrix(), Matrix3::scaling({0.5f, 0.5f})); CORRADE_COMPARE(data.emissiveTextureCoordinates(), 7); + CORRADE_COMPARE(data.emissiveTextureLayer(), 22); } void PbrSpecularGlossinessMaterialDataTest::texturedImplicitPackedSpecularGlossiness() { @@ -273,10 +303,12 @@ void PbrSpecularGlossinessMaterialDataTest::texturedImplicitPackedSpecularGlossi CORRADE_COMPARE(data.specularTextureSwizzle(), MaterialTextureSwizzle::RGB); CORRADE_COMPARE(data.specularTextureMatrix(), Matrix3{}); CORRADE_COMPARE(data.specularTextureCoordinates(), 0); + CORRADE_COMPARE(data.specularTextureLayer(), 0); CORRADE_COMPARE(data.glossinessTexture(), 2); CORRADE_COMPARE(data.glossinessTextureSwizzle(), MaterialTextureSwizzle::A); CORRADE_COMPARE(data.glossinessTextureMatrix(), Matrix3{}); CORRADE_COMPARE(data.glossinessTextureCoordinates(), 0); + CORRADE_COMPARE(data.glossinessTextureLayer(), 0); /* Explicit parameters for everything, but all the same */ } { @@ -285,19 +317,23 @@ void PbrSpecularGlossinessMaterialDataTest::texturedImplicitPackedSpecularGlossi {MaterialAttribute::SpecularTextureSwizzle, MaterialTextureSwizzle::RGB}, {MaterialAttribute::SpecularTextureMatrix, Matrix3::scaling({0.5f, 0.5f})}, {MaterialAttribute::SpecularTextureCoordinates, 3u}, + {MaterialAttribute::SpecularTextureLayer, 17u}, {MaterialAttribute::GlossinessTextureSwizzle, MaterialTextureSwizzle::A}, {MaterialAttribute::GlossinessTextureMatrix, Matrix3::scaling({0.5f, 0.5f})}, - {MaterialAttribute::GlossinessTextureCoordinates, 3u} + {MaterialAttribute::GlossinessTextureCoordinates, 3u}, + {MaterialAttribute::GlossinessTextureLayer, 17u} }}; CORRADE_VERIFY(data.hasSpecularGlossinessTexture()); CORRADE_COMPARE(data.specularTexture(), 2); CORRADE_COMPARE(data.specularTextureSwizzle(), MaterialTextureSwizzle::RGB); CORRADE_COMPARE(data.specularTextureMatrix(), Matrix3::scaling({0.5f, 0.5f})); CORRADE_COMPARE(data.specularTextureCoordinates(), 3); + CORRADE_COMPARE(data.specularTextureLayer(), 17); CORRADE_COMPARE(data.glossinessTexture(), 2); CORRADE_COMPARE(data.glossinessTextureSwizzle(), MaterialTextureSwizzle::A); CORRADE_COMPARE(data.glossinessTextureMatrix(), Matrix3::scaling({0.5f, 0.5f})); CORRADE_COMPARE(data.glossinessTextureCoordinates(), 3); + CORRADE_COMPARE(data.glossinessTextureLayer(), 17); /* Swizzle is ignored when the combined texture is specified, so this is fine. */ @@ -323,6 +359,14 @@ void PbrSpecularGlossinessMaterialDataTest::texturedImplicitPackedSpecularGlossi {MaterialAttribute::GlossinessTextureCoordinates, 1u}, }}; CORRADE_VERIFY(!data.hasSpecularGlossinessTexture()); + + /* Unexpected array texture layer */ + } { + PbrSpecularGlossinessMaterialData data{{}, { + {MaterialAttribute::SpecularGlossinessTexture, 2u}, + {MaterialAttribute::SpecularTextureLayer, 1u}, + }}; + CORRADE_VERIFY(!data.hasSpecularGlossinessTexture()); } } @@ -339,10 +383,12 @@ void PbrSpecularGlossinessMaterialDataTest::texturedExplicitPackedSpecularGlossi CORRADE_COMPARE(data.specularTextureSwizzle(), MaterialTextureSwizzle::RGB); CORRADE_COMPARE(data.specularTextureMatrix(), Matrix3{}); CORRADE_COMPARE(data.specularTextureCoordinates(), 0); + CORRADE_COMPARE(data.specularTextureLayer(), 0); CORRADE_COMPARE(data.glossinessTexture(), 2); CORRADE_COMPARE(data.glossinessTextureSwizzle(), MaterialTextureSwizzle::A); CORRADE_COMPARE(data.glossinessTextureMatrix(), Matrix3{}); CORRADE_COMPARE(data.glossinessTextureCoordinates(), 0); + CORRADE_COMPARE(data.glossinessTextureLayer(), 0); /* Explicit parameters for everything, but all the same */ } { @@ -351,20 +397,24 @@ void PbrSpecularGlossinessMaterialDataTest::texturedExplicitPackedSpecularGlossi {MaterialAttribute::SpecularTextureSwizzle, MaterialTextureSwizzle::RGB}, {MaterialAttribute::SpecularTextureMatrix, Matrix3::scaling({0.5f, 0.5f})}, {MaterialAttribute::SpecularTextureCoordinates, 3u}, + {MaterialAttribute::SpecularTextureLayer, 17u}, {MaterialAttribute::GlossinessTexture, 2u}, {MaterialAttribute::GlossinessTextureSwizzle, MaterialTextureSwizzle::A}, {MaterialAttribute::GlossinessTextureMatrix, Matrix3::scaling({0.5f, 0.5f})}, - {MaterialAttribute::GlossinessTextureCoordinates, 3u} + {MaterialAttribute::GlossinessTextureCoordinates, 3u}, + {MaterialAttribute::GlossinessTextureLayer, 17u} }}; CORRADE_VERIFY(data.hasSpecularGlossinessTexture()); CORRADE_COMPARE(data.specularTexture(), 2); CORRADE_COMPARE(data.specularTextureSwizzle(), MaterialTextureSwizzle::RGB); CORRADE_COMPARE(data.specularTextureMatrix(), Matrix3::scaling({0.5f, 0.5f})); CORRADE_COMPARE(data.specularTextureCoordinates(), 3); + CORRADE_COMPARE(data.specularTextureLayer(), 17); CORRADE_COMPARE(data.glossinessTexture(), 2); CORRADE_COMPARE(data.glossinessTextureSwizzle(), MaterialTextureSwizzle::A); CORRADE_COMPARE(data.glossinessTextureMatrix(), Matrix3::scaling({0.5f, 0.5f})); CORRADE_COMPARE(data.glossinessTextureCoordinates(), 3); + CORRADE_COMPARE(data.glossinessTextureLayer(), 17); /* Different texture ID */ } { @@ -413,6 +463,16 @@ void PbrSpecularGlossinessMaterialDataTest::texturedExplicitPackedSpecularGlossi {MaterialAttribute::GlossinessTextureCoordinates, 1u} }}; CORRADE_VERIFY(!data.hasSpecularGlossinessTexture()); + + /* Unexpected array texture layer */ + } { + PbrSpecularGlossinessMaterialData data{{}, { + {MaterialAttribute::SpecularTexture, 2u}, + {MaterialAttribute::SpecularTextureLayer, 1u}, + {MaterialAttribute::GlossinessTexture, 2u}, + {MaterialAttribute::GlossinessTextureSwizzle, MaterialTextureSwizzle::A}, + }}; + CORRADE_VERIFY(!data.hasSpecularGlossinessTexture()); } } @@ -428,72 +488,89 @@ void PbrSpecularGlossinessMaterialDataTest::invalidTextures() { data.diffuseTexture(); data.diffuseTextureMatrix(); data.diffuseTextureCoordinates(); + data.diffuseTextureLayer(); data.specularTexture(); data.specularTextureSwizzle(); data.specularTextureMatrix(); data.specularTextureCoordinates(); + data.specularTextureLayer(); data.glossinessTexture(); data.glossinessTextureSwizzle(); data.glossinessTextureMatrix(); data.glossinessTextureCoordinates(); + data.glossinessTextureLayer(); data.normalTexture(); data.normalTextureScale(); data.normalTextureSwizzle(); data.normalTextureMatrix(); data.normalTextureCoordinates(); + data.normalTextureLayer(); data.occlusionTexture(); data.occlusionTextureStrength(); data.occlusionTextureSwizzle(); data.occlusionTextureMatrix(); data.occlusionTextureCoordinates(); + data.occlusionTextureLayer(); data.emissiveTexture(); data.emissiveTextureMatrix(); data.emissiveTextureCoordinates(); + data.emissiveTextureLayer(); CORRADE_COMPARE(out.str(), "Trade::MaterialData::attribute(): attribute DiffuseTexture not found in layer 0\n" "Trade::PbrSpecularGlossinessMaterialData::diffuseTextureMatrix(): the material doesn't have a diffuse texture\n" "Trade::PbrSpecularGlossinessMaterialData::diffuseTextureCoordinates(): the material doesn't have a diffuse texture\n" + "Trade::PbrSpecularGlossinessMaterialData::diffuseTextureLayer(): the material doesn't have a diffuse texture\n" "Trade::PbrSpecularGlossinessMaterialData::specularTexture(): the material doesn't have a specular texture\n" "Trade::PbrSpecularGlossinessMaterialData::specularTextureSwizzle(): the material doesn't have a specular texture\n" "Trade::PbrSpecularGlossinessMaterialData::specularTextureMatrix(): the material doesn't have a specular texture\n" "Trade::PbrSpecularGlossinessMaterialData::specularTextureCoordinates(): the material doesn't have a specular texture\n" + "Trade::PbrSpecularGlossinessMaterialData::specularTextureLayer(): the material doesn't have a specular texture\n" "Trade::PbrSpecularGlossinessMaterialData::glossinessTexture(): the material doesn't have a glossiness texture\n" "Trade::PbrSpecularGlossinessMaterialData::glossinessTextureSwizzle(): the material doesn't have a glossiness texture\n" "Trade::PbrSpecularGlossinessMaterialData::glossinessTextureMatrix(): the material doesn't have a glossiness texture\n" "Trade::PbrSpecularGlossinessMaterialData::glossinessTextureCoordinates(): the material doesn't have a glossiness texture\n" + "Trade::PbrSpecularGlossinessMaterialData::glossinessTextureLayer(): the material doesn't have a glossiness texture\n" "Trade::MaterialData::attribute(): attribute NormalTexture not found in layer 0\n" "Trade::PbrSpecularGlossinessMaterialData::normalTextureScale(): the material doesn't have a normal texture\n" "Trade::PbrSpecularGlossinessMaterialData::normalTextureSwizzle(): the material doesn't have a normal texture\n" "Trade::PbrSpecularGlossinessMaterialData::normalTextureMatrix(): the material doesn't have a normal texture\n" "Trade::PbrSpecularGlossinessMaterialData::normalTextureCoordinates(): the material doesn't have a normal texture\n" + "Trade::PbrSpecularGlossinessMaterialData::normalTextureLayer(): the material doesn't have a normal texture\n" "Trade::MaterialData::attribute(): attribute OcclusionTexture not found in layer 0\n" "Trade::PbrSpecularGlossinessMaterialData::occlusionTextureStrength(): the material doesn't have an occlusion texture\n" "Trade::PbrSpecularGlossinessMaterialData::occlusionTextureSwizzle(): the material doesn't have an occlusion texture\n" "Trade::PbrSpecularGlossinessMaterialData::occlusionTextureMatrix(): the material doesn't have an occlusion texture\n" "Trade::PbrSpecularGlossinessMaterialData::occlusionTextureCoordinates(): the material doesn't have an occlusion texture\n" + "Trade::PbrSpecularGlossinessMaterialData::occlusionTextureLayer(): the material doesn't have an occlusion texture\n" "Trade::MaterialData::attribute(): attribute EmissiveTexture not found in layer 0\n" "Trade::PbrSpecularGlossinessMaterialData::emissiveTextureMatrix(): the material doesn't have an emissive texture\n" - "Trade::PbrSpecularGlossinessMaterialData::emissiveTextureCoordinates(): the material doesn't have an emissive texture\n"); + "Trade::PbrSpecularGlossinessMaterialData::emissiveTextureCoordinates(): the material doesn't have an emissive texture\n" + "Trade::PbrSpecularGlossinessMaterialData::emissiveTextureLayer(): the material doesn't have an emissive texture\n"); } -void PbrSpecularGlossinessMaterialDataTest::commonTransformationCoordinatesNoTextures() { +void PbrSpecularGlossinessMaterialDataTest::commonTransformationCoordinatesLayerNoTextures() { PbrSpecularGlossinessMaterialData a{{}, {}}; CORRADE_VERIFY(a.hasCommonTextureTransformation()); CORRADE_VERIFY(a.hasCommonTextureCoordinates()); + CORRADE_VERIFY(a.hasCommonTextureLayer()); CORRADE_COMPARE(a.commonTextureMatrix(), Matrix3{}); CORRADE_COMPARE(a.commonTextureCoordinates(), 0); + CORRADE_COMPARE(a.commonTextureLayer(), 0); PbrSpecularGlossinessMaterialData b{{}, { {MaterialAttribute::TextureMatrix, Matrix3::scaling({0.5f, 0.5f})}, - {MaterialAttribute::TextureCoordinates, 7u} + {MaterialAttribute::TextureCoordinates, 7u}, + {MaterialAttribute::TextureLayer, 22u} }}; CORRADE_VERIFY(b.hasCommonTextureTransformation()); CORRADE_VERIFY(b.hasCommonTextureCoordinates()); + CORRADE_VERIFY(b.hasCommonTextureLayer()); CORRADE_COMPARE(b.commonTextureMatrix(), Matrix3::scaling({0.5f, 0.5f})); CORRADE_COMPARE(b.commonTextureCoordinates(), 7); + CORRADE_COMPARE(b.commonTextureLayer(), 22); } -void PbrSpecularGlossinessMaterialDataTest::commonTransformationCoordinatesOneTexture() { +void PbrSpecularGlossinessMaterialDataTest::commonTransformationCoordinatesLayerOneTexture() { Containers::StringView textureName = PbrSpecularGlossinessTextureData[testCaseInstanceId()]; setTestCaseDescription(textureName); @@ -501,19 +578,23 @@ void PbrSpecularGlossinessMaterialDataTest::commonTransformationCoordinatesOneTe {textureName, 5u}, {textureName + "Matrix", Matrix3::scaling({0.5f, 1.0f})}, {textureName + "Coordinates", 17u}, + {textureName + "Layer", 22u}, /* These shouldn't affect the above */ {MaterialAttribute::TextureMatrix, Matrix3::translation({0.5f, 0.0f})}, - {MaterialAttribute::TextureCoordinates, 3u} + {MaterialAttribute::TextureCoordinates, 3u}, + {MaterialAttribute::TextureLayer, 66u}, }}; CORRADE_VERIFY(data.hasCommonTextureTransformation()); CORRADE_COMPARE(data.commonTextureMatrix(), Matrix3::scaling({0.5f, 1.0f})); CORRADE_VERIFY(data.hasCommonTextureCoordinates()); CORRADE_COMPARE(data.commonTextureCoordinates(), 17u); + CORRADE_VERIFY(data.hasCommonTextureLayer()); + CORRADE_COMPARE(data.commonTextureLayer(), 22u); } -void PbrSpecularGlossinessMaterialDataTest::commonTransformationCoordinatesOneDifferentTexture() { +void PbrSpecularGlossinessMaterialDataTest::commonTransformationCoordinatesLayerOneDifferentTexture() { Containers::StringView textureName = PbrSpecularGlossinessTextureData[testCaseInstanceId()]; setTestCaseDescription(textureName); @@ -526,18 +607,21 @@ void PbrSpecularGlossinessMaterialDataTest::commonTransformationCoordinatesOneDi {MaterialAttribute::EmissiveTexture, 7u}, {textureName + "Matrix", Matrix3::scaling({0.5f, 1.0f})}, {textureName + "Coordinates", 17u}, + {textureName + "Layer", 22u}, /* These are used by all textures except the one above, failing the check */ {MaterialAttribute::TextureMatrix, Matrix3::translation({0.5f, 0.0f})}, - {MaterialAttribute::TextureCoordinates, 3u} + {MaterialAttribute::TextureCoordinates, 3u}, + {MaterialAttribute::TextureLayer, 66u}, }}; CORRADE_VERIFY(!data.hasCommonTextureTransformation()); CORRADE_VERIFY(!data.hasCommonTextureCoordinates()); + CORRADE_VERIFY(!data.hasCommonTextureLayer()); } -void PbrSpecularGlossinessMaterialDataTest::commonCoordinatesImplicit() { +void PbrSpecularGlossinessMaterialDataTest::commonCoordinatesLayerImplicit() { Containers::StringView textureName = PbrSpecularGlossinessTextureData[testCaseInstanceId()]; setTestCaseDescription(textureName); @@ -546,16 +630,20 @@ void PbrSpecularGlossinessMaterialDataTest::commonCoordinatesImplicit() { PbrSpecularGlossinessMaterialData data{{}, { {textureName, 5u}, - {textureName + "Coordinates", 0u} + {textureName + "Coordinates", 0u}, + {textureName + "Layer", 0u}, }}; /* Zero is treated same as if there would be no attribute at all */ CORRADE_VERIFY(!data.hasTextureCoordinates()); + CORRADE_VERIFY(!data.hasTextureLayer()); CORRADE_VERIFY(data.hasCommonTextureCoordinates()); + CORRADE_VERIFY(data.hasCommonTextureLayer()); CORRADE_COMPARE(data.commonTextureCoordinates(), 0u); + CORRADE_COMPARE(data.commonTextureLayer(), 0u); } -void PbrSpecularGlossinessMaterialDataTest::noCommonTransformationCoordinates() { +void PbrSpecularGlossinessMaterialDataTest::noCommonTransformationCoordinatesLayer() { #ifdef CORRADE_NO_ASSERT CORRADE_SKIP("CORRADE_NO_ASSERT defined, can't test assertions"); #endif @@ -566,20 +654,24 @@ void PbrSpecularGlossinessMaterialDataTest::noCommonTransformationCoordinates() {MaterialAttribute::DiffuseTextureCoordinates, 3u}, {MaterialAttribute::SpecularTexture, 4u}, {MaterialAttribute::SpecularTextureMatrix, Matrix3::scaling({0.5f, 1.0f})}, + {MaterialAttribute::SpecularTextureLayer, 22u}, {MaterialAttribute::OcclusionTexture, 5u}, {MaterialAttribute::OcclusionTextureCoordinates, 17u} }}; CORRADE_VERIFY(!data.hasCommonTextureTransformation()); CORRADE_VERIFY(!data.hasCommonTextureCoordinates()); + CORRADE_VERIFY(!data.hasCommonTextureLayer()); std::ostringstream out; Error redirectError{&out}; data.commonTextureMatrix(); data.commonTextureCoordinates(); + data.commonTextureLayer(); CORRADE_COMPARE(out.str(), "Trade::PbrSpecularGlossinessMaterialData::commonTextureMatrix(): the material doesn't have a common texture coordinate transformation\n" - "Trade::PbrSpecularGlossinessMaterialData::commonTextureCoordinates(): the material doesn't have a common texture coordinate set\n"); + "Trade::PbrSpecularGlossinessMaterialData::commonTextureCoordinates(): the material doesn't have a common texture coordinate set\n" + "Trade::PbrSpecularGlossinessMaterialData::commonTextureLayer(): the material doesn't have a common array texture layer\n"); } }}}} diff --git a/src/Magnum/Trade/Test/PhongMaterialDataTest.cpp b/src/Magnum/Trade/Test/PhongMaterialDataTest.cpp index 9d6dea1ce..6bc5f7458 100644 --- a/src/Magnum/Trade/Test/PhongMaterialDataTest.cpp +++ b/src/Magnum/Trade/Test/PhongMaterialDataTest.cpp @@ -52,14 +52,14 @@ class PhongMaterialDataTest: public TestSuite::Tester { void defaults(); void textured(); void texturedDefaults(); - void texturedSingleMatrixCoordinates(); + void texturedSingleMatrixCoordinatesLayer(); void texturedImplicitPackedSpecularGlossiness(); void invalidTextures(); - void commonTransformationCoordinatesNoTextures(); - void commonTransformationCoordinatesOneTexture(); - void commonTransformationCoordinatesOneDifferentTexture(); - void commonCoordinatesImplicit(); - void noCommonTransformationCoordinates(); + void commonTransformationCoordinatesLayerNoTextures(); + void commonTransformationCoordinatesLayerOneTexture(); + void commonTransformationCoordinatesLayerOneDifferentTexture(); + void commonCoordinatesLayerImplicit(); + void noCommonTransformationCoordinatesLayer(); #ifdef MAGNUM_BUILD_DEPRECATED void debugFlag(); @@ -90,19 +90,20 @@ PhongMaterialDataTest::PhongMaterialDataTest() { &PhongMaterialDataTest::defaults, &PhongMaterialDataTest::textured, &PhongMaterialDataTest::texturedDefaults, - &PhongMaterialDataTest::texturedSingleMatrixCoordinates, + &PhongMaterialDataTest::texturedSingleMatrixCoordinatesLayer, &PhongMaterialDataTest::texturedImplicitPackedSpecularGlossiness, &PhongMaterialDataTest::invalidTextures, - &PhongMaterialDataTest::commonTransformationCoordinatesNoTextures}); + &PhongMaterialDataTest::commonTransformationCoordinatesLayerNoTextures}); addInstancedTests({ - &PhongMaterialDataTest::commonTransformationCoordinatesOneTexture, - &PhongMaterialDataTest::commonTransformationCoordinatesOneDifferentTexture, - &PhongMaterialDataTest::commonCoordinatesImplicit}, + &PhongMaterialDataTest::commonTransformationCoordinatesLayerOneTexture, + &PhongMaterialDataTest::commonTransformationCoordinatesLayerOneDifferentTexture, + &PhongMaterialDataTest::commonCoordinatesLayerImplicit}, Containers::arraySize(PhongTextureData)); addTests({ - &PhongMaterialDataTest::noCommonTransformationCoordinates, + &PhongMaterialDataTest::noCommonTransformationCoordinatesLayer, + #ifdef MAGNUM_BUILD_DEPRECATED &PhongMaterialDataTest::debugFlag, &PhongMaterialDataTest::debugFlags @@ -310,6 +311,7 @@ void PhongMaterialDataTest::basics() { CORRADE_VERIFY(!data.hasSpecularTexture()); CORRADE_VERIFY(!data.hasTextureTransformation()); CORRADE_VERIFY(!data.hasTextureCoordinates()); + CORRADE_VERIFY(!data.hasTextureLayer()); CORRADE_COMPARE(data.ambientColor(), 0xccffbb_rgbf); CORRADE_COMPARE(data.diffuseColor(), 0xebefbf_rgbf); CORRADE_COMPARE(data.specularColor(), 0xacabad_rgbf); @@ -325,6 +327,7 @@ void PhongMaterialDataTest::defaults() { CORRADE_VERIFY(!data.hasTextureTransformation()); CORRADE_VERIFY(!data.hasTextureCoordinates()); + CORRADE_VERIFY(!data.hasTextureLayer()); CORRADE_COMPARE(data.ambientColor(), 0x000000_rgbf); CORRADE_COMPARE(data.diffuseColor(), 0xffffff_rgbf); CORRADE_COMPARE(data.specularColor(), 0xffffff00_rgbaf); @@ -337,43 +340,52 @@ void PhongMaterialDataTest::textured() { {MaterialAttribute::AmbientTexture, 42u}, {MaterialAttribute::AmbientTextureMatrix, Matrix3::scaling({0.5f, 1.0f})}, {MaterialAttribute::AmbientTextureCoordinates, 2u}, + {MaterialAttribute::AmbientTextureLayer, 6u}, {MaterialAttribute::DiffuseTexture, 33u}, {MaterialAttribute::DiffuseColor, 0xeebbffff_rgbaf}, {MaterialAttribute::DiffuseTextureMatrix, Matrix3::scaling({0.5f, 0.5f})}, {MaterialAttribute::DiffuseTextureCoordinates, 3u}, + {MaterialAttribute::DiffuseTextureLayer, 7u}, {MaterialAttribute::SpecularColor, 0xacabadff_rgbaf}, {MaterialAttribute::SpecularTexture, 17u}, {MaterialAttribute::SpecularTextureSwizzle, MaterialTextureSwizzle::RGBA}, {MaterialAttribute::SpecularTextureMatrix, Matrix3::scaling({1.0f, 1.0f})}, {MaterialAttribute::SpecularTextureCoordinates, 4u}, + {MaterialAttribute::SpecularTextureLayer, 8u}, {MaterialAttribute::NormalTexture, 0u}, {MaterialAttribute::NormalTextureScale, 0.5f}, {MaterialAttribute::NormalTextureSwizzle, MaterialTextureSwizzle::GB}, {MaterialAttribute::NormalTextureMatrix, Matrix3::scaling({1.0f, 0.5f})}, - {MaterialAttribute::NormalTextureCoordinates, 5u} + {MaterialAttribute::NormalTextureCoordinates, 5u}, + {MaterialAttribute::NormalTextureLayer, 9u}, }}; CORRADE_VERIFY(data.hasSpecularTexture()); CORRADE_VERIFY(data.hasTextureTransformation()); CORRADE_VERIFY(data.hasTextureCoordinates()); + CORRADE_VERIFY(data.hasTextureLayer()); CORRADE_COMPARE(data.ambientColor(), 0x111111_rgbf); CORRADE_COMPARE(data.ambientTexture(), 42); CORRADE_COMPARE(data.ambientTextureMatrix(), Matrix3::scaling({0.5f, 1.0f})); CORRADE_COMPARE(data.ambientTextureCoordinates(), 2); + CORRADE_COMPARE(data.ambientTextureLayer(), 6); CORRADE_COMPARE(data.diffuseColor(), 0xeebbff_rgbf); CORRADE_COMPARE(data.diffuseTexture(), 33); CORRADE_COMPARE(data.diffuseTextureMatrix(), Matrix3::scaling({0.5f, 0.5f})); CORRADE_COMPARE(data.diffuseTextureCoordinates(), 3); + CORRADE_COMPARE(data.diffuseTextureLayer(), 7); CORRADE_COMPARE(data.specularColor(), 0xacabad_rgbf); CORRADE_COMPARE(data.specularTexture(), 17); CORRADE_COMPARE(data.specularTextureSwizzle(), MaterialTextureSwizzle::RGBA); CORRADE_COMPARE(data.specularTextureMatrix(), Matrix3::scaling({1.0f, 1.0f})); CORRADE_COMPARE(data.specularTextureCoordinates(), 4); + CORRADE_COMPARE(data.specularTextureLayer(), 8); CORRADE_COMPARE(data.normalTexture(), 0); CORRADE_COMPARE(data.normalTextureScale(), 0.5f); CORRADE_COMPARE(data.normalTextureSwizzle(), MaterialTextureSwizzle::GB); CORRADE_COMPARE(data.normalTextureMatrix(), Matrix3::scaling({1.0f, 0.5f})); CORRADE_COMPARE(data.normalTextureCoordinates(), 5); + CORRADE_COMPARE(data.normalTextureLayer(), 9); } void PhongMaterialDataTest::texturedDefaults() { @@ -387,46 +399,57 @@ void PhongMaterialDataTest::texturedDefaults() { CORRADE_VERIFY(data.hasSpecularTexture()); CORRADE_VERIFY(!data.hasTextureTransformation()); CORRADE_VERIFY(!data.hasTextureCoordinates()); + CORRADE_VERIFY(!data.hasTextureLayer()); CORRADE_COMPARE(data.ambientColor(), 0xffffffff_rgbaf); CORRADE_COMPARE(data.ambientTexture(), 42); CORRADE_COMPARE(data.ambientTextureMatrix(), Matrix3{}); CORRADE_COMPARE(data.ambientTextureCoordinates(), 0); + CORRADE_COMPARE(data.ambientTextureLayer(), 0); CORRADE_COMPARE(data.diffuseColor(), 0xffffffff_rgbaf); CORRADE_COMPARE(data.diffuseTexture(), 33); CORRADE_COMPARE(data.diffuseTextureMatrix(), Matrix3{}); CORRADE_COMPARE(data.diffuseTextureCoordinates(), 0); + CORRADE_COMPARE(data.diffuseTextureLayer(), 0); CORRADE_COMPARE(data.specularColor(), 0xffffff00_rgbaf); CORRADE_COMPARE(data.specularTexture(), 17); CORRADE_COMPARE(data.specularTextureSwizzle(), MaterialTextureSwizzle::RGB); CORRADE_COMPARE(data.specularTextureMatrix(), Matrix3{}); CORRADE_COMPARE(data.specularTextureCoordinates(), 0); + CORRADE_COMPARE(data.specularTextureLayer(), 0); CORRADE_COMPARE(data.normalTexture(), 1); CORRADE_COMPARE(data.normalTextureScale(), 1.0f); CORRADE_COMPARE(data.normalTextureSwizzle(), MaterialTextureSwizzle::RGB); CORRADE_COMPARE(data.normalTextureMatrix(), Matrix3{}); CORRADE_COMPARE(data.normalTextureCoordinates(), 0); + CORRADE_COMPARE(data.normalTextureLayer(), 0); } -void PhongMaterialDataTest::texturedSingleMatrixCoordinates() { +void PhongMaterialDataTest::texturedSingleMatrixCoordinatesLayer() { PhongMaterialData data{{}, { {MaterialAttribute::AmbientTexture, 42u}, {MaterialAttribute::DiffuseTexture, 33u}, {MaterialAttribute::SpecularTexture, 17u}, {MaterialAttribute::NormalTexture, 0u}, {MaterialAttribute::TextureMatrix, Matrix3::translation({0.5f, 1.0f})}, - {MaterialAttribute::TextureCoordinates, 2u} + {MaterialAttribute::TextureCoordinates, 2u}, + {MaterialAttribute::TextureLayer, 17u}, }}; CORRADE_VERIFY(data.hasTextureTransformation()); CORRADE_VERIFY(data.hasTextureCoordinates()); + CORRADE_VERIFY(data.hasTextureLayer()); CORRADE_COMPARE(data.ambientTextureMatrix(), Matrix3::translation({0.5f, 1.0f})); CORRADE_COMPARE(data.ambientTextureCoordinates(), 2); + CORRADE_COMPARE(data.ambientTextureLayer(), 17); CORRADE_COMPARE(data.diffuseTextureMatrix(), Matrix3::translation({0.5f, 1.0f})); CORRADE_COMPARE(data.diffuseTextureCoordinates(), 2); + CORRADE_COMPARE(data.diffuseTextureLayer(), 17); CORRADE_COMPARE(data.specularTextureMatrix(), Matrix3::translation({0.5f, 1.0f})); CORRADE_COMPARE(data.specularTextureCoordinates(), 2); + CORRADE_COMPARE(data.specularTextureLayer(), 17); CORRADE_COMPARE(data.normalTextureMatrix(), Matrix3::translation({0.5f, 1.0f})); CORRADE_COMPARE(data.normalTextureCoordinates(), 2); + CORRADE_COMPARE(data.normalTextureLayer(), 17); } void PhongMaterialDataTest::texturedImplicitPackedSpecularGlossiness() { @@ -435,6 +458,7 @@ void PhongMaterialDataTest::texturedImplicitPackedSpecularGlossiness() { {MaterialAttribute::SpecularGlossinessTexture, 17u}, {MaterialAttribute::SpecularTextureMatrix, Matrix3::scaling({1.0f, 1.0f})}, {MaterialAttribute::SpecularTextureCoordinates, 4u}, + {MaterialAttribute::SpecularTextureLayer, 22u}, }}; #ifdef MAGNUM_BUILD_DEPRECATED @@ -445,11 +469,13 @@ void PhongMaterialDataTest::texturedImplicitPackedSpecularGlossiness() { CORRADE_VERIFY(data.hasSpecularTexture()); CORRADE_VERIFY(data.hasTextureTransformation()); CORRADE_VERIFY(data.hasTextureCoordinates()); + CORRADE_VERIFY(data.hasTextureLayer()); CORRADE_COMPARE(data.specularColor(), 0xacabad_rgbf); CORRADE_COMPARE(data.specularTexture(), 17); CORRADE_COMPARE(data.specularTextureSwizzle(), MaterialTextureSwizzle::RGB); CORRADE_COMPARE(data.specularTextureMatrix(), Matrix3::scaling({1.0f, 1.0f})); CORRADE_COMPARE(data.specularTextureCoordinates(), 4); + CORRADE_COMPARE(data.specularTextureLayer(), 22); } void PhongMaterialDataTest::invalidTextures() { @@ -464,42 +490,52 @@ void PhongMaterialDataTest::invalidTextures() { data.ambientTexture(); data.ambientTextureMatrix(); data.ambientTextureCoordinates(); + data.ambientTextureLayer(); data.diffuseTexture(); data.diffuseTextureMatrix(); data.diffuseTextureCoordinates(); + data.diffuseTextureLayer(); data.specularTexture(); data.specularTextureSwizzle(); data.specularTextureMatrix(); data.specularTextureCoordinates(); + data.specularTextureLayer(); data.normalTexture(); data.normalTextureScale(); data.normalTextureSwizzle(); data.normalTextureMatrix(); data.normalTextureCoordinates(); + data.normalTextureLayer(); CORRADE_COMPARE(out.str(), "Trade::MaterialData::attribute(): attribute AmbientTexture not found in layer 0\n" "Trade::PhongMaterialData::ambientTextureMatrix(): the material doesn't have an ambient texture\n" "Trade::PhongMaterialData::ambientTextureCoordinates(): the material doesn't have an ambient texture\n" + "Trade::PhongMaterialData::ambientTextureLayer(): the material doesn't have an ambient texture\n" "Trade::MaterialData::attribute(): attribute DiffuseTexture not found in layer 0\n" "Trade::PhongMaterialData::diffuseTextureMatrix(): the material doesn't have a diffuse texture\n" "Trade::PhongMaterialData::diffuseTextureCoordinates(): the material doesn't have a diffuse texture\n" + "Trade::PhongMaterialData::diffuseTextureLayer(): the material doesn't have a diffuse texture\n" "Trade::PhongMaterialData::specularTexture(): the material doesn't have a specular texture\n" "Trade::PhongMaterialData::specularTextureSwizzle(): the material doesn't have a specular texture\n" "Trade::PhongMaterialData::specularTextureMatrix(): the material doesn't have a specular texture\n" "Trade::PhongMaterialData::specularTextureCoordinates(): the material doesn't have a specular texture\n" + "Trade::PhongMaterialData::specularTextureLayer(): the material doesn't have a specular texture\n" "Trade::MaterialData::attribute(): attribute NormalTexture not found in layer 0\n" "Trade::PhongMaterialData::normalTextureScale(): the material doesn't have a normal texture\n" "Trade::PhongMaterialData::normalTextureSwizzle(): the material doesn't have a normal texture\n" "Trade::PhongMaterialData::normalTextureMatrix(): the material doesn't have a normal texture\n" - "Trade::PhongMaterialData::normalTextureCoordinates(): the material doesn't have a normal texture\n"); + "Trade::PhongMaterialData::normalTextureCoordinates(): the material doesn't have a normal texture\n" + "Trade::PhongMaterialData::normalTextureLayer(): the material doesn't have a normal texture\n"); } -void PhongMaterialDataTest::commonTransformationCoordinatesNoTextures() { +void PhongMaterialDataTest::commonTransformationCoordinatesLayerNoTextures() { PhongMaterialData a{{}, {}}; CORRADE_VERIFY(a.hasCommonTextureTransformation()); CORRADE_VERIFY(a.hasCommonTextureCoordinates()); + CORRADE_VERIFY(a.hasCommonTextureLayer()); CORRADE_COMPARE(a.commonTextureMatrix(), Matrix3{}); CORRADE_COMPARE(a.commonTextureCoordinates(), 0); + CORRADE_COMPARE(a.commonTextureLayer(), 0); #ifdef MAGNUM_BUILD_DEPRECATED /* textureMatrix() should return the common matrix, if possible, and @@ -511,12 +547,15 @@ void PhongMaterialDataTest::commonTransformationCoordinatesNoTextures() { PhongMaterialData b{{}, { {MaterialAttribute::TextureMatrix, Matrix3::scaling({0.5f, 0.5f})}, - {MaterialAttribute::TextureCoordinates, 7u} + {MaterialAttribute::TextureCoordinates, 7u}, + {MaterialAttribute::TextureLayer, 22u}, }}; CORRADE_VERIFY(b.hasCommonTextureTransformation()); CORRADE_VERIFY(b.hasCommonTextureCoordinates()); + CORRADE_VERIFY(b.hasCommonTextureLayer()); CORRADE_COMPARE(b.commonTextureMatrix(), Matrix3::scaling({0.5f, 0.5f})); CORRADE_COMPARE(b.commonTextureCoordinates(), 7); + CORRADE_COMPARE(b.commonTextureLayer(), 22); #ifdef MAGNUM_BUILD_DEPRECATED /* textureMatrix() should return the common matrix, if possible, and @@ -527,7 +566,7 @@ void PhongMaterialDataTest::commonTransformationCoordinatesNoTextures() { #endif } -void PhongMaterialDataTest::commonTransformationCoordinatesOneTexture() { +void PhongMaterialDataTest::commonTransformationCoordinatesLayerOneTexture() { Containers::StringView textureName = PhongTextureData[testCaseInstanceId()]; setTestCaseDescription(textureName); @@ -535,16 +574,20 @@ void PhongMaterialDataTest::commonTransformationCoordinatesOneTexture() { {textureName, 5u}, {textureName + "Matrix", Matrix3::scaling({0.5f, 1.0f})}, {textureName + "Coordinates", 17u}, + {textureName + "Layer", 22u}, /* These shouldn't affect the above */ {MaterialAttribute::TextureMatrix, Matrix3::translation({0.5f, 0.0f})}, - {MaterialAttribute::TextureCoordinates, 3u} + {MaterialAttribute::TextureCoordinates, 3u}, + {MaterialAttribute::TextureLayer, 66u}, }}; CORRADE_VERIFY(data.hasCommonTextureTransformation()); CORRADE_COMPARE(data.commonTextureMatrix(), Matrix3::scaling({0.5f, 1.0f})); CORRADE_VERIFY(data.hasCommonTextureCoordinates()); CORRADE_COMPARE(data.commonTextureCoordinates(), 17u); + CORRADE_VERIFY(data.hasCommonTextureLayer()); + CORRADE_COMPARE(data.commonTextureLayer(), 22u); #ifdef MAGNUM_BUILD_DEPRECATED /* textureMatrix() should return the common matrix, if possible, and @@ -555,7 +598,7 @@ void PhongMaterialDataTest::commonTransformationCoordinatesOneTexture() { #endif } -void PhongMaterialDataTest::commonTransformationCoordinatesOneDifferentTexture() { +void PhongMaterialDataTest::commonTransformationCoordinatesLayerOneDifferentTexture() { Containers::StringView textureName = PhongTextureData[testCaseInstanceId()]; setTestCaseDescription(textureName); @@ -566,15 +609,18 @@ void PhongMaterialDataTest::commonTransformationCoordinatesOneDifferentTexture() {MaterialAttribute::NormalTexture, 5u}, {textureName + "Matrix", Matrix3::scaling({0.5f, 1.0f})}, {textureName + "Coordinates", 17u}, + {textureName + "Layer", 22u}, /* These are used by all textures except the one above, failing the check */ {MaterialAttribute::TextureMatrix, Matrix3::translation({0.5f, 0.0f})}, - {MaterialAttribute::TextureCoordinates, 3u} + {MaterialAttribute::TextureCoordinates, 3u}, + {MaterialAttribute::TextureLayer, 66u}, }}; CORRADE_VERIFY(!data.hasCommonTextureTransformation()); CORRADE_VERIFY(!data.hasCommonTextureCoordinates()); + CORRADE_VERIFY(!data.hasCommonTextureLayer()); #ifdef MAGNUM_BUILD_DEPRECATED /* textureMatrix() should return the common matrix, if possible, and @@ -585,7 +631,7 @@ void PhongMaterialDataTest::commonTransformationCoordinatesOneDifferentTexture() #endif } -void PhongMaterialDataTest::commonCoordinatesImplicit() { +void PhongMaterialDataTest::commonCoordinatesLayerImplicit() { Containers::StringView textureName = PhongTextureData[testCaseInstanceId()]; setTestCaseDescription(textureName); @@ -594,16 +640,20 @@ void PhongMaterialDataTest::commonCoordinatesImplicit() { PhongMaterialData data{{}, { {textureName, 5u}, - {textureName + "Coordinates", 0u} + {textureName + "Coordinates", 0u}, + {textureName + "Layer", 0u} }}; /* Zero is treated same as if there would be no attribute at all */ CORRADE_VERIFY(!data.hasTextureCoordinates()); + CORRADE_VERIFY(!data.hasTextureLayer()); CORRADE_VERIFY(data.hasCommonTextureCoordinates()); + CORRADE_VERIFY(data.hasCommonTextureLayer()); CORRADE_COMPARE(data.commonTextureCoordinates(), 0u); + CORRADE_COMPARE(data.commonTextureLayer(), 0u); } -void PhongMaterialDataTest::noCommonTransformationCoordinates() { +void PhongMaterialDataTest::noCommonTransformationCoordinatesLayer() { #ifdef CORRADE_NO_ASSERT CORRADE_SKIP("CORRADE_NO_ASSERT defined, can't test assertions"); #endif @@ -614,20 +664,24 @@ void PhongMaterialDataTest::noCommonTransformationCoordinates() { {MaterialAttribute::DiffuseTextureCoordinates, 3u}, {MaterialAttribute::SpecularTexture, 4u}, {MaterialAttribute::SpecularTextureMatrix, Matrix3::scaling({0.5f, 1.0f})}, + {MaterialAttribute::SpecularTextureLayer, 22u}, {MaterialAttribute::NormalTexture, 5u}, {MaterialAttribute::NormalTextureCoordinates, 17u} }}; CORRADE_VERIFY(!data.hasCommonTextureTransformation()); CORRADE_VERIFY(!data.hasCommonTextureCoordinates()); + CORRADE_VERIFY(!data.hasCommonTextureLayer()); std::ostringstream out; Error redirectError{&out}; data.commonTextureMatrix(); data.commonTextureCoordinates(); + data.commonTextureLayer(); CORRADE_COMPARE(out.str(), "Trade::PhongMaterialData::commonTextureMatrix(): the material doesn't have a common texture coordinate transformation\n" - "Trade::PhongMaterialData::commonTextureCoordinates(): the material doesn't have a common texture coordinate set\n"); + "Trade::PhongMaterialData::commonTextureCoordinates(): the material doesn't have a common texture coordinate set\n" + "Trade::PhongMaterialData::commonTextureLayer(): the material doesn't have a common array texture layer\n"); } #ifdef MAGNUM_BUILD_DEPRECATED