Browse Source

Trade: support for texture array layers in all MaterialData attributes.

Logic mostly the same as with MaterialAttribute::*TextureCoordinates --
attribute not present is treated the same way as if the layer was 0
(since that's what a 2D non-array texture is, a single-slice array), and
conversely if the attribute is 0 it's the same as if it would be not
present at all. Plus it also gets checked in queries for packed
textures, if everything is the same but the layer is different, then
it's not a packed texture.

The rest of the commit is just busywork for convenience APIs.
pull/570/head
Vladimír Vondruš 4 years ago
parent
commit
e7f9e74346
  1. 22
      src/Magnum/Trade/FlatMaterialData.cpp
  2. 30
      src/Magnum/Trade/FlatMaterialData.h
  3. 12
      src/Magnum/Trade/Implementation/materialAttributeProperties.hpp
  4. 33
      src/Magnum/Trade/MaterialData.cpp
  5. 176
      src/Magnum/Trade/MaterialData.h
  6. 11
      src/Magnum/Trade/MaterialLayerData.h
  7. 66
      src/Magnum/Trade/PbrClearCoatMaterialData.cpp
  8. 79
      src/Magnum/Trade/PbrClearCoatMaterialData.h
  9. 121
      src/Magnum/Trade/PbrMetallicRoughnessMaterialData.cpp
  10. 195
      src/Magnum/Trade/PbrMetallicRoughnessMaterialData.h
  11. 106
      src/Magnum/Trade/PbrSpecularGlossinessMaterialData.cpp
  12. 124
      src/Magnum/Trade/PbrSpecularGlossinessMaterialData.h
  13. 77
      src/Magnum/Trade/PhongMaterialData.cpp
  14. 89
      src/Magnum/Trade/PhongMaterialData.h
  15. 68
      src/Magnum/Trade/Test/FlatMaterialDataTest.cpp
  16. 57
      src/Magnum/Trade/Test/MaterialDataTest.cpp
  17. 132
      src/Magnum/Trade/Test/PbrClearCoatMaterialDataTest.cpp
  18. 188
      src/Magnum/Trade/Test/PbrMetallicRoughnessMaterialDataTest.cpp
  19. 148
      src/Magnum/Trade/Test/PbrSpecularGlossinessMaterialDataTest.cpp
  20. 106
      src/Magnum/Trade/Test/PhongMaterialDataTest.cpp

22
src/Magnum/Trade/FlatMaterialData.cpp

@ -49,6 +49,12 @@ bool FlatMaterialData::hasTextureCoordinates() const {
attributeOr(MaterialAttribute::TextureCoordinates, 0u); 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 { Color4 FlatMaterialData::color() const {
/* If the material has a texture, return the color that matches it */ /* If the material has a texture, return the color that matches it */
if(hasAttribute(MaterialAttribute::BaseColorTexture)) 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", {}); CORRADE_ASSERT_UNREACHABLE("Trade::FlatMaterialData::textureCoordinates(): the material doesn't have a texture", {});
} }
UnsignedInt FlatMaterialData::textureLayer() const {
if(hasAttribute(MaterialAttribute::BaseColorTexture)) {
if(Containers::Optional<UnsignedInt> value = tryAttribute<UnsignedInt>(MaterialAttribute::BaseColorTextureLayer))
return *value;
return attributeOr(MaterialAttribute::TextureLayer, 0u);
}
if(hasAttribute(MaterialAttribute::DiffuseTexture)) {
if(Containers::Optional<UnsignedInt> value = tryAttribute<UnsignedInt>(MaterialAttribute::DiffuseTextureLayer))
return *value;
return attributeOr(MaterialAttribute::TextureLayer, 0u);
}
CORRADE_ASSERT_UNREACHABLE("Trade::FlatMaterialData::textureLayer(): the material doesn't have a texture", {});
}
}} }}

30
src/Magnum/Trade/FlatMaterialData.h

@ -102,6 +102,21 @@ class MAGNUM_TRADE_EXPORT FlatMaterialData: public MaterialData {
*/ */
bool hasTextureCoordinates() const; 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 * @brief Color
* *
@ -156,6 +171,21 @@ class MAGNUM_TRADE_EXPORT FlatMaterialData: public MaterialData {
* @see @ref hasTexture() * @see @ref hasTexture()
*/ */
UnsignedInt textureCoordinates() const; 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;
}; };
}} }}

12
src/Magnum/Trade/Implementation/materialAttributeProperties.hpp

@ -33,56 +33,68 @@ _c(AmbientColor,Vector4)
_c(AmbientTexture,UnsignedInt) _c(AmbientTexture,UnsignedInt)
_c(AmbientTextureMatrix,Matrix3x3) _c(AmbientTextureMatrix,Matrix3x3)
_c(AmbientTextureCoordinates,UnsignedInt) _c(AmbientTextureCoordinates,UnsignedInt)
_c(AmbientTextureLayer,UnsignedInt)
_c(DiffuseColor,Vector4) _c(DiffuseColor,Vector4)
_c(DiffuseTexture,UnsignedInt) _c(DiffuseTexture,UnsignedInt)
_c(DiffuseTextureMatrix,Matrix3x3) _c(DiffuseTextureMatrix,Matrix3x3)
_c(DiffuseTextureCoordinates,UnsignedInt) _c(DiffuseTextureCoordinates,UnsignedInt)
_c(DiffuseTextureLayer,UnsignedInt)
_c(SpecularColor,Vector4) _c(SpecularColor,Vector4)
_c(SpecularTexture,UnsignedInt) _c(SpecularTexture,UnsignedInt)
_ct(SpecularTextureSwizzle,TextureSwizzle,MaterialTextureSwizzle) _ct(SpecularTextureSwizzle,TextureSwizzle,MaterialTextureSwizzle)
_c(SpecularTextureMatrix,Matrix3x3) _c(SpecularTextureMatrix,Matrix3x3)
_c(SpecularTextureCoordinates,UnsignedInt) _c(SpecularTextureCoordinates,UnsignedInt)
_c(SpecularTextureLayer,UnsignedInt)
_c(Shininess,Float) _c(Shininess,Float)
_c(BaseColor,Vector4) _c(BaseColor,Vector4)
_c(BaseColorTexture,UnsignedInt) _c(BaseColorTexture,UnsignedInt)
_c(BaseColorTextureMatrix,Matrix3x3) _c(BaseColorTextureMatrix,Matrix3x3)
_c(BaseColorTextureCoordinates,UnsignedInt) _c(BaseColorTextureCoordinates,UnsignedInt)
_c(BaseColorTextureLayer,UnsignedInt)
_c(Metalness,Float) _c(Metalness,Float)
_c(MetalnessTexture,UnsignedInt) _c(MetalnessTexture,UnsignedInt)
_ct(MetalnessTextureSwizzle,TextureSwizzle,MaterialTextureSwizzle) _ct(MetalnessTextureSwizzle,TextureSwizzle,MaterialTextureSwizzle)
_c(MetalnessTextureMatrix,Matrix3x3) _c(MetalnessTextureMatrix,Matrix3x3)
_c(MetalnessTextureCoordinates,UnsignedInt) _c(MetalnessTextureCoordinates,UnsignedInt)
_c(MetalnessTextureLayer,UnsignedInt)
_c(Roughness,Float) _c(Roughness,Float)
_c(RoughnessTexture,UnsignedInt) _c(RoughnessTexture,UnsignedInt)
_ct(RoughnessTextureSwizzle,TextureSwizzle,MaterialTextureSwizzle) _ct(RoughnessTextureSwizzle,TextureSwizzle,MaterialTextureSwizzle)
_c(RoughnessTextureMatrix,Matrix3x3) _c(RoughnessTextureMatrix,Matrix3x3)
_c(RoughnessTextureCoordinates,UnsignedInt) _c(RoughnessTextureCoordinates,UnsignedInt)
_c(RoughnessTextureLayer,UnsignedInt)
_c(NoneRoughnessMetallicTexture,UnsignedInt) _c(NoneRoughnessMetallicTexture,UnsignedInt)
_c(Glossiness,Float) _c(Glossiness,Float)
_c(GlossinessTexture,UnsignedInt) _c(GlossinessTexture,UnsignedInt)
_ct(GlossinessTextureSwizzle,TextureSwizzle,MaterialTextureSwizzle) _ct(GlossinessTextureSwizzle,TextureSwizzle,MaterialTextureSwizzle)
_c(GlossinessTextureMatrix,Matrix3x3) _c(GlossinessTextureMatrix,Matrix3x3)
_c(GlossinessTextureCoordinates,UnsignedInt) _c(GlossinessTextureCoordinates,UnsignedInt)
_c(GlossinessTextureLayer,UnsignedInt)
_c(SpecularGlossinessTexture,UnsignedInt) _c(SpecularGlossinessTexture,UnsignedInt)
_c(NormalTexture,UnsignedInt) _c(NormalTexture,UnsignedInt)
_c(NormalTextureScale,Float) _c(NormalTextureScale,Float)
_ct(NormalTextureSwizzle,TextureSwizzle,MaterialTextureSwizzle) _ct(NormalTextureSwizzle,TextureSwizzle,MaterialTextureSwizzle)
_c(NormalTextureMatrix,Matrix3x3) _c(NormalTextureMatrix,Matrix3x3)
_c(NormalTextureCoordinates,UnsignedInt) _c(NormalTextureCoordinates,UnsignedInt)
_c(NormalTextureLayer,UnsignedInt)
_c(OcclusionTexture,UnsignedInt) _c(OcclusionTexture,UnsignedInt)
_c(OcclusionTextureStrength,Float) _c(OcclusionTextureStrength,Float)
_ct(OcclusionTextureSwizzle,TextureSwizzle,MaterialTextureSwizzle) _ct(OcclusionTextureSwizzle,TextureSwizzle,MaterialTextureSwizzle)
_c(OcclusionTextureMatrix,Matrix3x3) _c(OcclusionTextureMatrix,Matrix3x3)
_c(OcclusionTextureCoordinates,UnsignedInt) _c(OcclusionTextureCoordinates,UnsignedInt)
_c(OcclusionTextureLayer,UnsignedInt)
_c(EmissiveColor,Vector3) _c(EmissiveColor,Vector3)
_c(EmissiveTexture,UnsignedInt) _c(EmissiveTexture,UnsignedInt)
_c(EmissiveTextureMatrix,Matrix3x3) _c(EmissiveTextureMatrix,Matrix3x3)
_c(EmissiveTextureCoordinates,UnsignedInt) _c(EmissiveTextureCoordinates,UnsignedInt)
_c(EmissiveTextureLayer,UnsignedInt)
_c(LayerFactor,Float) _c(LayerFactor,Float)
_c(LayerFactorTexture,UnsignedInt) _c(LayerFactorTexture,UnsignedInt)
_ct(LayerFactorTextureSwizzle,TextureSwizzle,MaterialTextureSwizzle) _ct(LayerFactorTextureSwizzle,TextureSwizzle,MaterialTextureSwizzle)
_c(LayerFactorTextureMatrix,Matrix3x3) _c(LayerFactorTextureMatrix,Matrix3x3)
_c(LayerFactorTextureCoordinates,UnsignedInt) _c(LayerFactorTextureCoordinates,UnsignedInt)
_c(LayerFactorTextureLayer,UnsignedInt)
_c(TextureMatrix,Matrix3x3) _c(TextureMatrix,Matrix3x3)
_c(TextureCoordinates,UnsignedInt) _c(TextureCoordinates,UnsignedInt)
_c(TextureLayer,UnsignedInt)
#endif #endif

33
src/Magnum/Trade/MaterialData.cpp

@ -491,6 +491,39 @@ UnsignedInt MaterialData::layerFactorTextureCoordinates(const MaterialLayer laye
return layerFactorTextureCoordinates(string); 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<UnsignedInt> value = tryAttribute<UnsignedInt>(layer, MaterialAttribute::LayerFactorTextureLayer))
return *value;
if(Containers::Optional<UnsignedInt> value = tryAttribute<UnsignedInt>(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<UnsignedInt> value = tryAttribute<UnsignedInt>(layerId, MaterialAttribute::LayerFactorTextureLayer))
return *value;
if(Containers::Optional<UnsignedInt> value = tryAttribute<UnsignedInt>(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 { UnsignedInt MaterialData::attributeCount(const UnsignedInt layer) const {
CORRADE_ASSERT(layer < layerCount(), CORRADE_ASSERT(layer < layerCount(),
"Trade::MaterialData::attributeCount(): index" << layer << "out of range for" << layerCount() << "layers", {}); "Trade::MaterialData::attributeCount(): index" << layer << "out of range for" << layerCount() << "layers", {});

176
src/Magnum/Trade/MaterialData.h

@ -186,6 +186,16 @@ enum class MaterialAttribute: UnsignedInt {
*/ */
AmbientTextureCoordinates, 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, * Diffuse color for Phong or PBR specular/glossiness materials,
* @ref MaterialAttributeType::Vector4. * @ref MaterialAttributeType::Vector4.
@ -234,6 +244,16 @@ enum class MaterialAttribute: UnsignedInt {
*/ */
DiffuseTextureCoordinates, 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, * Specular color for Phong or PBR specular/glossiness materials,
* @ref MaterialAttributeType::Vector4. Alpha is commonly zero to not * @ref MaterialAttributeType::Vector4. Alpha is commonly zero to not
@ -301,6 +321,17 @@ enum class MaterialAttribute: UnsignedInt {
*/ */
SpecularTextureCoordinates, 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. * Shininess value for Phong materials, @ref MaterialAttributeType::Float.
* *
@ -352,6 +383,17 @@ enum class MaterialAttribute: UnsignedInt {
*/ */
BaseColorTextureCoordinates, 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, * Metalness for PBR metallic/roughness materials,
* @ref MaterialAttributeType::Float. * @ref MaterialAttributeType::Float.
@ -416,6 +458,16 @@ enum class MaterialAttribute: UnsignedInt {
*/ */
MetalnessTextureCoordinates, 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, * Roughness for PBR metallic/roughness materials,
* @ref MaterialAttributeType::Float. * @ref MaterialAttributeType::Float.
@ -480,6 +532,16 @@ enum class MaterialAttribute: UnsignedInt {
*/ */
RoughnessTextureCoordinates, 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 * Combined roughness/metallic texture index for PBR metallic/roughness
* materials with metalness in the blue channel and roughness in the green * materials with metalness in the blue channel and roughness in the green
@ -513,9 +575,10 @@ enum class MaterialAttribute: UnsignedInt {
NoneRoughnessMetallicTexture, NoneRoughnessMetallicTexture,
/* DiffuseColor, DiffuseTexture, DiffuseTextureMatrix, /* DiffuseColor, DiffuseTexture, DiffuseTextureMatrix,
DiffuseTextureCoordinates, SpecularColor, SpecularTexture, DiffuseTextureCoordinates, DiffuseTextureLayer, SpecularColor,
SpecularTextureSwizzle, SpecularTextureMatrix, SpecularTexture, SpecularTextureSwizzle, SpecularTextureMatrix,
SpecularTextureCoordinates specified above for Phong already */ SpecularTextureCoordinates, SpecularTextureLayer specified above for
Phong already */
/** /**
* Glossiness for PBR specular/glossiness materials, * Glossiness for PBR specular/glossiness materials,
@ -577,6 +640,16 @@ enum class MaterialAttribute: UnsignedInt {
*/ */
GlossinessTextureCoordinates, 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 * Combined specular/glossiness texture index for PBR specular/glossiness
* materials with specular color in the RGB channels and glossiness in * materials with specular color in the RGB channels and glossiness in
@ -687,6 +760,17 @@ enum class MaterialAttribute: UnsignedInt {
*/ */
NormalTextureCoordinates, 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, * Occlusion texture index,
* @ref MaterialAttributeType::UnsignedInt. * @ref MaterialAttributeType::UnsignedInt.
@ -754,6 +838,16 @@ enum class MaterialAttribute: UnsignedInt {
*/ */
OcclusionTextureCoordinates, 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, * Emissive color,
* @ref MaterialAttributeType::Vector3. * @ref MaterialAttributeType::Vector3.
@ -801,6 +895,16 @@ enum class MaterialAttribute: UnsignedInt {
*/ */
EmissiveTextureCoordinates, 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. * Layer intensity. @ref MaterialAttributeType::Float.
* *
@ -855,6 +959,17 @@ enum class MaterialAttribute: UnsignedInt {
*/ */
LayerFactorTextureCoordinates, 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, * Common texture transformation matrix for all textures,
* @ref MaterialAttributeType::Matrix3x3. * @ref MaterialAttributeType::Matrix3x3.
@ -908,6 +1023,33 @@ enum class MaterialAttribute: UnsignedInt {
* @ref FlatMaterialData::textureCoordinates() * @ref FlatMaterialData::textureCoordinates()
*/ */
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(Containers::StringView layer) const;
UnsignedInt layerFactorTextureCoordinates(MaterialLayer layer) const; /**< @overload */ 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 * @brief Attribute count in given layer
* *

11
src/Magnum/Trade/MaterialLayerData.h

@ -110,6 +110,16 @@ template<MaterialLayer layer> class MaterialLayerData: public MaterialData {
return MaterialData::layerFactorTextureCoordinates(layer); 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 * @brief Attribute count in this layer
* *
@ -271,6 +281,7 @@ template<MaterialLayer layer> class MaterialLayerData: public MaterialData {
using MaterialData::layerFactorTextureSwizzle; using MaterialData::layerFactorTextureSwizzle;
using MaterialData::layerFactorTextureMatrix; using MaterialData::layerFactorTextureMatrix;
using MaterialData::layerFactorTextureCoordinates; using MaterialData::layerFactorTextureCoordinates;
using MaterialData::layerFactorTextureLayer;
/* MSVC is so damn unbelievably stupid it's setting my ass on fire. /* MSVC is so damn unbelievably stupid it's setting my ass on fire.
https://en.cppreference.com/w/cpp/language/using_declaration says https://en.cppreference.com/w/cpp/language/using_declaration says
that "If the derived class already has a member with the same name, that "If the derived class already has a member with the same name,

66
src/Magnum/Trade/PbrClearCoatMaterialData.cpp

@ -34,7 +34,8 @@ bool PbrClearCoatMaterialData::hasLayerFactorRoughnessTexture() const {
layerFactorTextureSwizzle() == MaterialTextureSwizzle::R && layerFactorTextureSwizzle() == MaterialTextureSwizzle::R &&
roughnessTextureSwizzle() == MaterialTextureSwizzle::G && roughnessTextureSwizzle() == MaterialTextureSwizzle::G &&
layerFactorTextureMatrix() == roughnessTextureMatrix() && layerFactorTextureMatrix() == roughnessTextureMatrix() &&
layerFactorTextureCoordinates() == roughnessTextureCoordinates(); layerFactorTextureCoordinates() == roughnessTextureCoordinates() &&
layerFactorTextureLayer() == roughnessTextureLayer();
} }
bool PbrClearCoatMaterialData::hasTextureTransformation() const { bool PbrClearCoatMaterialData::hasTextureTransformation() const {
@ -95,6 +96,35 @@ bool PbrClearCoatMaterialData::hasCommonTextureCoordinates() const {
return true; 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<UnsignedInt>& layer, UnsignedInt current) {
if(!layer) {
layer = current;
return true;
}
return layer == current;
};
Containers::Optional<UnsignedInt> 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 { Float PbrClearCoatMaterialData::roughness() const {
return attributeOr(MaterialAttribute::Roughness, 0.0f); return attributeOr(MaterialAttribute::Roughness, 0.0f);
} }
@ -129,6 +159,16 @@ UnsignedInt PbrClearCoatMaterialData::roughnessTextureCoordinates() const {
return attributeOr(0, MaterialAttribute::TextureCoordinates, 0u); 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<UnsignedInt> value = tryAttribute<UnsignedInt>(MaterialAttribute::RoughnessTextureLayer))
return *value;
if(Containers::Optional<UnsignedInt> value = tryAttribute<UnsignedInt>(MaterialAttribute::TextureLayer))
return *value;
return attributeOr(0, MaterialAttribute::TextureLayer, 0u);
}
UnsignedInt PbrClearCoatMaterialData::normalTexture() const { UnsignedInt PbrClearCoatMaterialData::normalTexture() const {
return attribute<UnsignedInt>(MaterialAttribute::NormalTexture); return attribute<UnsignedInt>(MaterialAttribute::NormalTexture);
} }
@ -165,6 +205,16 @@ UnsignedInt PbrClearCoatMaterialData::normalTextureCoordinates() const {
return attributeOr(0, MaterialAttribute::TextureCoordinates, 0u); 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<UnsignedInt> value = tryAttribute<UnsignedInt>(MaterialAttribute::NormalTextureLayer))
return *value;
if(Containers::Optional<UnsignedInt> value = tryAttribute<UnsignedInt>(MaterialAttribute::TextureLayer))
return *value;
return attributeOr(0, MaterialAttribute::TextureLayer, 0u);
}
Matrix3 PbrClearCoatMaterialData::commonTextureMatrix() const { Matrix3 PbrClearCoatMaterialData::commonTextureMatrix() const {
CORRADE_ASSERT(hasCommonTextureTransformation(), CORRADE_ASSERT(hasCommonTextureTransformation(),
"Trade::PbrClearCoatMaterialData::commonTextureMatrix(): the layer doesn't have a common texture coordinate transformation", {}); "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); 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<UnsignedInt> value = tryAttribute<UnsignedInt>(MaterialAttribute::TextureLayer))
return *value;
return attributeOr(0, MaterialAttribute::TextureLayer, 0u);
}
}} }}

79
src/Magnum/Trade/PbrClearCoatMaterialData.h

@ -69,17 +69,21 @@ class MAGNUM_TRADE_EXPORT PbrClearCoatMaterialData: public MaterialLayerData<Mat
* @ref MaterialTextureSwizzle::G, and additionally * @ref MaterialTextureSwizzle::G, and additionally
* @ref MaterialAttribute::LayerFactorTextureMatrix and * @ref MaterialAttribute::LayerFactorTextureMatrix and
* @ref MaterialAttribute::RoughnessTextureMatrix are both either not * @ref MaterialAttribute::RoughnessTextureMatrix are both either not
* present or have the same value, and * present or have the same value,
* @ref MaterialAttribute::LayerFactorTextureCoordinates and * @ref MaterialAttribute::LayerFactorTextureCoordinates and
* @ref MaterialAttribute::RoughnessTextureCoordinates are both either * @ref MaterialAttribute::RoughnessTextureCoordinates are both either
* not present or have the same value; @cpp false @ce otherwise. * not present or have the same value, and
* @ref MaterialAttribute::LayerFactorTextureLayer and
* @ref MaterialAttribute::RoughnessTextureLayer are both either not
* present or have the same value; @cpp false @ce otherwise.
* *
* In other words, if this function returns @cpp true @ce, * In other words, if this function returns @cpp true @ce,
* @ref layerFactorTexture(), @ref layerFactorTextureMatrix() and * @ref layerFactorTexture(), @ref layerFactorTextureMatrix(),
* @ref layerFactorTextureCoordinates() return values common for both * @ref layerFactorTextureCoordinates() and
* layer factor and roughness texture, and the two are packed together * @ref layerFactorTextureLayer() return values common for both layer
* with layer factor occupying the R channel and roughness the G * factor and roughness texture, and the two are packed together with
* channel. This check is present in order to provide support for the * layer factor occupying the R channel and roughness the G channel.
* This check is present in order to provide support for the
* [KHR_materials_clearcoat](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_clearcoat/README.md) * [KHR_materials_clearcoat](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_clearcoat/README.md)
* glTF extension. * glTF extension.
* @see @ref hasAttribute() * @see @ref hasAttribute()
@ -142,6 +146,33 @@ class MAGNUM_TRADE_EXPORT PbrClearCoatMaterialData: public MaterialLayerData<Mat
*/ */
bool hasCommonTextureCoordinates() const; bool hasCommonTextureCoordinates() const;
/**
* @brief Whether the material uses array texture layers
*
* Returns @cpp true @ce if any of the
* @ref MaterialAttribute::LayerFactorTextureLayer,
* @ref MaterialAttribute::RoughnessTextureLayer,
* @ref MaterialAttribute::NormalTextureLayer or
* @ref MaterialAttribute::TextureLayer attributes are present in this
* material or if @ref MaterialAttribute::TextureLayer is present in
* the base material, @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 layerFactorTextureLayer(), @ref roughnessTextureLayer() and
* @ref normalTextureLayer() 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 Roughness factor * @brief Roughness factor
* *
@ -199,6 +230,18 @@ class MAGNUM_TRADE_EXPORT PbrClearCoatMaterialData: public MaterialLayerData<Mat
*/ */
UnsignedInt roughnessTextureCoordinates() const; UnsignedInt roughnessTextureCoordinates() const;
/**
* @brief Roughness array texture layer
*
* Convenience access to the @ref MaterialAttribute::RoughnessTextureLayer
* / @ref MaterialAttribute::TextureLayer attributes in this layer or a
* @ref MaterialAttribute::TextureLayer attribute in the base material.
* If neither is present, the default is @cpp 0 @ce. Available only if
* @ref MaterialAttribute::RoughnessTexture is present in this layer.
* @see @ref hasAttribute()
*/
UnsignedInt roughnessTextureLayer() const;
/** /**
* @brief Normal texture ID * @brief Normal texture ID
* *
@ -260,6 +303,18 @@ class MAGNUM_TRADE_EXPORT PbrClearCoatMaterialData: public MaterialLayerData<Mat
*/ */
UnsignedInt normalTextureCoordinates() const; UnsignedInt normalTextureCoordinates() const;
/**
* @brief Normal array texture layer
*
* Convenience access to the @ref MaterialAttribute::NormalTextureLayer
* / @ref MaterialAttribute::TextureLayer attributes in this layer or a
* @ref MaterialAttribute::TextureLayer attribute in the base material.
* If neither is present, the default is @cpp 0 @ce. Available only if
* @ref MaterialAttribute::NormalTexture is present in this layer.
* @see @ref hasAttribute()
*/
UnsignedInt normalTextureLayer() const;
/** /**
* @brief Common texture coordinate transformation matrix for all textures * @brief Common texture coordinate transformation matrix for all textures
* *
@ -282,6 +337,16 @@ class MAGNUM_TRADE_EXPORT PbrClearCoatMaterialData: public MaterialLayerData<Mat
* texture is present, returns @cpp 0 @ce. * texture is present, returns @cpp 0 @ce.
*/ */
UnsignedInt commonTextureCoordinates() const; 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 layerFactorTextureLayer(),
* @ref roughnessTextureLayer() and @ref normalTextureLayer() where a
* texture is present. If no texture is present, returns @cpp 0 @ce.
*/
UnsignedInt commonTextureLayer() const;
}; };
}} }}

121
src/Magnum/Trade/PbrMetallicRoughnessMaterialData.cpp

@ -50,7 +50,8 @@ bool PbrMetallicRoughnessMaterialData::hasNoneRoughnessMetallicTexture() const {
roughnessTextureSwizzle() == MaterialTextureSwizzle::G && roughnessTextureSwizzle() == MaterialTextureSwizzle::G &&
metalnessTextureSwizzle() == MaterialTextureSwizzle::B)) && metalnessTextureSwizzle() == MaterialTextureSwizzle::B)) &&
roughnessTextureMatrix() == metalnessTextureMatrix() && roughnessTextureMatrix() == metalnessTextureMatrix() &&
roughnessTextureCoordinates() == metalnessTextureCoordinates(); roughnessTextureCoordinates() == metalnessTextureCoordinates() &&
roughnessTextureLayer() == metalnessTextureLayer();
} }
bool PbrMetallicRoughnessMaterialData::hasRoughnessMetallicOcclusionTexture() const { bool PbrMetallicRoughnessMaterialData::hasRoughnessMetallicOcclusionTexture() const {
@ -69,10 +70,13 @@ bool PbrMetallicRoughnessMaterialData::hasRoughnessMetallicOcclusionTexture() co
const Matrix3 roughnessTextureMatrix = this->roughnessTextureMatrix(); const Matrix3 roughnessTextureMatrix = this->roughnessTextureMatrix();
const UnsignedInt roughnessTextureCoordinates = this->roughnessTextureCoordinates(); const UnsignedInt roughnessTextureCoordinates = this->roughnessTextureCoordinates();
const UnsignedInt roughnessTextureLayer = this->roughnessTextureLayer();
return metalnessTextureMatrix() == roughnessTextureMatrix && return metalnessTextureMatrix() == roughnessTextureMatrix &&
occlusionTextureMatrix() == roughnessTextureMatrix && occlusionTextureMatrix() == roughnessTextureMatrix &&
metalnessTextureCoordinates() == roughnessTextureCoordinates && metalnessTextureCoordinates() == roughnessTextureCoordinates &&
occlusionTextureCoordinates() == roughnessTextureCoordinates; occlusionTextureCoordinates() == roughnessTextureCoordinates &&
metalnessTextureLayer() == roughnessTextureLayer &&
occlusionTextureLayer() == roughnessTextureLayer;
} }
bool PbrMetallicRoughnessMaterialData::hasOcclusionRoughnessMetallicTexture() const { bool PbrMetallicRoughnessMaterialData::hasOcclusionRoughnessMetallicTexture() const {
@ -91,10 +95,13 @@ bool PbrMetallicRoughnessMaterialData::hasOcclusionRoughnessMetallicTexture() co
const Matrix3 occlusionTextureMatrix = this->occlusionTextureMatrix(); const Matrix3 occlusionTextureMatrix = this->occlusionTextureMatrix();
const UnsignedInt occlusionTextureCoordinates = this->occlusionTextureCoordinates(); const UnsignedInt occlusionTextureCoordinates = this->occlusionTextureCoordinates();
const UnsignedInt occlusionTextureLayer = this->occlusionTextureLayer();
return roughnessTextureMatrix() == occlusionTextureMatrix && return roughnessTextureMatrix() == occlusionTextureMatrix &&
metalnessTextureMatrix() == occlusionTextureMatrix && metalnessTextureMatrix() == occlusionTextureMatrix &&
roughnessTextureCoordinates() == occlusionTextureCoordinates && roughnessTextureCoordinates() == occlusionTextureCoordinates &&
metalnessTextureCoordinates() == occlusionTextureCoordinates; metalnessTextureCoordinates() == occlusionTextureCoordinates &&
roughnessTextureLayer() == occlusionTextureLayer &&
metalnessTextureLayer() == occlusionTextureLayer;
} }
bool PbrMetallicRoughnessMaterialData::hasNormalRoughnessMetallicTexture() const { bool PbrMetallicRoughnessMaterialData::hasNormalRoughnessMetallicTexture() const {
@ -113,10 +120,13 @@ bool PbrMetallicRoughnessMaterialData::hasNormalRoughnessMetallicTexture() const
const Matrix3 normalTextureMatrix = this->normalTextureMatrix(); const Matrix3 normalTextureMatrix = this->normalTextureMatrix();
const UnsignedInt normalTextureCoordinates = this->normalTextureCoordinates(); const UnsignedInt normalTextureCoordinates = this->normalTextureCoordinates();
const UnsignedInt normalTextureLayer = this->normalTextureLayer();
return roughnessTextureMatrix() == normalTextureMatrix && return roughnessTextureMatrix() == normalTextureMatrix &&
metalnessTextureMatrix() == normalTextureMatrix && metalnessTextureMatrix() == normalTextureMatrix &&
roughnessTextureCoordinates() == normalTextureCoordinates && roughnessTextureCoordinates() == normalTextureCoordinates &&
metalnessTextureCoordinates() == normalTextureCoordinates; metalnessTextureCoordinates() == normalTextureCoordinates &&
roughnessTextureLayer() == normalTextureLayer &&
metalnessTextureLayer() == normalTextureLayer;
} }
bool PbrMetallicRoughnessMaterialData::hasTextureTransformation() const { bool PbrMetallicRoughnessMaterialData::hasTextureTransformation() const {
@ -193,6 +203,43 @@ bool PbrMetallicRoughnessMaterialData::hasCommonTextureCoordinates() const {
return true; 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<UnsignedInt>& layer, UnsignedInt current) {
if(!layer) {
layer = current;
return true;
}
return layer == current;
};
Containers::Optional<UnsignedInt> 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 { Color4 PbrMetallicRoughnessMaterialData::baseColor() const {
return attributeOr(MaterialAttribute::BaseColor, 0xffffffff_rgbaf); return attributeOr(MaterialAttribute::BaseColor, 0xffffffff_rgbaf);
} }
@ -217,6 +264,14 @@ UnsignedInt PbrMetallicRoughnessMaterialData::baseColorTextureCoordinates() cons
return attributeOr(MaterialAttribute::TextureCoordinates, 0u); 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<UnsignedInt> value = tryAttribute<UnsignedInt>(MaterialAttribute::BaseColorTextureLayer))
return *value;
return attributeOr(MaterialAttribute::TextureLayer, 0u);
}
Float PbrMetallicRoughnessMaterialData::metalness() const { Float PbrMetallicRoughnessMaterialData::metalness() const {
return attributeOr(MaterialAttribute::Metalness, 1.0f); return attributeOr(MaterialAttribute::Metalness, 1.0f);
} }
@ -256,6 +311,14 @@ UnsignedInt PbrMetallicRoughnessMaterialData::metalnessTextureCoordinates() cons
return attributeOr(MaterialAttribute::TextureCoordinates, 0u); 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<UnsignedInt> value = tryAttribute<UnsignedInt>(MaterialAttribute::MetalnessTextureLayer))
return *value;
return attributeOr(MaterialAttribute::TextureLayer, 0u);
}
Float PbrMetallicRoughnessMaterialData::roughness() const { Float PbrMetallicRoughnessMaterialData::roughness() const {
return attributeOr(MaterialAttribute::Roughness, 1.0f); return attributeOr(MaterialAttribute::Roughness, 1.0f);
} }
@ -295,6 +358,14 @@ UnsignedInt PbrMetallicRoughnessMaterialData::roughnessTextureCoordinates() cons
return attributeOr(MaterialAttribute::TextureCoordinates, 0u); 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<UnsignedInt> value = tryAttribute<UnsignedInt>(MaterialAttribute::RoughnessTextureLayer))
return *value;
return attributeOr(MaterialAttribute::TextureLayer, 0u);
}
UnsignedInt PbrMetallicRoughnessMaterialData::normalTexture() const { UnsignedInt PbrMetallicRoughnessMaterialData::normalTexture() const {
return attribute<UnsignedInt>(MaterialAttribute::NormalTexture); return attribute<UnsignedInt>(MaterialAttribute::NormalTexture);
} }
@ -327,6 +398,14 @@ UnsignedInt PbrMetallicRoughnessMaterialData::normalTextureCoordinates() const {
return attributeOr(MaterialAttribute::TextureCoordinates, 0u); 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<UnsignedInt> value = tryAttribute<UnsignedInt>(MaterialAttribute::NormalTextureLayer))
return *value;
return attributeOr(MaterialAttribute::TextureLayer, 0u);
}
UnsignedInt PbrMetallicRoughnessMaterialData::occlusionTexture() const { UnsignedInt PbrMetallicRoughnessMaterialData::occlusionTexture() const {
return attribute<UnsignedInt>(MaterialAttribute::OcclusionTexture); return attribute<UnsignedInt>(MaterialAttribute::OcclusionTexture);
} }
@ -359,6 +438,14 @@ UnsignedInt PbrMetallicRoughnessMaterialData::occlusionTextureCoordinates() cons
return attributeOr(MaterialAttribute::TextureCoordinates, 0u); 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<UnsignedInt> value = tryAttribute<UnsignedInt>(MaterialAttribute::OcclusionTextureLayer))
return *value;
return attributeOr(MaterialAttribute::TextureLayer, 0u);
}
Color3 PbrMetallicRoughnessMaterialData::emissiveColor() const { Color3 PbrMetallicRoughnessMaterialData::emissiveColor() const {
return attributeOr(MaterialAttribute::EmissiveColor, 0x000000_srgbf); return attributeOr(MaterialAttribute::EmissiveColor, 0x000000_srgbf);
} }
@ -383,6 +470,14 @@ UnsignedInt PbrMetallicRoughnessMaterialData::emissiveTextureCoordinates() const
return attributeOr(MaterialAttribute::TextureCoordinates, 0u); 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<UnsignedInt> value = tryAttribute<UnsignedInt>(MaterialAttribute::EmissiveTextureLayer))
return *value;
return attributeOr(MaterialAttribute::TextureLayer, 0u);
}
Matrix3 PbrMetallicRoughnessMaterialData::commonTextureMatrix() const { Matrix3 PbrMetallicRoughnessMaterialData::commonTextureMatrix() const {
CORRADE_ASSERT(hasCommonTextureTransformation(), CORRADE_ASSERT(hasCommonTextureTransformation(),
"Trade::PbrMetallicRoughnessMaterialData::commonTextureMatrix(): the material doesn't have a common texture coordinate transformation", {}); "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); 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);
}
}} }}

195
src/Magnum/Trade/PbrMetallicRoughnessMaterialData.h

@ -92,19 +92,23 @@ class MAGNUM_TRADE_EXPORT PbrMetallicRoughnessMaterialData: public MaterialData
* @ref MaterialTextureSwizzle::B, and ddditionally * @ref MaterialTextureSwizzle::B, and ddditionally
* @ref MaterialAttribute::RoughnessTextureMatrix and * @ref MaterialAttribute::RoughnessTextureMatrix and
* @ref MaterialAttribute::MetalnessTextureMatrix are both either not * @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::RoughnessTextureCoordinates and
* @ref MaterialAttribute::MetalnessTextureCoordinates are both either * @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, * In other words, if this function returns @cpp true @ce,
* @ref roughnessTexture(), @ref roughnessTextureMatrix() and * @ref roughnessTexture(), @ref roughnessTextureMatrix(),
* @ref roughnessTextureCoordinates() return values common for both * @ref roughnessTextureCoordinates() and @ref roughnessTextureLayer()
* metalness and roughness texture, and the two are packed together * return values common for both metalness and roughness texture, and
* with roughness occupying the G channel and metalness the B channel. * the two are packed together with roughness occupying the G channel
* This packing is common in glTF metallic/roughness materials, which * and metalness the B channel. This packing is common in glTF
* in turn is compatible with how UE4 assets are usually packed. * metallic/roughness materials, which in turn is compatible with how
* Original rationale for this [can be seen here](https://github.com/KhronosGroup/glTF/issues/857). * 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 * The red and alpha channels are ignored and can be repurposed for
* other maps such as occlusion or transmission. This check is a subset * 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::OcclusionTextureMatrix,
* @ref MaterialAttribute::RoughnessTextureMatrix and * @ref MaterialAttribute::RoughnessTextureMatrix and
* @ref MaterialAttribute::MetalnessTextureMatrix are all other not * @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::OcclusionTextureCoordinates,
* @ref MaterialAttribute::RoughnessTextureCoordinates and * @ref MaterialAttribute::RoughnessTextureCoordinates and
* @ref MaterialAttribute::MetalnessTextureCoordinates are all either * @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, * In other words, if this function returns @cpp true @ce,
* @ref occlusionTexture(), @ref occlusionTextureMatrix() and * @ref occlusionTexture(), @ref occlusionTextureMatrix(),
* @ref occlusionTextureCoordinates() return values common for * @ref occlusionTextureCoordinates() and @ref occlusionTextureLayer()
* occlusion, roughness and metalness textures, and the three are * return values common for occlusion, roughness and metalness
* packed together with occlusion occupying the R channel, roughness * textures, and the three are packed together with occlusion occupying
* the G channel and metalness the B channel. This packing is common in * the R channel, roughness the G channel and metalness the B channel.
* glTF metallic/roughness materials, which in turn is compatible with * This packing is common in glTF metallic/roughness materials, which
* how UE4 assets are usually packed. Original rationale for this [can * in turn is compatible with how UE4 assets are usually packed.
* be seen here](https://github.com/KhronosGroup/glTF/issues/857), * 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) * 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. * 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::RoughnessTextureMatrix,
* @ref MaterialAttribute::MetalnessTextureMatrix and * @ref MaterialAttribute::MetalnessTextureMatrix and
* @ref MaterialAttribute::OcclusionTextureMatrix are all other not * @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::RoughnessTextureCoordinates,
* @ref MaterialAttribute::MetalnessTextureCoordinates and * @ref MaterialAttribute::MetalnessTextureCoordinates and
* @ref MaterialAttribute::OcclusionTextureCoordinates are all either * @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, * In other words, if this function returns @cpp true @ce,
* @ref roughnessTexture(), @ref roughnessTextureMatrix() and * @ref roughnessTexture(), @ref roughnessTextureMatrix(),
* @ref roughnessTextureCoordinates() return values common for * @ref roughnessTextureCoordinates() and @ref roughnessTextureLayer()
* roughness, metalness and occlusion textures, and the three are * return values common for roughness, metalness and occlusion
* packed together with roughness occupying the R channel, metalness * textures, and the three are packed together with roughness occupying
* the G channel and occlusion the B channel. This check is present in * the R channel, metalness the G channel and occlusion the B channel.
* 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) * 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. * glTF extension.
* *
* The alpha channel is ignored and can be repurposed for other maps * 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::NormalTextureMatrix,
* @ref MaterialAttribute::RoughnessTextureMatrix and * @ref MaterialAttribute::RoughnessTextureMatrix and
* @ref MaterialAttribute::MetalnessTextureMatrix are all other not * @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::NormalTextureCoordinates,
* @ref MaterialAttribute::RoughnessTextureCoordinates and * @ref MaterialAttribute::RoughnessTextureCoordinates and
* @ref MaterialAttribute::MetalnessTextureCoordinates are all either * @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, * In other words, if this function returns @cpp true @ce,
* @ref normalTexture(), @ref normalTextureMatrix() and * @ref normalTexture(), @ref normalTextureMatrix(),
* @ref normalTextureCoordinates() return values common for normal, * @ref normalTextureCoordinates() and @ref normalTextureLayer() return
* roughness and metalness textures, and the three are packed together * values common for normal, roughness and metalness textures, and the
* with normals occupying the RG channel, roughness the B channel and * three are packed together with normals occupying the RG channel,
* metalness the A channel. This check is present in order to provide * roughness the B channel and metalness the A channel. This check is
* support for the [MSFT_packing_normalRoughnessMetallic](https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Vendor/MSFT_packing_normalRoughnessMetallic/README.md) * 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. * glTF extension.
* *
* @see @ref hasMetalnessTexture(), @ref hasRoughnessTexture(), * @see @ref hasMetalnessTexture(), @ref hasRoughnessTexture(),
@ -297,6 +314,36 @@ class MAGNUM_TRADE_EXPORT PbrMetallicRoughnessMaterialData: public MaterialData
*/ */
bool hasCommonTextureCoordinates() const; 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 * @brief Base color
* *
@ -339,6 +386,17 @@ class MAGNUM_TRADE_EXPORT PbrMetallicRoughnessMaterialData: public MaterialData
*/ */
UnsignedInt baseColorTextureCoordinates() const; 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 * @brief Metalness factor
* *
@ -395,6 +453,17 @@ class MAGNUM_TRADE_EXPORT PbrMetallicRoughnessMaterialData: public MaterialData
*/ */
UnsignedInt metalnessTextureCoordinates() const; 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 * @brief Roughness factor
* *
@ -451,6 +520,17 @@ class MAGNUM_TRADE_EXPORT PbrMetallicRoughnessMaterialData: public MaterialData
*/ */
UnsignedInt roughnessTextureCoordinates() const; 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 * @brief Normal texture ID
* *
@ -503,6 +583,17 @@ class MAGNUM_TRADE_EXPORT PbrMetallicRoughnessMaterialData: public MaterialData
*/ */
UnsignedInt normalTextureCoordinates() const; 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 * @brief Occlusion texture ID
* *
@ -555,6 +646,17 @@ class MAGNUM_TRADE_EXPORT PbrMetallicRoughnessMaterialData: public MaterialData
*/ */
UnsignedInt occlusionTextureCoordinates() const; 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 * @brief Emissive color
* *
@ -600,6 +702,17 @@ class MAGNUM_TRADE_EXPORT PbrMetallicRoughnessMaterialData: public MaterialData
*/ */
UnsignedInt emissiveTextureCoordinates() const; 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 * @brief Common texture coordinate transformation matrix for all textures
* *
@ -625,6 +738,18 @@ class MAGNUM_TRADE_EXPORT PbrMetallicRoughnessMaterialData: public MaterialData
* @cpp 0 @ce. * @cpp 0 @ce.
*/ */
UnsignedInt commonTextureCoordinates() const; 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;
}; };
}} }}

106
src/Magnum/Trade/PbrSpecularGlossinessMaterialData.cpp

@ -50,7 +50,8 @@ bool PbrSpecularGlossinessMaterialData::hasSpecularGlossinessTexture() const {
specularTextureSwizzle() == MaterialTextureSwizzle::RGB && specularTextureSwizzle() == MaterialTextureSwizzle::RGB &&
glossinessTextureSwizzle() == MaterialTextureSwizzle::A)) && glossinessTextureSwizzle() == MaterialTextureSwizzle::A)) &&
specularTextureMatrix() == glossinessTextureMatrix() && specularTextureMatrix() == glossinessTextureMatrix() &&
specularTextureCoordinates() == glossinessTextureCoordinates(); specularTextureCoordinates() == glossinessTextureCoordinates() &&
specularTextureLayer() == glossinessTextureLayer();
} }
bool PbrSpecularGlossinessMaterialData::hasTextureTransformation() const { bool PbrSpecularGlossinessMaterialData::hasTextureTransformation() const {
@ -127,6 +128,43 @@ bool PbrSpecularGlossinessMaterialData::hasCommonTextureCoordinates() const {
return true; 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<UnsignedInt>& layer, UnsignedInt current) {
if(!layer) {
layer = current;
return true;
}
return layer == current;
};
Containers::Optional<UnsignedInt> 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 { Color4 PbrSpecularGlossinessMaterialData::diffuseColor() const {
return attributeOr(MaterialAttribute::DiffuseColor, 0xffffffff_srgbaf); return attributeOr(MaterialAttribute::DiffuseColor, 0xffffffff_srgbaf);
} }
@ -151,6 +189,14 @@ UnsignedInt PbrSpecularGlossinessMaterialData::diffuseTextureCoordinates() const
return attributeOr(MaterialAttribute::TextureCoordinates, 0u); 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<UnsignedInt> value = tryAttribute<UnsignedInt>(MaterialAttribute::DiffuseTextureLayer))
return *value;
return attributeOr(MaterialAttribute::TextureLayer, 0u);
}
Color4 PbrSpecularGlossinessMaterialData::specularColor() const { Color4 PbrSpecularGlossinessMaterialData::specularColor() const {
return attributeOr(MaterialAttribute::SpecularColor, 0xffffff00_srgbaf); return attributeOr(MaterialAttribute::SpecularColor, 0xffffff00_srgbaf);
} }
@ -190,6 +236,14 @@ UnsignedInt PbrSpecularGlossinessMaterialData::specularTextureCoordinates() cons
return attributeOr(MaterialAttribute::TextureCoordinates, 0u); 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<UnsignedInt> value = tryAttribute<UnsignedInt>(MaterialAttribute::SpecularTextureLayer))
return *value;
return attributeOr(MaterialAttribute::TextureLayer, 0u);
}
Float PbrSpecularGlossinessMaterialData::glossiness() const { Float PbrSpecularGlossinessMaterialData::glossiness() const {
return attributeOr(MaterialAttribute::Glossiness, 1.0f); return attributeOr(MaterialAttribute::Glossiness, 1.0f);
} }
@ -229,6 +283,14 @@ UnsignedInt PbrSpecularGlossinessMaterialData::glossinessTextureCoordinates() co
return attributeOr(MaterialAttribute::TextureCoordinates, 0u); 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<UnsignedInt> value = tryAttribute<UnsignedInt>(MaterialAttribute::GlossinessTextureLayer))
return *value;
return attributeOr(MaterialAttribute::TextureLayer, 0u);
}
UnsignedInt PbrSpecularGlossinessMaterialData::normalTexture() const { UnsignedInt PbrSpecularGlossinessMaterialData::normalTexture() const {
return attribute<UnsignedInt>(MaterialAttribute::NormalTexture); return attribute<UnsignedInt>(MaterialAttribute::NormalTexture);
} }
@ -261,6 +323,14 @@ UnsignedInt PbrSpecularGlossinessMaterialData::normalTextureCoordinates() const
return attributeOr(MaterialAttribute::TextureCoordinates, 0u); 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<UnsignedInt> value = tryAttribute<UnsignedInt>(MaterialAttribute::NormalTextureLayer))
return *value;
return attributeOr(MaterialAttribute::TextureLayer, 0u);
}
UnsignedInt PbrSpecularGlossinessMaterialData::occlusionTexture() const { UnsignedInt PbrSpecularGlossinessMaterialData::occlusionTexture() const {
return attribute<UnsignedInt>(MaterialAttribute::OcclusionTexture); return attribute<UnsignedInt>(MaterialAttribute::OcclusionTexture);
} }
@ -293,6 +363,14 @@ UnsignedInt PbrSpecularGlossinessMaterialData::occlusionTextureCoordinates() con
return attributeOr(MaterialAttribute::TextureCoordinates, 0u); 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<UnsignedInt> value = tryAttribute<UnsignedInt>(MaterialAttribute::OcclusionTextureLayer))
return *value;
return attributeOr(MaterialAttribute::TextureLayer, 0u);
}
Color3 PbrSpecularGlossinessMaterialData::emissiveColor() const { Color3 PbrSpecularGlossinessMaterialData::emissiveColor() const {
return attributeOr(MaterialAttribute::EmissiveColor, 0x000000_srgbf); return attributeOr(MaterialAttribute::EmissiveColor, 0x000000_srgbf);
} }
@ -317,6 +395,14 @@ UnsignedInt PbrSpecularGlossinessMaterialData::emissiveTextureCoordinates() cons
return attributeOr(MaterialAttribute::TextureCoordinates, 0u); 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<UnsignedInt> value = tryAttribute<UnsignedInt>(MaterialAttribute::EmissiveTextureLayer))
return *value;
return attributeOr(MaterialAttribute::TextureLayer, 0u);
}
Matrix3 PbrSpecularGlossinessMaterialData::commonTextureMatrix() const { Matrix3 PbrSpecularGlossinessMaterialData::commonTextureMatrix() const {
CORRADE_ASSERT(hasCommonTextureTransformation(), CORRADE_ASSERT(hasCommonTextureTransformation(),
"Trade::PbrSpecularGlossinessMaterialData::commonTextureMatrix(): the material doesn't have a common texture coordinate transformation", {}); "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); 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);
}
}} }}

124
src/Magnum/Trade/PbrSpecularGlossinessMaterialData.h

@ -90,16 +90,20 @@ class MAGNUM_TRADE_EXPORT PbrSpecularGlossinessMaterialData: public MaterialData
* is set to @ref MaterialTextureSwizzle::A, and ddditionally * is set to @ref MaterialTextureSwizzle::A, and ddditionally
* @ref MaterialAttribute::SpecularTextureMatrix and * @ref MaterialAttribute::SpecularTextureMatrix and
* @ref MaterialAttribute::GlossinessTextureMatrix are both either not * @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::SpecularTextureCoordinates and
* @ref MaterialAttribute::GlossinessTextureCoordinates are both either * @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, * In other words, if this function returns @cpp true @ce,
* @ref specularTexture(), @ref specularTextureMatrix() and * @ref specularTexture(), @ref specularTextureMatrix(),
* @ref specularTextureCoordinates() return values common for both * @ref specularTextureCoordinates() and @ref specularTextureLayer()
* specular and glossiness texture, and the two are packed together * return values common for both specular and glossiness texture, and
* with specular occupying the RGB channels and glossiness the alpha. * the two are packed together with specular occupying the RGB channels
* and glossiness the alpha.
* @see @ref hasSpecularTexture(), @ref hasGlossinessTexture() * @see @ref hasSpecularTexture(), @ref hasGlossinessTexture()
*/ */
bool hasSpecularGlossinessTexture() const; bool hasSpecularGlossinessTexture() const;
@ -165,6 +169,36 @@ class MAGNUM_TRADE_EXPORT PbrSpecularGlossinessMaterialData: public MaterialData
*/ */
bool hasCommonTextureCoordinates() const; 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 * @brief Diffuse color
* *
@ -207,6 +241,17 @@ class MAGNUM_TRADE_EXPORT PbrSpecularGlossinessMaterialData: public MaterialData
*/ */
UnsignedInt diffuseTextureCoordinates() const; 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 * @brief Specular color
* *
@ -263,6 +308,17 @@ class MAGNUM_TRADE_EXPORT PbrSpecularGlossinessMaterialData: public MaterialData
*/ */
UnsignedInt specularTextureCoordinates() const; 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 * @brief Glossiness factor
* *
@ -319,6 +375,17 @@ class MAGNUM_TRADE_EXPORT PbrSpecularGlossinessMaterialData: public MaterialData
*/ */
UnsignedInt glossinessTextureCoordinates() const; 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 * @brief Normal texture ID
* *
@ -370,6 +437,17 @@ class MAGNUM_TRADE_EXPORT PbrSpecularGlossinessMaterialData: public MaterialData
*/ */
UnsignedInt normalTextureCoordinates() const; 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 * @brief Occlusion texture ID
* *
@ -422,6 +500,17 @@ class MAGNUM_TRADE_EXPORT PbrSpecularGlossinessMaterialData: public MaterialData
*/ */
UnsignedInt occlusionTextureCoordinates() const; 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 * @brief Emissive color
* *
@ -467,6 +556,17 @@ class MAGNUM_TRADE_EXPORT PbrSpecularGlossinessMaterialData: public MaterialData
*/ */
UnsignedInt emissiveTextureCoordinates() const; 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 * @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. * no texture is present, returns @cpp 0 @ce.
*/ */
UnsignedInt commonTextureCoordinates() const; 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;
}; };
}} }}

77
src/Magnum/Trade/PhongMaterialData.cpp

@ -196,6 +196,37 @@ bool PhongMaterialData::hasCommonTextureCoordinates() const {
return true; 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<UnsignedInt>& layer, UnsignedInt current) {
if(!layer) {
layer = current;
return true;
}
return layer == current;
};
Containers::Optional<UnsignedInt> 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 { Color4 PhongMaterialData::ambientColor() const {
return attributeOr(MaterialAttribute::AmbientColor, return attributeOr(MaterialAttribute::AmbientColor,
hasAttribute(MaterialAttribute::AmbientTexture) ? 0xffffffff_rgbaf : 0x000000ff_rgbaf); hasAttribute(MaterialAttribute::AmbientTexture) ? 0xffffffff_rgbaf : 0x000000ff_rgbaf);
@ -221,6 +252,14 @@ UnsignedInt PhongMaterialData::ambientTextureCoordinates() const {
return attributeOr(MaterialAttribute::TextureCoordinates, 0u); 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<UnsignedInt> set = tryAttribute<UnsignedInt>(MaterialAttribute::AmbientTextureLayer))
return *set;
return attributeOr(MaterialAttribute::TextureLayer, 0u);
}
Color4 PhongMaterialData::diffuseColor() const { Color4 PhongMaterialData::diffuseColor() const {
return attributeOr(MaterialAttribute::DiffuseColor, 0xffffffff_rgbaf); return attributeOr(MaterialAttribute::DiffuseColor, 0xffffffff_rgbaf);
} }
@ -245,6 +284,14 @@ UnsignedInt PhongMaterialData::diffuseTextureCoordinates() const {
return attributeOr(MaterialAttribute::TextureCoordinates, 0u); 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<UnsignedInt> set = tryAttribute<UnsignedInt>(MaterialAttribute::DiffuseTextureLayer))
return *set;
return attributeOr(MaterialAttribute::TextureLayer, 0u);
}
Color4 PhongMaterialData::specularColor() const { Color4 PhongMaterialData::specularColor() const {
return attributeOr(MaterialAttribute::SpecularColor, 0xffffff00_rgbaf); return attributeOr(MaterialAttribute::SpecularColor, 0xffffff00_rgbaf);
} }
@ -284,6 +331,14 @@ UnsignedInt PhongMaterialData::specularTextureCoordinates() const {
return attributeOr(MaterialAttribute::TextureCoordinates, 0u); 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<UnsignedInt> set = tryAttribute<UnsignedInt>(MaterialAttribute::SpecularTextureLayer))
return *set;
return attributeOr(MaterialAttribute::TextureLayer, 0u);
}
UnsignedInt PhongMaterialData::normalTexture() const { UnsignedInt PhongMaterialData::normalTexture() const {
return attribute<UnsignedInt>(MaterialAttribute::NormalTexture); return attribute<UnsignedInt>(MaterialAttribute::NormalTexture);
} }
@ -316,6 +371,14 @@ UnsignedInt PhongMaterialData::normalTextureCoordinates() const {
return attributeOr(MaterialAttribute::TextureCoordinates, 0u); 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<UnsignedInt> set = tryAttribute<UnsignedInt>(MaterialAttribute::NormalTextureLayer))
return *set;
return attributeOr(MaterialAttribute::TextureLayer, 0u);
}
Matrix3 PhongMaterialData::commonTextureMatrix() const { Matrix3 PhongMaterialData::commonTextureMatrix() const {
CORRADE_ASSERT(hasCommonTextureTransformation(), CORRADE_ASSERT(hasCommonTextureTransformation(),
"Trade::PhongMaterialData::commonTextureMatrix(): the material doesn't have a common texture coordinate transformation", {}); "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); 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 { Float PhongMaterialData::shininess() const {
return attributeOr(MaterialAttribute::Shininess, 80.0f); return attributeOr(MaterialAttribute::Shininess, 80.0f);
} }

89
src/Magnum/Trade/PhongMaterialData.h

@ -301,6 +301,35 @@ class MAGNUM_TRADE_EXPORT PhongMaterialData: public MaterialData {
*/ */
bool hasCommonTextureCoordinates() const; 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 #ifdef MAGNUM_BUILD_DEPRECATED
/** /**
* @brief Material flags * @brief Material flags
@ -376,6 +405,18 @@ class MAGNUM_TRADE_EXPORT PhongMaterialData: public MaterialData {
} }
#endif #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 * @brief Diffuse color
* *
@ -432,6 +473,18 @@ class MAGNUM_TRADE_EXPORT PhongMaterialData: public MaterialData {
} }
#endif #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 * @brief Specular color
* *
@ -502,6 +555,18 @@ class MAGNUM_TRADE_EXPORT PhongMaterialData: public MaterialData {
} }
#endif #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 * @brief Normal texture ID
* @m_since{2020,06} * @m_since{2020,06}
@ -569,6 +634,18 @@ class MAGNUM_TRADE_EXPORT PhongMaterialData: public MaterialData {
} }
#endif #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 * @brief Common texture coordinate transformation matrix for all textures
* @m_since_latest * @m_since_latest
@ -609,6 +686,18 @@ class MAGNUM_TRADE_EXPORT PhongMaterialData: public MaterialData {
*/ */
UnsignedInt commonTextureCoordinates() const; 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 * @brief Shininess
* *

68
src/Magnum/Trade/Test/FlatMaterialDataTest.cpp

@ -43,10 +43,10 @@ class FlatMaterialDataTest: public TestSuite::Tester {
void texturedBaseColor(); void texturedBaseColor();
void texturedDiffuseColor(); void texturedDiffuseColor();
void texturedDefaults(); void texturedDefaults();
void texturedBaseColorSingleMatrixCoordinates(); void texturedBaseColorSingleMatrixCoordinatesLayer();
void texturedDiffuseColorSingleMatrixCoordinates(); void texturedDiffuseColorSingleMatrixCoordinatesLayer();
void texturedMismatchedMatrixCoordinates(); void texturedMismatchedMatrixCoordinatesLayer();
void texturedImplicitCoordinates(); void texturedImplicitCoordinatesLayer();
void invalidTextures(); void invalidTextures();
}; };
@ -57,10 +57,10 @@ FlatMaterialDataTest::FlatMaterialDataTest() {
&FlatMaterialDataTest::texturedBaseColor, &FlatMaterialDataTest::texturedBaseColor,
&FlatMaterialDataTest::texturedDiffuseColor, &FlatMaterialDataTest::texturedDiffuseColor,
&FlatMaterialDataTest::texturedDefaults, &FlatMaterialDataTest::texturedDefaults,
&FlatMaterialDataTest::texturedBaseColorSingleMatrixCoordinates, &FlatMaterialDataTest::texturedBaseColorSingleMatrixCoordinatesLayer,
&FlatMaterialDataTest::texturedDiffuseColorSingleMatrixCoordinates, &FlatMaterialDataTest::texturedDiffuseColorSingleMatrixCoordinatesLayer,
&FlatMaterialDataTest::texturedMismatchedMatrixCoordinates, &FlatMaterialDataTest::texturedMismatchedMatrixCoordinatesLayer,
&FlatMaterialDataTest::texturedImplicitCoordinates, &FlatMaterialDataTest::texturedImplicitCoordinatesLayer,
&FlatMaterialDataTest::invalidTextures}); &FlatMaterialDataTest::invalidTextures});
} }
@ -78,6 +78,7 @@ void FlatMaterialDataTest::baseColor() {
CORRADE_VERIFY(!data.hasTexture()); CORRADE_VERIFY(!data.hasTexture());
CORRADE_VERIFY(!data.hasTextureTransformation()); CORRADE_VERIFY(!data.hasTextureTransformation());
CORRADE_VERIFY(!data.hasTextureCoordinates()); CORRADE_VERIFY(!data.hasTextureCoordinates());
CORRADE_VERIFY(!data.hasTextureLayer());
CORRADE_COMPARE(data.color(), 0xccffbb_rgbf); CORRADE_COMPARE(data.color(), 0xccffbb_rgbf);
} }
@ -92,6 +93,7 @@ void FlatMaterialDataTest::diffuseColor() {
CORRADE_VERIFY(!data.hasTexture()); CORRADE_VERIFY(!data.hasTexture());
CORRADE_VERIFY(!data.hasTextureTransformation()); CORRADE_VERIFY(!data.hasTextureTransformation());
CORRADE_VERIFY(!data.hasTextureCoordinates()); CORRADE_VERIFY(!data.hasTextureCoordinates());
CORRADE_VERIFY(!data.hasTextureLayer());
CORRADE_COMPARE(data.color(), 0xccffbb_rgbf); CORRADE_COMPARE(data.color(), 0xccffbb_rgbf);
} }
@ -105,6 +107,7 @@ void FlatMaterialDataTest::defaults() {
CORRADE_VERIFY(!data.hasTexture()); CORRADE_VERIFY(!data.hasTexture());
CORRADE_VERIFY(!data.hasTextureTransformation()); CORRADE_VERIFY(!data.hasTextureTransformation());
CORRADE_VERIFY(!data.hasTextureCoordinates()); CORRADE_VERIFY(!data.hasTextureCoordinates());
CORRADE_VERIFY(!data.hasTextureLayer());
CORRADE_COMPARE(data.color(), 0xffffff_rgbf); CORRADE_COMPARE(data.color(), 0xffffff_rgbf);
} }
@ -114,21 +117,25 @@ void FlatMaterialDataTest::texturedBaseColor() {
{MaterialAttribute::BaseColorTexture, 5u}, {MaterialAttribute::BaseColorTexture, 5u},
{MaterialAttribute::BaseColorTextureMatrix, Matrix3::scaling({0.5f, 1.0f})}, {MaterialAttribute::BaseColorTextureMatrix, Matrix3::scaling({0.5f, 1.0f})},
{MaterialAttribute::BaseColorTextureCoordinates, 2u}, {MaterialAttribute::BaseColorTextureCoordinates, 2u},
{MaterialAttribute::BaseColorTextureLayer, 17u},
/* All this is ignored */ /* All this is ignored */
{MaterialAttribute::DiffuseColor, 0x33556600_rgbaf}, {MaterialAttribute::DiffuseColor, 0x33556600_rgbaf},
{MaterialAttribute::DiffuseTexture, 6u}, {MaterialAttribute::DiffuseTexture, 6u},
{MaterialAttribute::DiffuseTextureMatrix, Matrix3::translation({0.5f, 1.0f})}, {MaterialAttribute::DiffuseTextureMatrix, Matrix3::translation({0.5f, 1.0f})},
{MaterialAttribute::DiffuseTextureCoordinates, 3u} {MaterialAttribute::DiffuseTextureCoordinates, 3u},
{MaterialAttribute::DiffuseTextureLayer, 66u},
}}; }};
CORRADE_VERIFY(data.hasTexture()); CORRADE_VERIFY(data.hasTexture());
CORRADE_VERIFY(data.hasTextureTransformation()); CORRADE_VERIFY(data.hasTextureTransformation());
CORRADE_VERIFY(data.hasTextureCoordinates()); CORRADE_VERIFY(data.hasTextureCoordinates());
CORRADE_VERIFY(data.hasTextureLayer());
CORRADE_COMPARE(data.color(), 0xccffbb_rgbf); CORRADE_COMPARE(data.color(), 0xccffbb_rgbf);
CORRADE_COMPARE(data.texture(), 5); CORRADE_COMPARE(data.texture(), 5);
CORRADE_COMPARE(data.textureMatrix(), Matrix3::scaling({0.5f, 1.0f})); CORRADE_COMPARE(data.textureMatrix(), Matrix3::scaling({0.5f, 1.0f}));
CORRADE_COMPARE(data.textureCoordinates(), 2); CORRADE_COMPARE(data.textureCoordinates(), 2);
CORRADE_COMPARE(data.textureLayer(), 17);
} }
void FlatMaterialDataTest::texturedDiffuseColor() { void FlatMaterialDataTest::texturedDiffuseColor() {
@ -137,6 +144,7 @@ void FlatMaterialDataTest::texturedDiffuseColor() {
{MaterialAttribute::DiffuseTexture, 5u}, {MaterialAttribute::DiffuseTexture, 5u},
{MaterialAttribute::DiffuseTextureMatrix, Matrix3::scaling({0.5f, 1.0f})}, {MaterialAttribute::DiffuseTextureMatrix, Matrix3::scaling({0.5f, 1.0f})},
{MaterialAttribute::DiffuseTextureCoordinates, 2u}, {MaterialAttribute::DiffuseTextureCoordinates, 2u},
{MaterialAttribute::DiffuseTextureLayer, 17u},
/* Ignored, as we have a diffuse texture */ /* Ignored, as we have a diffuse texture */
{MaterialAttribute::BaseColor, 0x33556600_rgbaf} {MaterialAttribute::BaseColor, 0x33556600_rgbaf}
@ -145,10 +153,12 @@ void FlatMaterialDataTest::texturedDiffuseColor() {
CORRADE_VERIFY(data.hasTexture()); CORRADE_VERIFY(data.hasTexture());
CORRADE_VERIFY(data.hasTextureTransformation()); CORRADE_VERIFY(data.hasTextureTransformation());
CORRADE_VERIFY(data.hasTextureCoordinates()); CORRADE_VERIFY(data.hasTextureCoordinates());
CORRADE_VERIFY(data.hasTextureLayer());
CORRADE_COMPARE(data.color(), 0xccffbb_rgbf); CORRADE_COMPARE(data.color(), 0xccffbb_rgbf);
CORRADE_COMPARE(data.texture(), 5); CORRADE_COMPARE(data.texture(), 5);
CORRADE_COMPARE(data.textureMatrix(), Matrix3::scaling({0.5f, 1.0f})); CORRADE_COMPARE(data.textureMatrix(), Matrix3::scaling({0.5f, 1.0f}));
CORRADE_COMPARE(data.textureCoordinates(), 2); CORRADE_COMPARE(data.textureCoordinates(), 2);
CORRADE_COMPARE(data.textureLayer(), 17);
} }
void FlatMaterialDataTest::texturedDefaults() { void FlatMaterialDataTest::texturedDefaults() {
@ -159,55 +169,65 @@ void FlatMaterialDataTest::texturedDefaults() {
CORRADE_VERIFY(data.hasTexture()); CORRADE_VERIFY(data.hasTexture());
CORRADE_VERIFY(!data.hasTextureTransformation()); CORRADE_VERIFY(!data.hasTextureTransformation());
CORRADE_VERIFY(!data.hasTextureCoordinates()); CORRADE_VERIFY(!data.hasTextureCoordinates());
CORRADE_VERIFY(!data.hasTextureLayer());
CORRADE_COMPARE(data.color(), 0xffffff_rgbf); CORRADE_COMPARE(data.color(), 0xffffff_rgbf);
CORRADE_COMPARE(data.texture(), 5); CORRADE_COMPARE(data.texture(), 5);
CORRADE_COMPARE(data.textureMatrix(), Matrix3{}); CORRADE_COMPARE(data.textureMatrix(), Matrix3{});
CORRADE_COMPARE(data.textureCoordinates(), 0); CORRADE_COMPARE(data.textureCoordinates(), 0);
CORRADE_COMPARE(data.textureLayer(), 0);
} }
void FlatMaterialDataTest::texturedBaseColorSingleMatrixCoordinates() { void FlatMaterialDataTest::texturedBaseColorSingleMatrixCoordinatesLayer() {
FlatMaterialData data{{}, { FlatMaterialData data{{}, {
{MaterialAttribute::BaseColor, 0xccffbbff_rgbaf}, {MaterialAttribute::BaseColor, 0xccffbbff_rgbaf},
{MaterialAttribute::BaseColorTexture, 5u}, {MaterialAttribute::BaseColorTexture, 5u},
{MaterialAttribute::TextureMatrix, Matrix3::scaling({0.5f, 1.0f})}, {MaterialAttribute::TextureMatrix, Matrix3::scaling({0.5f, 1.0f})},
{MaterialAttribute::TextureCoordinates, 2u}, {MaterialAttribute::TextureCoordinates, 2u},
{MaterialAttribute::TextureLayer, 17u},
/* This is ignored because it doesn't match the texture */ /* This is ignored because it doesn't match the texture */
{MaterialAttribute::DiffuseTextureMatrix, Matrix3::translation({0.5f, 1.0f})}, {MaterialAttribute::DiffuseTextureMatrix, Matrix3::translation({0.5f, 1.0f})},
{MaterialAttribute::DiffuseTextureCoordinates, 3u} {MaterialAttribute::DiffuseTextureCoordinates, 3u},
{MaterialAttribute::DiffuseTextureLayer, 66u},
}}; }};
CORRADE_VERIFY(data.hasTexture()); CORRADE_VERIFY(data.hasTexture());
CORRADE_VERIFY(data.hasTextureTransformation()); CORRADE_VERIFY(data.hasTextureTransformation());
CORRADE_VERIFY(data.hasTextureCoordinates()); CORRADE_VERIFY(data.hasTextureCoordinates());
CORRADE_VERIFY(data.hasTextureLayer());
CORRADE_COMPARE(data.color(), 0xccffbb_rgbf); CORRADE_COMPARE(data.color(), 0xccffbb_rgbf);
CORRADE_COMPARE(data.texture(), 5); CORRADE_COMPARE(data.texture(), 5);
CORRADE_COMPARE(data.textureMatrix(), Matrix3::scaling({0.5f, 1.0f})); CORRADE_COMPARE(data.textureMatrix(), Matrix3::scaling({0.5f, 1.0f}));
CORRADE_COMPARE(data.textureCoordinates(), 2); CORRADE_COMPARE(data.textureCoordinates(), 2);
CORRADE_COMPARE(data.textureLayer(), 17);
} }
void FlatMaterialDataTest::texturedDiffuseColorSingleMatrixCoordinates() { void FlatMaterialDataTest::texturedDiffuseColorSingleMatrixCoordinatesLayer() {
FlatMaterialData data{{}, { FlatMaterialData data{{}, {
{MaterialAttribute::DiffuseColor, 0xccffbbff_rgbaf}, {MaterialAttribute::DiffuseColor, 0xccffbbff_rgbaf},
{MaterialAttribute::DiffuseTexture, 5u}, {MaterialAttribute::DiffuseTexture, 5u},
{MaterialAttribute::TextureMatrix, Matrix3::scaling({0.5f, 1.0f})}, {MaterialAttribute::TextureMatrix, Matrix3::scaling({0.5f, 1.0f})},
{MaterialAttribute::TextureCoordinates, 2u}, {MaterialAttribute::TextureCoordinates, 2u},
{MaterialAttribute::TextureLayer, 17u},
/* This is ignored because it doesn't match the texture */ /* This is ignored because it doesn't match the texture */
{MaterialAttribute::BaseColorTextureMatrix, Matrix3::translation({0.5f, 1.0f})}, {MaterialAttribute::BaseColorTextureMatrix, Matrix3::translation({0.5f, 1.0f})},
{MaterialAttribute::BaseColorTextureCoordinates, 3u} {MaterialAttribute::BaseColorTextureCoordinates, 3u},
{MaterialAttribute::BaseColorTextureLayer, 66u}
}}; }};
CORRADE_VERIFY(data.hasTexture()); CORRADE_VERIFY(data.hasTexture());
CORRADE_VERIFY(data.hasTextureTransformation()); CORRADE_VERIFY(data.hasTextureTransformation());
CORRADE_VERIFY(data.hasTextureCoordinates()); CORRADE_VERIFY(data.hasTextureCoordinates());
CORRADE_VERIFY(data.hasTextureLayer());
CORRADE_COMPARE(data.color(), 0xccffbb_rgbf); CORRADE_COMPARE(data.color(), 0xccffbb_rgbf);
CORRADE_COMPARE(data.texture(), 5); CORRADE_COMPARE(data.texture(), 5);
CORRADE_COMPARE(data.textureMatrix(), Matrix3::scaling({0.5f, 1.0f})); CORRADE_COMPARE(data.textureMatrix(), Matrix3::scaling({0.5f, 1.0f}));
CORRADE_COMPARE(data.textureCoordinates(), 2); CORRADE_COMPARE(data.textureCoordinates(), 2);
CORRADE_COMPARE(data.textureLayer(), 17);
} }
void FlatMaterialDataTest::texturedMismatchedMatrixCoordinates() { void FlatMaterialDataTest::texturedMismatchedMatrixCoordinatesLayer() {
{ {
FlatMaterialData data{{}, { FlatMaterialData data{{}, {
{MaterialAttribute::BaseColorTexture, 5u}, {MaterialAttribute::BaseColorTexture, 5u},
@ -216,15 +236,18 @@ void FlatMaterialDataTest::texturedMismatchedMatrixCoordinates() {
{MaterialAttribute::DiffuseColor, 0x33556600_rgbaf}, {MaterialAttribute::DiffuseColor, 0x33556600_rgbaf},
{MaterialAttribute::DiffuseTextureMatrix, Matrix3::scaling({0.5f, 1.0f})}, {MaterialAttribute::DiffuseTextureMatrix, Matrix3::scaling({0.5f, 1.0f})},
{MaterialAttribute::DiffuseTextureCoordinates, 2u}, {MaterialAttribute::DiffuseTextureCoordinates, 2u},
{MaterialAttribute::DiffuseTextureLayer, 17u},
}}; }};
CORRADE_VERIFY(data.hasTexture()); CORRADE_VERIFY(data.hasTexture());
CORRADE_VERIFY(!data.hasTextureTransformation()); CORRADE_VERIFY(!data.hasTextureTransformation());
CORRADE_VERIFY(!data.hasTextureCoordinates()); CORRADE_VERIFY(!data.hasTextureCoordinates());
CORRADE_VERIFY(!data.hasTextureLayer());
CORRADE_COMPARE(data.color(), 0xffffff_rgbf); CORRADE_COMPARE(data.color(), 0xffffff_rgbf);
CORRADE_COMPARE(data.texture(), 5); CORRADE_COMPARE(data.texture(), 5);
CORRADE_COMPARE(data.textureMatrix(), Matrix3{}); CORRADE_COMPARE(data.textureMatrix(), Matrix3{});
CORRADE_COMPARE(data.textureCoordinates(), 0); CORRADE_COMPARE(data.textureCoordinates(), 0);
CORRADE_COMPARE(data.textureLayer(), 0);
} { } {
FlatMaterialData data{{}, { FlatMaterialData data{{}, {
{MaterialAttribute::DiffuseTexture, 5u}, {MaterialAttribute::DiffuseTexture, 5u},
@ -233,43 +256,54 @@ void FlatMaterialDataTest::texturedMismatchedMatrixCoordinates() {
{MaterialAttribute::BaseColor, 0x33556600_rgbaf}, {MaterialAttribute::BaseColor, 0x33556600_rgbaf},
{MaterialAttribute::BaseColorTextureMatrix, Matrix3::scaling({0.5f, 1.0f})}, {MaterialAttribute::BaseColorTextureMatrix, Matrix3::scaling({0.5f, 1.0f})},
{MaterialAttribute::BaseColorTextureCoordinates, 2u}, {MaterialAttribute::BaseColorTextureCoordinates, 2u},
{MaterialAttribute::BaseColorTextureLayer, 17u},
}}; }};
CORRADE_VERIFY(data.hasTexture()); CORRADE_VERIFY(data.hasTexture());
CORRADE_VERIFY(!data.hasTextureTransformation()); CORRADE_VERIFY(!data.hasTextureTransformation());
CORRADE_VERIFY(!data.hasTextureCoordinates()); CORRADE_VERIFY(!data.hasTextureCoordinates());
CORRADE_VERIFY(!data.hasTextureLayer());
CORRADE_COMPARE(data.color(), 0xffffff_rgbf); CORRADE_COMPARE(data.color(), 0xffffff_rgbf);
CORRADE_COMPARE(data.texture(), 5); CORRADE_COMPARE(data.texture(), 5);
CORRADE_COMPARE(data.textureMatrix(), Matrix3{}); CORRADE_COMPARE(data.textureMatrix(), Matrix3{});
CORRADE_COMPARE(data.textureCoordinates(), 0); CORRADE_COMPARE(data.textureCoordinates(), 0);
CORRADE_COMPARE(data.textureLayer(), 0);
} }
} }
void FlatMaterialDataTest::texturedImplicitCoordinates() { void FlatMaterialDataTest::texturedImplicitCoordinatesLayer() {
{ {
FlatMaterialData data{{}, { FlatMaterialData data{{}, {
{MaterialAttribute::BaseColorTexture, 5u}, {MaterialAttribute::BaseColorTexture, 5u},
{MaterialAttribute::BaseColorTextureCoordinates, 0u}, {MaterialAttribute::BaseColorTextureCoordinates, 0u},
{MaterialAttribute::BaseColorTextureLayer, 0u},
/* This is ignored because it doesn't match the texture */ /* This is ignored because it doesn't match the texture */
{MaterialAttribute::DiffuseTextureCoordinates, 2u}, {MaterialAttribute::DiffuseTextureCoordinates, 2u},
{MaterialAttribute::DiffuseTextureLayer, 17u},
}}; }};
CORRADE_VERIFY(data.hasTexture()); CORRADE_VERIFY(data.hasTexture());
CORRADE_VERIFY(!data.hasTextureCoordinates()); CORRADE_VERIFY(!data.hasTextureCoordinates());
CORRADE_VERIFY(!data.hasTextureLayer());
CORRADE_COMPARE(data.textureCoordinates(), 0); CORRADE_COMPARE(data.textureCoordinates(), 0);
CORRADE_COMPARE(data.textureLayer(), 0);
} { } {
FlatMaterialData data{{}, { FlatMaterialData data{{}, {
{MaterialAttribute::DiffuseTexture, 5u}, {MaterialAttribute::DiffuseTexture, 5u},
{MaterialAttribute::DiffuseTextureCoordinates, 0u}, {MaterialAttribute::DiffuseTextureCoordinates, 0u},
{MaterialAttribute::DiffuseTextureLayer, 0u},
/* This is ignored because it doesn't match the texture */ /* This is ignored because it doesn't match the texture */
{MaterialAttribute::BaseColorTextureCoordinates, 2u}, {MaterialAttribute::BaseColorTextureCoordinates, 2u},
{MaterialAttribute::BaseColorTextureLayer, 17u},
}}; }};
CORRADE_VERIFY(data.hasTexture()); CORRADE_VERIFY(data.hasTexture());
CORRADE_VERIFY(!data.hasTextureCoordinates()); CORRADE_VERIFY(!data.hasTextureCoordinates());
CORRADE_VERIFY(!data.hasTextureLayer());
CORRADE_COMPARE(data.textureCoordinates(), 0); CORRADE_COMPARE(data.textureCoordinates(), 0);
CORRADE_COMPARE(data.textureLayer(), 0);
} }
} }
@ -285,10 +319,12 @@ void FlatMaterialDataTest::invalidTextures() {
data.texture(); data.texture();
data.textureMatrix(); data.textureMatrix();
data.textureCoordinates(); data.textureCoordinates();
data.textureLayer();
CORRADE_COMPARE(out.str(), CORRADE_COMPARE(out.str(),
"Trade::FlatMaterialData::texture(): the material doesn't have a texture\n" "Trade::FlatMaterialData::texture(): the material doesn't have a texture\n"
"Trade::FlatMaterialData::textureMatrix(): 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");
} }
}}}} }}}}

57
src/Magnum/Trade/Test/MaterialDataTest.cpp

@ -124,8 +124,8 @@ class MaterialDataTest: public TestSuite::Tester {
void accessLayersDefaults(); void accessLayersDefaults();
void accessLayersTextured(); void accessLayersTextured();
void accessLayersTexturedDefault(); void accessLayersTexturedDefault();
void accessLayersTexturedSingleMatrixCoordinates(); void accessLayersTexturedSingleMatrixCoordinatesLayer();
void accessLayersTexturedBaseMaterialMatrixCoordinates(); void accessLayersTexturedBaseMaterialMatrixCoordinatesLayer();
void accessLayersInvalidTextures(); void accessLayersInvalidTextures();
void accessLayerLayerNameInBaseMaterial(); void accessLayerLayerNameInBaseMaterial();
@ -277,8 +277,8 @@ MaterialDataTest::MaterialDataTest() {
&MaterialDataTest::accessLayersDefaults, &MaterialDataTest::accessLayersDefaults,
&MaterialDataTest::accessLayersTextured, &MaterialDataTest::accessLayersTextured,
&MaterialDataTest::accessLayersTexturedDefault, &MaterialDataTest::accessLayersTexturedDefault,
&MaterialDataTest::accessLayersTexturedSingleMatrixCoordinates, &MaterialDataTest::accessLayersTexturedSingleMatrixCoordinatesLayer,
&MaterialDataTest::accessLayersTexturedBaseMaterialMatrixCoordinates, &MaterialDataTest::accessLayersTexturedBaseMaterialMatrixCoordinatesLayer,
&MaterialDataTest::accessLayersInvalidTextures, &MaterialDataTest::accessLayersInvalidTextures,
&MaterialDataTest::accessLayerLayerNameInBaseMaterial, &MaterialDataTest::accessLayerLayerNameInBaseMaterial,
@ -1984,8 +1984,9 @@ void MaterialDataTest::accessLayersTextured() {
{MaterialAttribute::LayerFactorTextureSwizzle, MaterialTextureSwizzle::A}, {MaterialAttribute::LayerFactorTextureSwizzle, MaterialTextureSwizzle::A},
{MaterialAttribute::LayerFactorTextureMatrix, Matrix3::scaling({0.5f, 1.0f})}, {MaterialAttribute::LayerFactorTextureMatrix, Matrix3::scaling({0.5f, 1.0f})},
{MaterialAttribute::LayerFactorTextureCoordinates, 2u}, {MaterialAttribute::LayerFactorTextureCoordinates, 2u},
{MaterialAttribute::LayerFactorTextureLayer, 3u},
}, { }, {
0, 1, 7 0, 1, 8
}}; }};
CORRADE_COMPARE(data.layerCount(), 3); CORRADE_COMPARE(data.layerCount(), 3);
@ -2009,6 +2010,10 @@ void MaterialDataTest::accessLayersTextured() {
CORRADE_COMPARE(data.layerFactorTextureCoordinates(2), 2u); CORRADE_COMPARE(data.layerFactorTextureCoordinates(2), 2u);
CORRADE_COMPARE(data.layerFactorTextureCoordinates("ClearCoat"), 2u); CORRADE_COMPARE(data.layerFactorTextureCoordinates("ClearCoat"), 2u);
CORRADE_COMPARE(data.layerFactorTextureCoordinates(MaterialLayer::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() { void MaterialDataTest::accessLayersTexturedDefault() {
@ -2042,16 +2047,21 @@ void MaterialDataTest::accessLayersTexturedDefault() {
CORRADE_COMPARE(data.layerFactorTextureCoordinates(2), 0); CORRADE_COMPARE(data.layerFactorTextureCoordinates(2), 0);
CORRADE_COMPARE(data.layerFactorTextureCoordinates("ClearCoat"), 0); CORRADE_COMPARE(data.layerFactorTextureCoordinates("ClearCoat"), 0);
CORRADE_COMPARE(data.layerFactorTextureCoordinates(MaterialLayer::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{{}, { MaterialData data{{}, {
{MaterialAttribute::LayerName, "ClearCoat"}, {MaterialAttribute::LayerName, "ClearCoat"},
{MaterialAttribute::LayerFactorTexture, 4u}, {MaterialAttribute::LayerFactorTexture, 4u},
{MaterialAttribute::TextureMatrix, Matrix3::scaling({0.5f, 1.0f})}, {MaterialAttribute::TextureMatrix, Matrix3::scaling({0.5f, 1.0f})},
{MaterialAttribute::TextureCoordinates, 2u}, {MaterialAttribute::TextureCoordinates, 2u},
{MaterialAttribute::TextureLayer, 3u},
}, { }, {
0, 4 0, 5
}}; }};
CORRADE_COMPARE(data.layerFactorTextureMatrix(1), Matrix3::scaling({0.5f, 1.0f})); 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(1), 2u);
CORRADE_COMPARE(data.layerFactorTextureCoordinates("ClearCoat"), 2u); CORRADE_COMPARE(data.layerFactorTextureCoordinates("ClearCoat"), 2u);
CORRADE_COMPARE(data.layerFactorTextureCoordinates(MaterialLayer::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{{}, { MaterialData data{{}, {
{MaterialAttribute::TextureMatrix, Matrix3::scaling({0.5f, 1.0f})}, {MaterialAttribute::TextureMatrix, Matrix3::scaling({0.5f, 1.0f})},
{MaterialAttribute::TextureCoordinates, 2u}, {MaterialAttribute::TextureCoordinates, 2u},
{MaterialAttribute::TextureLayer, 3u},
{MaterialAttribute::LayerName, "ClearCoat"}, {MaterialAttribute::LayerName, "ClearCoat"},
{MaterialAttribute::LayerFactorTexture, 4u}, {MaterialAttribute::LayerFactorTexture, 4u},
}, { }, {
2, 4 3, 5
}}; }};
CORRADE_COMPARE(data.layerFactorTextureMatrix(1), Matrix3::scaling({0.5f, 1.0f})); 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(1), 2u);
CORRADE_COMPARE(data.layerFactorTextureCoordinates("ClearCoat"), 2u); CORRADE_COMPARE(data.layerFactorTextureCoordinates("ClearCoat"), 2u);
CORRADE_COMPARE(data.layerFactorTextureCoordinates(MaterialLayer::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() { void MaterialDataTest::accessLayersInvalidTextures() {
@ -2106,6 +2125,9 @@ void MaterialDataTest::accessLayersInvalidTextures() {
data.layerFactorTextureCoordinates(1); data.layerFactorTextureCoordinates(1);
data.layerFactorTextureCoordinates("ClearCoat"); data.layerFactorTextureCoordinates("ClearCoat");
data.layerFactorTextureCoordinates(MaterialLayer::ClearCoat); data.layerFactorTextureCoordinates(MaterialLayer::ClearCoat);
data.layerFactorTextureLayer(1);
data.layerFactorTextureLayer("ClearCoat");
data.layerFactorTextureLayer(MaterialLayer::ClearCoat);
CORRADE_COMPARE(out.str(), CORRADE_COMPARE(out.str(),
"Trade::MaterialData::attribute(): attribute LayerFactorTexture not found in layer 1\n" "Trade::MaterialData::attribute(): attribute LayerFactorTexture not found in layer 1\n"
"Trade::MaterialData::attribute(): attribute LayerFactorTexture not found in layer ClearCoat\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::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 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::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() { void MaterialDataTest::accessLayerLayerNameInBaseMaterial() {
@ -2359,6 +2384,7 @@ void MaterialDataTest::accessLayerOutOfBounds() {
data.layerFactorTextureSwizzle(2); data.layerFactorTextureSwizzle(2);
data.layerFactorTextureMatrix(2); data.layerFactorTextureMatrix(2);
data.layerFactorTextureCoordinates(2); data.layerFactorTextureCoordinates(2);
data.layerFactorTextureLayer(2);
data.attributeCount(2); data.attributeCount(2);
data.hasAttribute(2, "AlphaMask"); data.hasAttribute(2, "AlphaMask");
data.hasAttribute(2, MaterialAttribute::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::layerFactorTextureSwizzle(): index 2 out of range for 2 layers\n"
"Trade::MaterialData::layerFactorTextureMatrix(): 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::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::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"
"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.layerFactorTextureSwizzle("ClearCoat");
data.layerFactorTextureMatrix("ClearCoat"); data.layerFactorTextureMatrix("ClearCoat");
data.layerFactorTextureCoordinates("ClearCoat"); data.layerFactorTextureCoordinates("ClearCoat");
data.layerFactorTextureLayer("ClearCoat");
data.attributeCount("ClearCoat"); data.attributeCount("ClearCoat");
data.hasAttribute("ClearCoat", "AlphaMask"); data.hasAttribute("ClearCoat", "AlphaMask");
data.hasAttribute("ClearCoat", MaterialAttribute::AlphaMask); data.hasAttribute("ClearCoat", MaterialAttribute::AlphaMask);
@ -2480,6 +2508,7 @@ void MaterialDataTest::accessLayerNotFound() {
"Trade::MaterialData::layerFactorTextureSwizzle(): layer ClearCoat not found\n" "Trade::MaterialData::layerFactorTextureSwizzle(): layer ClearCoat not found\n"
"Trade::MaterialData::layerFactorTextureMatrix(): layer ClearCoat not found\n" "Trade::MaterialData::layerFactorTextureMatrix(): layer ClearCoat not found\n"
"Trade::MaterialData::layerFactorTextureCoordinates(): 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::attributeCount(): layer ClearCoat not found\n"
"Trade::MaterialData::hasAttribute(): layer ClearCoat not found\n" "Trade::MaterialData::hasAttribute(): 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.layerFactorTextureSwizzle(MaterialLayer(0xfefe));
data.layerFactorTextureMatrix(MaterialLayer(0xfefe)); data.layerFactorTextureMatrix(MaterialLayer(0xfefe));
data.layerFactorTextureCoordinates(MaterialLayer(0xfefe)); data.layerFactorTextureCoordinates(MaterialLayer(0xfefe));
data.layerFactorTextureLayer(MaterialLayer(0xfefe));
data.attributeCount(MaterialLayer(0xfefe)); data.attributeCount(MaterialLayer(0xfefe));
data.hasAttribute(MaterialLayer(0xfefe), "AlphaMask"); data.hasAttribute(MaterialLayer(0xfefe), "AlphaMask");
data.hasAttribute(MaterialLayer(0xfefe), MaterialAttribute::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::layerFactorTextureSwizzle(): invalid name Trade::MaterialLayer(0xfefe)\n"
"Trade::MaterialData::layerFactorTextureMatrix(): 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::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::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"
"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::LayerFactorTextureSwizzle, MaterialTextureSwizzle::B},
{MaterialAttribute::LayerFactorTextureMatrix, Matrix3::scaling({0.5f, 1.0f})}, {MaterialAttribute::LayerFactorTextureMatrix, Matrix3::scaling({0.5f, 1.0f})},
{MaterialAttribute::LayerFactorTextureCoordinates, 4u}, {MaterialAttribute::LayerFactorTextureCoordinates, 4u},
}, {1, 7}}; {MaterialAttribute::LayerFactorTextureLayer, 5u},
}, {1, 8}};
CORRADE_COMPARE(data.layerName(), "ClearCoat"); CORRADE_COMPARE(data.layerName(), "ClearCoat");
CORRADE_COMPARE(data.layerFactor(), 0.35f); CORRADE_COMPARE(data.layerFactor(), 0.35f);
@ -2918,8 +2950,9 @@ void MaterialDataTest::templateLayerAccess() {
CORRADE_COMPARE(data.layerFactorTextureSwizzle(), MaterialTextureSwizzle::B); CORRADE_COMPARE(data.layerFactorTextureSwizzle(), MaterialTextureSwizzle::B);
CORRADE_COMPARE(data.layerFactorTextureMatrix(), Matrix3::scaling({0.5f, 1.0f})); CORRADE_COMPARE(data.layerFactorTextureMatrix(), Matrix3::scaling({0.5f, 1.0f}));
CORRADE_COMPARE(data.layerFactorTextureCoordinates(), 4u); 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(MaterialAttribute::LayerFactor));
CORRADE_VERIFY(data.hasAttribute("LayerFactorTexture")); CORRADE_VERIFY(data.hasAttribute("LayerFactorTexture"));
CORRADE_VERIFY(!data.hasAttribute(MaterialAttribute::BaseColor)); CORRADE_VERIFY(!data.hasAttribute(MaterialAttribute::BaseColor));

132
src/Magnum/Trade/Test/PbrClearCoatMaterialDataTest.cpp

@ -41,14 +41,14 @@ class PbrClearCoatMaterialDataTest: public TestSuite::Tester {
void textured(); void textured();
void texturedDefaults(); void texturedDefaults();
void texturedExplicitPackedLayerFactorRoughness(); void texturedExplicitPackedLayerFactorRoughness();
void texturedSingleMatrixCoordinates(); void texturedSingleMatrixCoordinatesLayer();
void texturedBaseMaterialMatrixCoordinates(); void texturedBaseMaterialMatrixCoordinatesLayer();
void invalidTextures(); void invalidTextures();
void commonTransformationCoordinatesNoTextures(); void commonTransformationCoordinatesLayerNoTextures();
void commonTransformationCoordinatesOneTexture(); void commonTransformationCoordinatesLayerOneTexture();
void commonTransformationCoordinatesOneDifferentTexture(); void commonTransformationCoordinatesLayerOneDifferentTexture();
void commonCoordinatesImplicit(); void commonCoordinatesLayerImplicit();
void noCommonTransformationCoordinates(); void noCommonTransformationCoordinatesLayer();
}; };
const Containers::StringView PbrClearCoatTextureData[] { const Containers::StringView PbrClearCoatTextureData[] {
@ -63,18 +63,18 @@ PbrClearCoatMaterialDataTest::PbrClearCoatMaterialDataTest() {
&PbrClearCoatMaterialDataTest::textured, &PbrClearCoatMaterialDataTest::textured,
&PbrClearCoatMaterialDataTest::texturedDefaults, &PbrClearCoatMaterialDataTest::texturedDefaults,
&PbrClearCoatMaterialDataTest::texturedExplicitPackedLayerFactorRoughness, &PbrClearCoatMaterialDataTest::texturedExplicitPackedLayerFactorRoughness,
&PbrClearCoatMaterialDataTest::texturedSingleMatrixCoordinates, &PbrClearCoatMaterialDataTest::texturedSingleMatrixCoordinatesLayer,
&PbrClearCoatMaterialDataTest::texturedBaseMaterialMatrixCoordinates, &PbrClearCoatMaterialDataTest::texturedBaseMaterialMatrixCoordinatesLayer,
&PbrClearCoatMaterialDataTest::invalidTextures, &PbrClearCoatMaterialDataTest::invalidTextures,
&PbrClearCoatMaterialDataTest::commonTransformationCoordinatesNoTextures}); &PbrClearCoatMaterialDataTest::commonTransformationCoordinatesLayerNoTextures});
addInstancedTests({ addInstancedTests({
&PbrClearCoatMaterialDataTest::commonTransformationCoordinatesOneTexture, &PbrClearCoatMaterialDataTest::commonTransformationCoordinatesLayerOneTexture,
&PbrClearCoatMaterialDataTest::commonTransformationCoordinatesOneDifferentTexture, &PbrClearCoatMaterialDataTest::commonTransformationCoordinatesLayerOneDifferentTexture,
&PbrClearCoatMaterialDataTest::commonCoordinatesImplicit}, &PbrClearCoatMaterialDataTest::commonCoordinatesLayerImplicit},
Containers::arraySize(PbrClearCoatTextureData)); Containers::arraySize(PbrClearCoatTextureData));
addTests({&PbrClearCoatMaterialDataTest::noCommonTransformationCoordinates}); addTests({&PbrClearCoatMaterialDataTest::noCommonTransformationCoordinatesLayer});
} }
using namespace Math::Literals; using namespace Math::Literals;
@ -90,6 +90,7 @@ void PbrClearCoatMaterialDataTest::basics() {
CORRADE_VERIFY(!data.hasTextureTransformation()); CORRADE_VERIFY(!data.hasTextureTransformation());
CORRADE_VERIFY(!data.hasTextureCoordinates()); CORRADE_VERIFY(!data.hasTextureCoordinates());
CORRADE_VERIFY(!data.hasTextureLayer());
CORRADE_COMPARE(data.roughness(), 0.7f); CORRADE_COMPARE(data.roughness(), 0.7f);
} }
@ -105,6 +106,7 @@ void PbrClearCoatMaterialDataTest::defaults() {
CORRADE_VERIFY(!data.hasTextureTransformation()); CORRADE_VERIFY(!data.hasTextureTransformation());
CORRADE_VERIFY(!data.hasTextureCoordinates()); CORRADE_VERIFY(!data.hasTextureCoordinates());
CORRADE_VERIFY(!data.hasTextureLayer());
CORRADE_COMPARE(data.layerFactor(), 1.0f); CORRADE_COMPARE(data.layerFactor(), 1.0f);
CORRADE_COMPARE(data.roughness(), 0.0f); CORRADE_COMPARE(data.roughness(), 0.0f);
} }
@ -117,25 +119,30 @@ void PbrClearCoatMaterialDataTest::textured() {
{MaterialAttribute::RoughnessTextureSwizzle, MaterialTextureSwizzle::A}, {MaterialAttribute::RoughnessTextureSwizzle, MaterialTextureSwizzle::A},
{MaterialAttribute::RoughnessTextureMatrix, Matrix3::translation({2.0f, 1.5f})}, {MaterialAttribute::RoughnessTextureMatrix, Matrix3::translation({2.0f, 1.5f})},
{MaterialAttribute::RoughnessTextureCoordinates, 6u}, {MaterialAttribute::RoughnessTextureCoordinates, 6u},
{MaterialAttribute::RoughnessTextureLayer, 17u},
{MaterialAttribute::NormalTexture, 3u}, {MaterialAttribute::NormalTexture, 3u},
{MaterialAttribute::NormalTextureScale, 0.5f}, {MaterialAttribute::NormalTextureScale, 0.5f},
{MaterialAttribute::NormalTextureSwizzle, MaterialTextureSwizzle::B}, {MaterialAttribute::NormalTextureSwizzle, MaterialTextureSwizzle::B},
{MaterialAttribute::NormalTextureMatrix, Matrix3::translation({0.0f, 0.5f})}, {MaterialAttribute::NormalTextureMatrix, Matrix3::translation({0.0f, 0.5f})},
{MaterialAttribute::NormalTextureCoordinates, 7u}, {MaterialAttribute::NormalTextureCoordinates, 7u},
}, {0, 11}}; {MaterialAttribute::NormalTextureLayer, 66u},
}, {0, 13}};
CORRADE_VERIFY(data.hasTextureTransformation()); CORRADE_VERIFY(data.hasTextureTransformation());
CORRADE_VERIFY(data.hasTextureCoordinates()); CORRADE_VERIFY(data.hasTextureCoordinates());
CORRADE_VERIFY(data.hasTextureLayer());
CORRADE_COMPARE(data.roughness(), 0.7f); CORRADE_COMPARE(data.roughness(), 0.7f);
CORRADE_COMPARE(data.roughnessTexture(), 2u); CORRADE_COMPARE(data.roughnessTexture(), 2u);
CORRADE_COMPARE(data.roughnessTextureSwizzle(), MaterialTextureSwizzle::A); CORRADE_COMPARE(data.roughnessTextureSwizzle(), MaterialTextureSwizzle::A);
CORRADE_COMPARE(data.roughnessTextureMatrix(), Matrix3::translation({2.0f, 1.5f})); CORRADE_COMPARE(data.roughnessTextureMatrix(), Matrix3::translation({2.0f, 1.5f}));
CORRADE_COMPARE(data.roughnessTextureCoordinates(), 6u); CORRADE_COMPARE(data.roughnessTextureCoordinates(), 6u);
CORRADE_COMPARE(data.roughnessTextureLayer(), 17u);
CORRADE_COMPARE(data.normalTexture(), 3u); CORRADE_COMPARE(data.normalTexture(), 3u);
CORRADE_COMPARE(data.normalTextureScale(), 0.5f); CORRADE_COMPARE(data.normalTextureScale(), 0.5f);
CORRADE_COMPARE(data.normalTextureSwizzle(), MaterialTextureSwizzle::B); CORRADE_COMPARE(data.normalTextureSwizzle(), MaterialTextureSwizzle::B);
CORRADE_COMPARE(data.normalTextureMatrix(), Matrix3::translation({0.0f, 0.5f})); CORRADE_COMPARE(data.normalTextureMatrix(), Matrix3::translation({0.0f, 0.5f}));
CORRADE_COMPARE(data.normalTextureCoordinates(), 7u); CORRADE_COMPARE(data.normalTextureCoordinates(), 7u);
CORRADE_COMPARE(data.normalTextureLayer(), 66u);
} }
void PbrClearCoatMaterialDataTest::texturedDefaults() { void PbrClearCoatMaterialDataTest::texturedDefaults() {
@ -147,16 +154,19 @@ void PbrClearCoatMaterialDataTest::texturedDefaults() {
CORRADE_VERIFY(!data.hasTextureTransformation()); CORRADE_VERIFY(!data.hasTextureTransformation());
CORRADE_VERIFY(!data.hasTextureCoordinates()); CORRADE_VERIFY(!data.hasTextureCoordinates());
CORRADE_VERIFY(!data.hasTextureLayer());
CORRADE_COMPARE(data.roughness(), 0.0f); CORRADE_COMPARE(data.roughness(), 0.0f);
CORRADE_COMPARE(data.roughnessTexture(), 2u); CORRADE_COMPARE(data.roughnessTexture(), 2u);
CORRADE_COMPARE(data.roughnessTextureSwizzle(), MaterialTextureSwizzle::R); CORRADE_COMPARE(data.roughnessTextureSwizzle(), MaterialTextureSwizzle::R);
CORRADE_COMPARE(data.roughnessTextureMatrix(), Matrix3{}); CORRADE_COMPARE(data.roughnessTextureMatrix(), Matrix3{});
CORRADE_COMPARE(data.roughnessTextureCoordinates(), 0u); CORRADE_COMPARE(data.roughnessTextureCoordinates(), 0u);
CORRADE_COMPARE(data.roughnessTextureLayer(), 0u);
CORRADE_COMPARE(data.normalTexture(), 3u); CORRADE_COMPARE(data.normalTexture(), 3u);
CORRADE_COMPARE(data.normalTextureScale(), 1.0f); CORRADE_COMPARE(data.normalTextureScale(), 1.0f);
CORRADE_COMPARE(data.normalTextureSwizzle(), MaterialTextureSwizzle::RGB); CORRADE_COMPARE(data.normalTextureSwizzle(), MaterialTextureSwizzle::RGB);
CORRADE_COMPARE(data.normalTextureMatrix(), Matrix3{}); CORRADE_COMPARE(data.normalTextureMatrix(), Matrix3{});
CORRADE_COMPARE(data.normalTextureCoordinates(), 0u); CORRADE_COMPARE(data.normalTextureCoordinates(), 0u);
CORRADE_COMPARE(data.normalTextureLayer(), 0u);
} }
void PbrClearCoatMaterialDataTest::texturedExplicitPackedLayerFactorRoughness() { void PbrClearCoatMaterialDataTest::texturedExplicitPackedLayerFactorRoughness() {
@ -176,6 +186,7 @@ void PbrClearCoatMaterialDataTest::texturedExplicitPackedLayerFactorRoughness()
CORRADE_COMPARE(data.roughnessTextureSwizzle(), MaterialTextureSwizzle::G); CORRADE_COMPARE(data.roughnessTextureSwizzle(), MaterialTextureSwizzle::G);
CORRADE_COMPARE(data.roughnessTextureMatrix(), Matrix3{}); CORRADE_COMPARE(data.roughnessTextureMatrix(), Matrix3{});
CORRADE_COMPARE(data.roughnessTextureCoordinates(), 0); CORRADE_COMPARE(data.roughnessTextureCoordinates(), 0);
CORRADE_COMPARE(data.roughnessTextureLayer(), 0);
/* Explicit parameters for everything, but all the same */ /* Explicit parameters for everything, but all the same */
} { } {
@ -185,19 +196,23 @@ void PbrClearCoatMaterialDataTest::texturedExplicitPackedLayerFactorRoughness()
{MaterialAttribute::LayerFactorTextureSwizzle, MaterialTextureSwizzle::R}, {MaterialAttribute::LayerFactorTextureSwizzle, MaterialTextureSwizzle::R},
{MaterialAttribute::LayerFactorTextureMatrix, Matrix3::scaling({0.5f, 0.5f})}, {MaterialAttribute::LayerFactorTextureMatrix, Matrix3::scaling({0.5f, 0.5f})},
{MaterialAttribute::LayerFactorTextureCoordinates, 3u}, {MaterialAttribute::LayerFactorTextureCoordinates, 3u},
{MaterialAttribute::LayerFactorTextureLayer, 17u},
{MaterialAttribute::RoughnessTexture, 2u}, {MaterialAttribute::RoughnessTexture, 2u},
{MaterialAttribute::RoughnessTextureSwizzle, MaterialTextureSwizzle::G}, {MaterialAttribute::RoughnessTextureSwizzle, MaterialTextureSwizzle::G},
{MaterialAttribute::RoughnessTextureMatrix, Matrix3::scaling({0.5f, 0.5f})}, {MaterialAttribute::RoughnessTextureMatrix, Matrix3::scaling({0.5f, 0.5f})},
{MaterialAttribute::RoughnessTextureCoordinates, 3u} {MaterialAttribute::RoughnessTextureCoordinates, 3u},
}, {0, 9}}; {MaterialAttribute::RoughnessTextureLayer, 17u}
}, {0, 11}};
CORRADE_VERIFY(data.hasLayerFactorRoughnessTexture()); CORRADE_VERIFY(data.hasLayerFactorRoughnessTexture());
CORRADE_COMPARE(data.layerFactorTexture(), 2); CORRADE_COMPARE(data.layerFactorTexture(), 2);
CORRADE_COMPARE(data.layerFactorTextureMatrix(), Matrix3::scaling({0.5f, 0.5f})); CORRADE_COMPARE(data.layerFactorTextureMatrix(), Matrix3::scaling({0.5f, 0.5f}));
CORRADE_COMPARE(data.layerFactorTextureCoordinates(), 3); CORRADE_COMPARE(data.layerFactorTextureCoordinates(), 3);
CORRADE_COMPARE(data.layerFactorTextureLayer(), 17);
CORRADE_COMPARE(data.roughnessTexture(), 2); CORRADE_COMPARE(data.roughnessTexture(), 2);
CORRADE_COMPARE(data.roughnessTextureSwizzle(), MaterialTextureSwizzle::G); CORRADE_COMPARE(data.roughnessTextureSwizzle(), MaterialTextureSwizzle::G);
CORRADE_COMPARE(data.roughnessTextureMatrix(), Matrix3::scaling({0.5f, 0.5f})); CORRADE_COMPARE(data.roughnessTextureMatrix(), Matrix3::scaling({0.5f, 0.5f}));
CORRADE_COMPARE(data.roughnessTextureCoordinates(), 3); CORRADE_COMPARE(data.roughnessTextureCoordinates(), 3);
CORRADE_COMPARE(data.roughnessTextureLayer(), 17);
/* Different texture ID */ /* Different texture ID */
} { } {
@ -251,47 +266,68 @@ void PbrClearCoatMaterialDataTest::texturedExplicitPackedLayerFactorRoughness()
{MaterialAttribute::RoughnessTextureCoordinates, 1u} {MaterialAttribute::RoughnessTextureCoordinates, 1u}
}, {0, 5}}; }, {0, 5}};
CORRADE_VERIFY(!data.hasLayerFactorRoughnessTexture()); 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{{}, { PbrClearCoatMaterialData data{{}, {
{MaterialLayer::ClearCoat}, {MaterialLayer::ClearCoat},
{MaterialAttribute::RoughnessTexture, 2u}, {MaterialAttribute::RoughnessTexture, 2u},
{MaterialAttribute::NormalTexture, 3u}, {MaterialAttribute::NormalTexture, 3u},
{MaterialAttribute::TextureMatrix, Matrix3::translation({0.0f, 0.5f})}, {MaterialAttribute::TextureMatrix, Matrix3::translation({0.0f, 0.5f})},
{MaterialAttribute::TextureCoordinates, 7u}, {MaterialAttribute::TextureCoordinates, 7u},
}, {0, 5}}; {MaterialAttribute::TextureLayer, 17u},
}, {0, 6}};
CORRADE_VERIFY(data.hasTextureTransformation()); CORRADE_VERIFY(data.hasTextureTransformation());
CORRADE_VERIFY(data.hasTextureCoordinates()); CORRADE_VERIFY(data.hasTextureCoordinates());
CORRADE_VERIFY(data.hasTextureLayer());
CORRADE_COMPARE(data.roughnessTextureMatrix(), Matrix3::translation({0.0f, 0.5f})); CORRADE_COMPARE(data.roughnessTextureMatrix(), Matrix3::translation({0.0f, 0.5f}));
CORRADE_COMPARE(data.roughnessTextureCoordinates(), 7u); CORRADE_COMPARE(data.roughnessTextureCoordinates(), 7u);
CORRADE_COMPARE(data.roughnessTextureLayer(), 17u);
CORRADE_COMPARE(data.normalTextureMatrix(), Matrix3::translation({0.0f, 0.5f})); CORRADE_COMPARE(data.normalTextureMatrix(), Matrix3::translation({0.0f, 0.5f}));
CORRADE_COMPARE(data.normalTextureCoordinates(), 7u); CORRADE_COMPARE(data.normalTextureCoordinates(), 7u);
CORRADE_COMPARE(data.normalTextureLayer(), 17u);
} }
void PbrClearCoatMaterialDataTest::texturedBaseMaterialMatrixCoordinates() { void PbrClearCoatMaterialDataTest::texturedBaseMaterialMatrixCoordinatesLayer() {
PbrClearCoatMaterialData data{{}, { PbrClearCoatMaterialData data{{}, {
{MaterialAttribute::TextureMatrix, Matrix3::translation({0.0f, 0.5f})}, {MaterialAttribute::TextureMatrix, Matrix3::translation({0.0f, 0.5f})},
{MaterialAttribute::TextureCoordinates, 7u}, {MaterialAttribute::TextureCoordinates, 7u},
{MaterialAttribute::TextureLayer, 17u},
{MaterialLayer::ClearCoat}, {MaterialLayer::ClearCoat},
{MaterialAttribute::RoughnessTexture, 2u}, {MaterialAttribute::RoughnessTexture, 2u},
{MaterialAttribute::NormalTexture, 3u}, {MaterialAttribute::NormalTexture, 3u},
}, {2, 5}}; }, {3, 6}};
CORRADE_VERIFY(data.hasTextureTransformation()); CORRADE_VERIFY(data.hasTextureTransformation());
CORRADE_VERIFY(data.hasTextureCoordinates()); CORRADE_VERIFY(data.hasTextureCoordinates());
CORRADE_VERIFY(data.hasTextureLayer());
CORRADE_COMPARE(data.roughnessTextureMatrix(), Matrix3::translation({0.0f, 0.5f})); CORRADE_COMPARE(data.roughnessTextureMatrix(), Matrix3::translation({0.0f, 0.5f}));
CORRADE_COMPARE(data.roughnessTextureCoordinates(), 7u); CORRADE_COMPARE(data.roughnessTextureCoordinates(), 7u);
CORRADE_COMPARE(data.roughnessTextureLayer(), 17u);
CORRADE_COMPARE(data.normalTextureMatrix(), Matrix3::translation({0.0f, 0.5f})); CORRADE_COMPARE(data.normalTextureMatrix(), Matrix3::translation({0.0f, 0.5f}));
CORRADE_COMPARE(data.normalTextureCoordinates(), 7u); CORRADE_COMPARE(data.normalTextureCoordinates(), 7u);
CORRADE_COMPARE(data.normalTextureLayer(), 17u);
CORRADE_VERIFY(data.hasCommonTextureTransformation()); CORRADE_VERIFY(data.hasCommonTextureTransformation());
CORRADE_VERIFY(data.hasCommonTextureCoordinates()); CORRADE_VERIFY(data.hasCommonTextureCoordinates());
CORRADE_VERIFY(data.hasCommonTextureLayer());
CORRADE_COMPARE(data.commonTextureMatrix(), Matrix3::translation({0.0f, 0.5f})); CORRADE_COMPARE(data.commonTextureMatrix(), Matrix3::translation({0.0f, 0.5f}));
CORRADE_COMPARE(data.commonTextureCoordinates(), 7); CORRADE_COMPARE(data.commonTextureCoordinates(), 7);
CORRADE_COMPARE(data.commonTextureLayer(), 17);
} }
void PbrClearCoatMaterialDataTest::invalidTextures() { void PbrClearCoatMaterialDataTest::invalidTextures() {
@ -309,55 +345,67 @@ void PbrClearCoatMaterialDataTest::invalidTextures() {
data.roughnessTextureSwizzle(); data.roughnessTextureSwizzle();
data.roughnessTextureMatrix(); data.roughnessTextureMatrix();
data.roughnessTextureCoordinates(); data.roughnessTextureCoordinates();
data.roughnessTextureLayer();
data.normalTexture(); data.normalTexture();
data.normalTextureScale(); data.normalTextureScale();
data.normalTextureSwizzle(); data.normalTextureSwizzle();
data.normalTextureMatrix(); data.normalTextureMatrix();
data.normalTextureCoordinates(); data.normalTextureCoordinates();
data.normalTextureLayer();
CORRADE_COMPARE(out.str(), CORRADE_COMPARE(out.str(),
"Trade::MaterialData::attribute(): attribute RoughnessTexture not found in layer ClearCoat\n" "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::roughnessTextureSwizzle(): the layer doesn't have a roughness texture\n"
"Trade::PbrClearCoatMaterialData::roughnessTextureMatrix(): 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::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::MaterialData::attribute(): attribute NormalTexture not found in layer ClearCoat\n"
"Trade::PbrClearCoatMaterialData::normalTextureScale(): the layer doesn't have a normal texture\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::normalTextureSwizzle(): the layer doesn't have a normal texture\n"
"Trade::PbrClearCoatMaterialData::normalTextureMatrix(): 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{{}, { PbrClearCoatMaterialData a{{}, {
{MaterialLayer::ClearCoat}, {MaterialLayer::ClearCoat},
}, {0, 1}}; }, {0, 1}};
CORRADE_VERIFY(a.hasCommonTextureTransformation()); CORRADE_VERIFY(a.hasCommonTextureTransformation());
CORRADE_VERIFY(a.hasCommonTextureCoordinates()); CORRADE_VERIFY(a.hasCommonTextureCoordinates());
CORRADE_VERIFY(a.hasCommonTextureLayer());
CORRADE_COMPARE(a.commonTextureMatrix(), Matrix3{}); CORRADE_COMPARE(a.commonTextureMatrix(), Matrix3{});
CORRADE_COMPARE(a.commonTextureCoordinates(), 0); CORRADE_COMPARE(a.commonTextureCoordinates(), 0);
CORRADE_COMPARE(a.commonTextureLayer(), 0);
PbrClearCoatMaterialData b{{}, { PbrClearCoatMaterialData b{{}, {
{MaterialAttribute::TextureMatrix, Matrix3::scaling({0.5f, 0.5f})}, {MaterialAttribute::TextureMatrix, Matrix3::scaling({0.5f, 0.5f})},
{MaterialAttribute::TextureCoordinates, 7u}, {MaterialAttribute::TextureCoordinates, 7u},
{MaterialAttribute::TextureLayer, 17u},
{MaterialLayer::ClearCoat} {MaterialLayer::ClearCoat}
}, {2, 3}}; }, {3, 4}};
CORRADE_VERIFY(b.hasCommonTextureTransformation()); CORRADE_VERIFY(b.hasCommonTextureTransformation());
CORRADE_VERIFY(b.hasCommonTextureCoordinates()); CORRADE_VERIFY(b.hasCommonTextureCoordinates());
CORRADE_VERIFY(b.hasCommonTextureLayer());
CORRADE_COMPARE(b.commonTextureMatrix(), Matrix3::scaling({0.5f, 0.5f})); CORRADE_COMPARE(b.commonTextureMatrix(), Matrix3::scaling({0.5f, 0.5f}));
CORRADE_COMPARE(b.commonTextureCoordinates(), 7); CORRADE_COMPARE(b.commonTextureCoordinates(), 7);
CORRADE_COMPARE(b.commonTextureLayer(), 17);
PbrClearCoatMaterialData c{{}, { PbrClearCoatMaterialData c{{}, {
{MaterialLayer::ClearCoat}, {MaterialLayer::ClearCoat},
{MaterialAttribute::TextureMatrix, Matrix3::scaling({0.5f, 0.5f})}, {MaterialAttribute::TextureMatrix, Matrix3::scaling({0.5f, 0.5f})},
{MaterialAttribute::TextureCoordinates, 7u}, {MaterialAttribute::TextureCoordinates, 7u},
}, {0, 3}}; {MaterialAttribute::TextureLayer, 17u},
}, {0, 4}};
CORRADE_VERIFY(c.hasCommonTextureTransformation()); CORRADE_VERIFY(c.hasCommonTextureTransformation());
CORRADE_VERIFY(c.hasCommonTextureCoordinates()); CORRADE_VERIFY(c.hasCommonTextureCoordinates());
CORRADE_VERIFY(c.hasCommonTextureLayer());
CORRADE_COMPARE(c.commonTextureMatrix(), Matrix3::scaling({0.5f, 0.5f})); CORRADE_COMPARE(c.commonTextureMatrix(), Matrix3::scaling({0.5f, 0.5f}));
CORRADE_COMPARE(c.commonTextureCoordinates(), 7); CORRADE_COMPARE(c.commonTextureCoordinates(), 7);
CORRADE_COMPARE(c.commonTextureLayer(), 17);
} }
void PbrClearCoatMaterialDataTest::commonTransformationCoordinatesOneTexture() { void PbrClearCoatMaterialDataTest::commonTransformationCoordinatesLayerOneTexture() {
Containers::StringView textureName = PbrClearCoatTextureData[testCaseInstanceId()]; Containers::StringView textureName = PbrClearCoatTextureData[testCaseInstanceId()];
setTestCaseDescription(textureName); setTestCaseDescription(textureName);
@ -365,20 +413,24 @@ void PbrClearCoatMaterialDataTest::commonTransformationCoordinatesOneTexture() {
/* These shouldn't affect the below */ /* These shouldn't affect the below */
{MaterialAttribute::TextureMatrix, Matrix3::translation({0.5f, 0.0f})}, {MaterialAttribute::TextureMatrix, Matrix3::translation({0.5f, 0.0f})},
{MaterialAttribute::TextureCoordinates, 3u}, {MaterialAttribute::TextureCoordinates, 3u},
{MaterialAttribute::TextureLayer, 22u},
{MaterialLayer::ClearCoat}, {MaterialLayer::ClearCoat},
{textureName, 5u}, {textureName, 5u},
{textureName + "Matrix", Matrix3::scaling({0.5f, 1.0f})}, {textureName + "Matrix", Matrix3::scaling({0.5f, 1.0f})},
{textureName + "Coordinates", 17u}, {textureName + "Coordinates", 17u},
}, {2, 6}}; {textureName + "Layer", 66u},
}, {3, 8}};
CORRADE_VERIFY(data.hasCommonTextureTransformation()); CORRADE_VERIFY(data.hasCommonTextureTransformation());
CORRADE_COMPARE(data.commonTextureMatrix(), Matrix3::scaling({0.5f, 1.0f})); CORRADE_COMPARE(data.commonTextureMatrix(), Matrix3::scaling({0.5f, 1.0f}));
CORRADE_VERIFY(data.hasCommonTextureCoordinates()); CORRADE_VERIFY(data.hasCommonTextureCoordinates());
CORRADE_COMPARE(data.commonTextureCoordinates(), 17u); 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()]; Containers::StringView textureName = PbrClearCoatTextureData[testCaseInstanceId()];
setTestCaseDescription(textureName); setTestCaseDescription(textureName);
@ -387,20 +439,23 @@ void PbrClearCoatMaterialDataTest::commonTransformationCoordinatesOneDifferentTe
check */ check */
{MaterialAttribute::TextureMatrix, Matrix3::translation({0.5f, 0.0f})}, {MaterialAttribute::TextureMatrix, Matrix3::translation({0.5f, 0.0f})},
{MaterialAttribute::TextureCoordinates, 3u}, {MaterialAttribute::TextureCoordinates, 3u},
{MaterialAttribute::TextureLayer, 22u},
{MaterialLayer::ClearCoat}, {MaterialLayer::ClearCoat},
{MaterialAttribute::LayerFactorTexture, 2u}, {MaterialAttribute::LayerFactorTexture, 2u},
{MaterialAttribute::RoughnessTexture, 3u}, {MaterialAttribute::RoughnessTexture, 3u},
{MaterialAttribute::NormalTexture, 5u}, {MaterialAttribute::NormalTexture, 5u},
{textureName + "Matrix", Matrix3::scaling({0.5f, 1.0f})}, {textureName + "Matrix", Matrix3::scaling({0.5f, 1.0f})},
{textureName + "Coordinates", 17u} {textureName + "Coordinates", 17u},
}, {2, 8}}; {textureName + "Layer", 66u},
}, {3, 10}};
CORRADE_VERIFY(!data.hasCommonTextureTransformation()); CORRADE_VERIFY(!data.hasCommonTextureTransformation());
CORRADE_VERIFY(!data.hasCommonTextureCoordinates()); CORRADE_VERIFY(!data.hasCommonTextureCoordinates());
CORRADE_VERIFY(!data.hasCommonTextureLayer());
} }
void PbrClearCoatMaterialDataTest::commonCoordinatesImplicit() { void PbrClearCoatMaterialDataTest::commonCoordinatesLayerImplicit() {
Containers::StringView textureName = PbrClearCoatTextureData[testCaseInstanceId()]; Containers::StringView textureName = PbrClearCoatTextureData[testCaseInstanceId()];
setTestCaseDescription(textureName); setTestCaseDescription(textureName);
@ -410,16 +465,20 @@ void PbrClearCoatMaterialDataTest::commonCoordinatesImplicit() {
PbrClearCoatMaterialData data{{}, { PbrClearCoatMaterialData data{{}, {
{MaterialLayer::ClearCoat}, {MaterialLayer::ClearCoat},
{textureName, 5u}, {textureName, 5u},
{textureName + "Coordinates", 0u} {textureName + "Coordinates", 0u},
{textureName + "Layer", 0u},
}, {0, 3}}; }, {0, 3}};
/* Zero is treated same as if there would be no attribute at all */ /* Zero is treated same as if there would be no attribute at all */
CORRADE_VERIFY(!data.hasTextureCoordinates()); CORRADE_VERIFY(!data.hasTextureCoordinates());
CORRADE_VERIFY(!data.hasTextureLayer());
CORRADE_VERIFY(data.hasCommonTextureCoordinates()); CORRADE_VERIFY(data.hasCommonTextureCoordinates());
CORRADE_VERIFY(data.hasCommonTextureLayer());
CORRADE_COMPARE(data.commonTextureCoordinates(), 0u); CORRADE_COMPARE(data.commonTextureCoordinates(), 0u);
CORRADE_COMPARE(data.commonTextureLayer(), 0u);
} }
void PbrClearCoatMaterialDataTest::noCommonTransformationCoordinates() { void PbrClearCoatMaterialDataTest::noCommonTransformationCoordinatesLayer() {
#ifdef CORRADE_NO_ASSERT #ifdef CORRADE_NO_ASSERT
CORRADE_SKIP("CORRADE_NO_ASSERT defined, can't test assertions"); CORRADE_SKIP("CORRADE_NO_ASSERT defined, can't test assertions");
#endif #endif
@ -431,9 +490,10 @@ void PbrClearCoatMaterialDataTest::noCommonTransformationCoordinates() {
{MaterialAttribute::LayerFactorTextureCoordinates, 3u}, {MaterialAttribute::LayerFactorTextureCoordinates, 3u},
{MaterialAttribute::RoughnessTexture, 4u}, {MaterialAttribute::RoughnessTexture, 4u},
{MaterialAttribute::RoughnessTextureMatrix, Matrix3::scaling({0.5f, 1.0f})}, {MaterialAttribute::RoughnessTextureMatrix, Matrix3::scaling({0.5f, 1.0f})},
{MaterialAttribute::RoughnessTextureLayer, 22u},
{MaterialAttribute::NormalTexture, 5u}, {MaterialAttribute::NormalTexture, 5u},
{MaterialAttribute::NormalTextureCoordinates, 17u} {MaterialAttribute::NormalTextureCoordinates, 17u}
}, {0, 8}}; }, {0, 9}};
CORRADE_VERIFY(!data.hasCommonTextureTransformation()); CORRADE_VERIFY(!data.hasCommonTextureTransformation());
CORRADE_VERIFY(!data.hasCommonTextureCoordinates()); CORRADE_VERIFY(!data.hasCommonTextureCoordinates());
@ -442,9 +502,11 @@ void PbrClearCoatMaterialDataTest::noCommonTransformationCoordinates() {
Error redirectError{&out}; Error redirectError{&out};
data.commonTextureMatrix(); data.commonTextureMatrix();
data.commonTextureCoordinates(); data.commonTextureCoordinates();
data.commonTextureLayer();
CORRADE_COMPARE(out.str(), CORRADE_COMPARE(out.str(),
"Trade::PbrClearCoatMaterialData::commonTextureMatrix(): the layer doesn't have a common texture coordinate transformation\n" "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");
} }
}}}} }}}}

188
src/Magnum/Trade/Test/PbrMetallicRoughnessMaterialDataTest.cpp

@ -47,13 +47,13 @@ class PbrMetallicRoughnessMaterialDataTest: public TestSuite::Tester {
void texturedExplicitPackedRoughnessMetallicOcclusion(); void texturedExplicitPackedRoughnessMetallicOcclusion();
void texturedExplicitPackedOcclusionRoughnessMetallic(); void texturedExplicitPackedOcclusionRoughnessMetallic();
void texturedExplicitPackedNormalRoughnessMetallic(); void texturedExplicitPackedNormalRoughnessMetallic();
void texturedSingleMatrixCoordinates(); void texturedSingleMatrixCoordinatesLayer();
void invalidTextures(); void invalidTextures();
void commonTransformationCoordinatesNoTextures(); void commonTransformationCoordinatesLayerNoTextures();
void commonTransformationCoordinatesOneTexture(); void commonTransformationCoordinatesLayerOneTexture();
void commonTransformationCoordinatesOneDifferentTexture(); void commonTransformationCoordinatesLayerOneDifferentTexture();
void commonCoordinatesImplicit(); void commonCoordinatesLayerImplicit();
void noCommonTransformationCoordinates(); void noCommonTransformationCoordinatesLayer();
}; };
const Containers::StringView PbrMetallicRoughnessTextureData[] { const Containers::StringView PbrMetallicRoughnessTextureData[] {
@ -75,17 +75,17 @@ PbrMetallicRoughnessMaterialDataTest::PbrMetallicRoughnessMaterialDataTest() {
&PbrMetallicRoughnessMaterialDataTest::texturedExplicitPackedRoughnessMetallicOcclusion, &PbrMetallicRoughnessMaterialDataTest::texturedExplicitPackedRoughnessMetallicOcclusion,
&PbrMetallicRoughnessMaterialDataTest::texturedExplicitPackedOcclusionRoughnessMetallic, &PbrMetallicRoughnessMaterialDataTest::texturedExplicitPackedOcclusionRoughnessMetallic,
&PbrMetallicRoughnessMaterialDataTest::texturedExplicitPackedNormalRoughnessMetallic, &PbrMetallicRoughnessMaterialDataTest::texturedExplicitPackedNormalRoughnessMetallic,
&PbrMetallicRoughnessMaterialDataTest::texturedSingleMatrixCoordinates, &PbrMetallicRoughnessMaterialDataTest::texturedSingleMatrixCoordinatesLayer,
&PbrMetallicRoughnessMaterialDataTest::invalidTextures, &PbrMetallicRoughnessMaterialDataTest::invalidTextures,
&PbrMetallicRoughnessMaterialDataTest::commonTransformationCoordinatesNoTextures}); &PbrMetallicRoughnessMaterialDataTest::commonTransformationCoordinatesLayerNoTextures});
addInstancedTests({ addInstancedTests({
&PbrMetallicRoughnessMaterialDataTest::commonTransformationCoordinatesOneTexture, &PbrMetallicRoughnessMaterialDataTest::commonTransformationCoordinatesLayerOneTexture,
&PbrMetallicRoughnessMaterialDataTest::commonTransformationCoordinatesOneDifferentTexture, &PbrMetallicRoughnessMaterialDataTest::commonTransformationCoordinatesLayerOneDifferentTexture,
&PbrMetallicRoughnessMaterialDataTest::commonCoordinatesImplicit}, &PbrMetallicRoughnessMaterialDataTest::commonCoordinatesLayerImplicit},
Containers::arraySize(PbrMetallicRoughnessTextureData)); Containers::arraySize(PbrMetallicRoughnessTextureData));
addTests({&PbrMetallicRoughnessMaterialDataTest::noCommonTransformationCoordinates}); addTests({&PbrMetallicRoughnessMaterialDataTest::noCommonTransformationCoordinatesLayer});
} }
using namespace Math::Literals; using namespace Math::Literals;
@ -109,6 +109,7 @@ void PbrMetallicRoughnessMaterialDataTest::basics() {
CORRADE_VERIFY(!data.hasNormalRoughnessMetallicTexture()); CORRADE_VERIFY(!data.hasNormalRoughnessMetallicTexture());
CORRADE_VERIFY(!data.hasTextureTransformation()); CORRADE_VERIFY(!data.hasTextureTransformation());
CORRADE_VERIFY(!data.hasTextureCoordinates()); CORRADE_VERIFY(!data.hasTextureCoordinates());
CORRADE_VERIFY(!data.hasTextureLayer());
CORRADE_COMPARE(data.baseColor(), 0xccffbbff_rgbaf); CORRADE_COMPARE(data.baseColor(), 0xccffbbff_rgbaf);
CORRADE_COMPARE(data.metalness(), 0.5f); CORRADE_COMPARE(data.metalness(), 0.5f);
CORRADE_COMPARE(data.roughness(), 0.79f); CORRADE_COMPARE(data.roughness(), 0.79f);
@ -130,6 +131,7 @@ void PbrMetallicRoughnessMaterialDataTest::defaults() {
CORRADE_VERIFY(!data.hasNormalRoughnessMetallicTexture()); CORRADE_VERIFY(!data.hasNormalRoughnessMetallicTexture());
CORRADE_VERIFY(!data.hasTextureTransformation()); CORRADE_VERIFY(!data.hasTextureTransformation());
CORRADE_VERIFY(!data.hasTextureCoordinates()); CORRADE_VERIFY(!data.hasTextureCoordinates());
CORRADE_VERIFY(!data.hasTextureLayer());
CORRADE_COMPARE(data.baseColor(), 0xffffffff_rgbaf); CORRADE_COMPARE(data.baseColor(), 0xffffffff_rgbaf);
CORRADE_COMPARE(data.metalness(), 1.0f); CORRADE_COMPARE(data.metalness(), 1.0f);
CORRADE_COMPARE(data.roughness(), 1.0f); CORRADE_COMPARE(data.roughness(), 1.0f);
@ -142,30 +144,36 @@ void PbrMetallicRoughnessMaterialDataTest::textured() {
{MaterialAttribute::BaseColorTexture, 0u}, {MaterialAttribute::BaseColorTexture, 0u},
{MaterialAttribute::BaseColorTextureMatrix, Matrix3::scaling({0.5f, 1.0f})}, {MaterialAttribute::BaseColorTextureMatrix, Matrix3::scaling({0.5f, 1.0f})},
{MaterialAttribute::BaseColorTextureCoordinates, 2u}, {MaterialAttribute::BaseColorTextureCoordinates, 2u},
{MaterialAttribute::BaseColorTextureLayer, 8u},
{MaterialAttribute::Metalness, 0.5f}, {MaterialAttribute::Metalness, 0.5f},
{MaterialAttribute::MetalnessTexture, 1u}, {MaterialAttribute::MetalnessTexture, 1u},
{MaterialAttribute::MetalnessTextureSwizzle, MaterialTextureSwizzle::G}, {MaterialAttribute::MetalnessTextureSwizzle, MaterialTextureSwizzle::G},
{MaterialAttribute::MetalnessTextureMatrix, Matrix3::scaling({0.5f, 0.5f})}, {MaterialAttribute::MetalnessTextureMatrix, Matrix3::scaling({0.5f, 0.5f})},
{MaterialAttribute::MetalnessTextureCoordinates, 3u}, {MaterialAttribute::MetalnessTextureCoordinates, 3u},
{MaterialAttribute::MetalnessTextureLayer, 9u},
{MaterialAttribute::Roughness, 0.79f}, {MaterialAttribute::Roughness, 0.79f},
{MaterialAttribute::RoughnessTexture, 2u}, {MaterialAttribute::RoughnessTexture, 2u},
{MaterialAttribute::RoughnessTextureSwizzle, MaterialTextureSwizzle::A}, {MaterialAttribute::RoughnessTextureSwizzle, MaterialTextureSwizzle::A},
{MaterialAttribute::RoughnessTextureMatrix, Matrix3::scaling({1.0f, 1.0f})}, {MaterialAttribute::RoughnessTextureMatrix, Matrix3::scaling({1.0f, 1.0f})},
{MaterialAttribute::RoughnessTextureCoordinates, 4u}, {MaterialAttribute::RoughnessTextureCoordinates, 4u},
{MaterialAttribute::RoughnessTextureLayer, 10u},
{MaterialAttribute::NormalTexture, 3u}, {MaterialAttribute::NormalTexture, 3u},
{MaterialAttribute::NormalTextureScale, 0.35f}, {MaterialAttribute::NormalTextureScale, 0.35f},
{MaterialAttribute::NormalTextureSwizzle, MaterialTextureSwizzle::BA}, {MaterialAttribute::NormalTextureSwizzle, MaterialTextureSwizzle::BA},
{MaterialAttribute::NormalTextureMatrix, Matrix3::scaling({1.0f, 0.5f})}, {MaterialAttribute::NormalTextureMatrix, Matrix3::scaling({1.0f, 0.5f})},
{MaterialAttribute::NormalTextureCoordinates, 5u}, {MaterialAttribute::NormalTextureCoordinates, 5u},
{MaterialAttribute::NormalTextureLayer, 11u},
{MaterialAttribute::OcclusionTexture, 4u}, {MaterialAttribute::OcclusionTexture, 4u},
{MaterialAttribute::OcclusionTextureStrength, 0.66f}, {MaterialAttribute::OcclusionTextureStrength, 0.66f},
{MaterialAttribute::OcclusionTextureSwizzle, MaterialTextureSwizzle::B}, {MaterialAttribute::OcclusionTextureSwizzle, MaterialTextureSwizzle::B},
{MaterialAttribute::OcclusionTextureMatrix, Matrix3::scaling({1.0f, 0.75f})}, {MaterialAttribute::OcclusionTextureMatrix, Matrix3::scaling({1.0f, 0.75f})},
{MaterialAttribute::OcclusionTextureCoordinates, 6u}, {MaterialAttribute::OcclusionTextureCoordinates, 6u},
{MaterialAttribute::OcclusionTextureLayer, 12u},
{MaterialAttribute::EmissiveColor, 0x111111_rgbf}, {MaterialAttribute::EmissiveColor, 0x111111_rgbf},
{MaterialAttribute::EmissiveTexture, 5u}, {MaterialAttribute::EmissiveTexture, 5u},
{MaterialAttribute::EmissiveTextureMatrix, Matrix3::scaling({0.75f, 0.5f})}, {MaterialAttribute::EmissiveTextureMatrix, Matrix3::scaling({0.75f, 0.5f})},
{MaterialAttribute::EmissiveTextureCoordinates, 7u} {MaterialAttribute::EmissiveTextureCoordinates, 7u},
{MaterialAttribute::EmissiveTextureLayer, 13u}
}}; }};
CORRADE_VERIFY(data.hasMetalnessTexture()); CORRADE_VERIFY(data.hasMetalnessTexture());
@ -176,34 +184,41 @@ void PbrMetallicRoughnessMaterialDataTest::textured() {
CORRADE_VERIFY(!data.hasNormalRoughnessMetallicTexture()); CORRADE_VERIFY(!data.hasNormalRoughnessMetallicTexture());
CORRADE_VERIFY(data.hasTextureTransformation()); CORRADE_VERIFY(data.hasTextureTransformation());
CORRADE_VERIFY(data.hasTextureCoordinates()); CORRADE_VERIFY(data.hasTextureCoordinates());
CORRADE_VERIFY(data.hasTextureLayer());
CORRADE_COMPARE(data.baseColor(), 0xccffbbff_rgbaf); CORRADE_COMPARE(data.baseColor(), 0xccffbbff_rgbaf);
CORRADE_COMPARE(data.baseColorTexture(), 0); CORRADE_COMPARE(data.baseColorTexture(), 0);
CORRADE_COMPARE(data.baseColorTextureMatrix(), Matrix3::scaling({0.5f, 1.0f})); CORRADE_COMPARE(data.baseColorTextureMatrix(), Matrix3::scaling({0.5f, 1.0f}));
CORRADE_COMPARE(data.baseColorTextureCoordinates(), 2); CORRADE_COMPARE(data.baseColorTextureCoordinates(), 2);
CORRADE_COMPARE(data.baseColorTextureLayer(), 8);
CORRADE_COMPARE(data.metalness(), 0.5f); CORRADE_COMPARE(data.metalness(), 0.5f);
CORRADE_COMPARE(data.metalnessTexture(), 1); CORRADE_COMPARE(data.metalnessTexture(), 1);
CORRADE_COMPARE(data.metalnessTextureSwizzle(), MaterialTextureSwizzle::G); CORRADE_COMPARE(data.metalnessTextureSwizzle(), MaterialTextureSwizzle::G);
CORRADE_COMPARE(data.metalnessTextureMatrix(), Matrix3::scaling({0.5f, 0.5f})); CORRADE_COMPARE(data.metalnessTextureMatrix(), Matrix3::scaling({0.5f, 0.5f}));
CORRADE_COMPARE(data.metalnessTextureCoordinates(), 3); CORRADE_COMPARE(data.metalnessTextureCoordinates(), 3);
CORRADE_COMPARE(data.metalnessTextureLayer(), 9);
CORRADE_COMPARE(data.roughness(), 0.79f); CORRADE_COMPARE(data.roughness(), 0.79f);
CORRADE_COMPARE(data.roughnessTexture(), 2); CORRADE_COMPARE(data.roughnessTexture(), 2);
CORRADE_COMPARE(data.roughnessTextureSwizzle(), MaterialTextureSwizzle::A); CORRADE_COMPARE(data.roughnessTextureSwizzle(), MaterialTextureSwizzle::A);
CORRADE_COMPARE(data.roughnessTextureMatrix(), Matrix3::scaling({1.0f, 1.0f})); CORRADE_COMPARE(data.roughnessTextureMatrix(), Matrix3::scaling({1.0f, 1.0f}));
CORRADE_COMPARE(data.roughnessTextureCoordinates(), 4); CORRADE_COMPARE(data.roughnessTextureCoordinates(), 4);
CORRADE_COMPARE(data.roughnessTextureLayer(), 10);
CORRADE_COMPARE(data.normalTexture(), 3); CORRADE_COMPARE(data.normalTexture(), 3);
CORRADE_COMPARE(data.normalTextureScale(), 0.35f); CORRADE_COMPARE(data.normalTextureScale(), 0.35f);
CORRADE_COMPARE(data.normalTextureSwizzle(), MaterialTextureSwizzle::BA); CORRADE_COMPARE(data.normalTextureSwizzle(), MaterialTextureSwizzle::BA);
CORRADE_COMPARE(data.normalTextureMatrix(), Matrix3::scaling({1.0f, 0.5f})); CORRADE_COMPARE(data.normalTextureMatrix(), Matrix3::scaling({1.0f, 0.5f}));
CORRADE_COMPARE(data.normalTextureCoordinates(), 5); CORRADE_COMPARE(data.normalTextureCoordinates(), 5);
CORRADE_COMPARE(data.normalTextureLayer(), 11);
CORRADE_COMPARE(data.occlusionTexture(), 4); CORRADE_COMPARE(data.occlusionTexture(), 4);
CORRADE_COMPARE(data.occlusionTextureStrength(), 0.66f); CORRADE_COMPARE(data.occlusionTextureStrength(), 0.66f);
CORRADE_COMPARE(data.occlusionTextureMatrix(), Matrix3::scaling({1.0f, 0.75f})); CORRADE_COMPARE(data.occlusionTextureMatrix(), Matrix3::scaling({1.0f, 0.75f}));
CORRADE_COMPARE(data.occlusionTextureSwizzle(), MaterialTextureSwizzle::B); CORRADE_COMPARE(data.occlusionTextureSwizzle(), MaterialTextureSwizzle::B);
CORRADE_COMPARE(data.occlusionTextureCoordinates(), 6); CORRADE_COMPARE(data.occlusionTextureCoordinates(), 6);
CORRADE_COMPARE(data.occlusionTextureLayer(), 12);
CORRADE_COMPARE(data.emissiveColor(), 0x111111_rgbf); CORRADE_COMPARE(data.emissiveColor(), 0x111111_rgbf);
CORRADE_COMPARE(data.emissiveTextureMatrix(), Matrix3::scaling({0.75f, 0.5f})); CORRADE_COMPARE(data.emissiveTextureMatrix(), Matrix3::scaling({0.75f, 0.5f}));
CORRADE_COMPARE(data.emissiveTexture(), 5); CORRADE_COMPARE(data.emissiveTexture(), 5);
CORRADE_COMPARE(data.emissiveTextureCoordinates(), 7); CORRADE_COMPARE(data.emissiveTextureCoordinates(), 7);
CORRADE_COMPARE(data.emissiveTextureLayer(), 13);
} }
void PbrMetallicRoughnessMaterialDataTest::texturedDefaults() { void PbrMetallicRoughnessMaterialDataTest::texturedDefaults() {
@ -224,37 +239,44 @@ void PbrMetallicRoughnessMaterialDataTest::texturedDefaults() {
CORRADE_VERIFY(!data.hasNormalRoughnessMetallicTexture()); CORRADE_VERIFY(!data.hasNormalRoughnessMetallicTexture());
CORRADE_VERIFY(!data.hasTextureTransformation()); CORRADE_VERIFY(!data.hasTextureTransformation());
CORRADE_VERIFY(!data.hasTextureCoordinates()); CORRADE_VERIFY(!data.hasTextureCoordinates());
CORRADE_VERIFY(!data.hasTextureLayer());
CORRADE_COMPARE(data.baseColor(), 0xffffffff_rgbaf); CORRADE_COMPARE(data.baseColor(), 0xffffffff_rgbaf);
CORRADE_COMPARE(data.baseColorTexture(), 1); CORRADE_COMPARE(data.baseColorTexture(), 1);
CORRADE_COMPARE(data.baseColorTextureMatrix(), Matrix3{}); CORRADE_COMPARE(data.baseColorTextureMatrix(), Matrix3{});
CORRADE_COMPARE(data.baseColorTextureCoordinates(), 0); CORRADE_COMPARE(data.baseColorTextureCoordinates(), 0);
CORRADE_COMPARE(data.baseColorTextureLayer(), 0);
CORRADE_COMPARE(data.metalness(), 1.0f); CORRADE_COMPARE(data.metalness(), 1.0f);
CORRADE_COMPARE(data.metalnessTexture(), 2); CORRADE_COMPARE(data.metalnessTexture(), 2);
CORRADE_COMPARE(data.metalnessTextureSwizzle(), MaterialTextureSwizzle::R); CORRADE_COMPARE(data.metalnessTextureSwizzle(), MaterialTextureSwizzle::R);
CORRADE_COMPARE(data.metalnessTextureMatrix(), Matrix3{}); CORRADE_COMPARE(data.metalnessTextureMatrix(), Matrix3{});
CORRADE_COMPARE(data.metalnessTextureCoordinates(), 0); CORRADE_COMPARE(data.metalnessTextureCoordinates(), 0);
CORRADE_COMPARE(data.metalnessTextureLayer(), 0);
CORRADE_COMPARE(data.roughness(), 1.0f); CORRADE_COMPARE(data.roughness(), 1.0f);
CORRADE_COMPARE(data.roughnessTexture(), 3); CORRADE_COMPARE(data.roughnessTexture(), 3);
CORRADE_COMPARE(data.roughnessTextureSwizzle(), MaterialTextureSwizzle::R); CORRADE_COMPARE(data.roughnessTextureSwizzle(), MaterialTextureSwizzle::R);
CORRADE_COMPARE(data.roughnessTextureMatrix(), Matrix3{}); CORRADE_COMPARE(data.roughnessTextureMatrix(), Matrix3{});
CORRADE_COMPARE(data.roughnessTextureCoordinates(), 0); CORRADE_COMPARE(data.roughnessTextureCoordinates(), 0);
CORRADE_COMPARE(data.roughnessTextureLayer(), 0);
CORRADE_COMPARE(data.normalTexture(), 4); CORRADE_COMPARE(data.normalTexture(), 4);
CORRADE_COMPARE(data.normalTextureScale(), 1.0f); CORRADE_COMPARE(data.normalTextureScale(), 1.0f);
CORRADE_COMPARE(data.normalTextureSwizzle(), MaterialTextureSwizzle::RGB); CORRADE_COMPARE(data.normalTextureSwizzle(), MaterialTextureSwizzle::RGB);
CORRADE_COMPARE(data.normalTextureMatrix(), Matrix3{}); CORRADE_COMPARE(data.normalTextureMatrix(), Matrix3{});
CORRADE_COMPARE(data.normalTextureCoordinates(), 0); CORRADE_COMPARE(data.normalTextureCoordinates(), 0);
CORRADE_COMPARE(data.normalTextureLayer(), 0);
CORRADE_COMPARE(data.occlusionTexture(), 5); CORRADE_COMPARE(data.occlusionTexture(), 5);
CORRADE_COMPARE(data.occlusionTextureStrength(), 1.0f); CORRADE_COMPARE(data.occlusionTextureStrength(), 1.0f);
CORRADE_COMPARE(data.occlusionTextureSwizzle(), MaterialTextureSwizzle::R); CORRADE_COMPARE(data.occlusionTextureSwizzle(), MaterialTextureSwizzle::R);
CORRADE_COMPARE(data.occlusionTextureMatrix(), Matrix3{}); CORRADE_COMPARE(data.occlusionTextureMatrix(), Matrix3{});
CORRADE_COMPARE(data.occlusionTextureCoordinates(), 0); CORRADE_COMPARE(data.occlusionTextureCoordinates(), 0);
CORRADE_COMPARE(data.occlusionTextureLayer(), 0);
CORRADE_COMPARE(data.emissiveColor(), 0x000000_rgbf); CORRADE_COMPARE(data.emissiveColor(), 0x000000_rgbf);
CORRADE_COMPARE(data.emissiveTexture(), 6); CORRADE_COMPARE(data.emissiveTexture(), 6);
CORRADE_COMPARE(data.emissiveTextureMatrix(), Matrix3{}); CORRADE_COMPARE(data.emissiveTextureMatrix(), Matrix3{});
CORRADE_COMPARE(data.emissiveTextureCoordinates(), 0); CORRADE_COMPARE(data.emissiveTextureCoordinates(), 0);
CORRADE_COMPARE(data.emissiveTextureLayer(), 0);
} }
void PbrMetallicRoughnessMaterialDataTest::texturedSingleMatrixCoordinates() { void PbrMetallicRoughnessMaterialDataTest::texturedSingleMatrixCoordinatesLayer() {
PbrMetallicRoughnessMaterialData data{{}, { PbrMetallicRoughnessMaterialData data{{}, {
{MaterialAttribute::BaseColorTexture, 1u}, {MaterialAttribute::BaseColorTexture, 1u},
{MaterialAttribute::MetalnessTexture, 2u}, {MaterialAttribute::MetalnessTexture, 2u},
@ -263,21 +285,28 @@ void PbrMetallicRoughnessMaterialDataTest::texturedSingleMatrixCoordinates() {
{MaterialAttribute::OcclusionTexture, 5u}, {MaterialAttribute::OcclusionTexture, 5u},
{MaterialAttribute::EmissiveTexture, 6u}, {MaterialAttribute::EmissiveTexture, 6u},
{MaterialAttribute::TextureMatrix, Matrix3::scaling({0.5f, 0.5f})}, {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.baseColorTextureMatrix(), Matrix3::scaling({0.5f, 0.5f}));
CORRADE_COMPARE(data.baseColorTextureCoordinates(), 7); CORRADE_COMPARE(data.baseColorTextureCoordinates(), 7);
CORRADE_COMPARE(data.baseColorTextureLayer(), 8);
CORRADE_COMPARE(data.metalnessTextureMatrix(), Matrix3::scaling({0.5f, 0.5f})); CORRADE_COMPARE(data.metalnessTextureMatrix(), Matrix3::scaling({0.5f, 0.5f}));
CORRADE_COMPARE(data.metalnessTextureCoordinates(), 7); CORRADE_COMPARE(data.metalnessTextureCoordinates(), 7);
CORRADE_COMPARE(data.metalnessTextureLayer(), 8);
CORRADE_COMPARE(data.roughnessTextureMatrix(), Matrix3::scaling({0.5f, 0.5f})); CORRADE_COMPARE(data.roughnessTextureMatrix(), Matrix3::scaling({0.5f, 0.5f}));
CORRADE_COMPARE(data.roughnessTextureCoordinates(), 7); CORRADE_COMPARE(data.roughnessTextureCoordinates(), 7);
CORRADE_COMPARE(data.roughnessTextureLayer(), 8);
CORRADE_COMPARE(data.normalTextureMatrix(), Matrix3::scaling({0.5f, 0.5f})); CORRADE_COMPARE(data.normalTextureMatrix(), Matrix3::scaling({0.5f, 0.5f}));
CORRADE_COMPARE(data.normalTextureCoordinates(), 7); CORRADE_COMPARE(data.normalTextureCoordinates(), 7);
CORRADE_COMPARE(data.normalTextureLayer(), 8);
CORRADE_COMPARE(data.occlusionTextureMatrix(), Matrix3::scaling({0.5f, 0.5f})); CORRADE_COMPARE(data.occlusionTextureMatrix(), Matrix3::scaling({0.5f, 0.5f}));
CORRADE_COMPARE(data.occlusionTextureCoordinates(), 7); CORRADE_COMPARE(data.occlusionTextureCoordinates(), 7);
CORRADE_COMPARE(data.occlusionTextureLayer(), 8);
CORRADE_COMPARE(data.emissiveTextureMatrix(), Matrix3::scaling({0.5f, 0.5f})); CORRADE_COMPARE(data.emissiveTextureMatrix(), Matrix3::scaling({0.5f, 0.5f}));
CORRADE_COMPARE(data.emissiveTextureCoordinates(), 7); CORRADE_COMPARE(data.emissiveTextureCoordinates(), 7);
CORRADE_COMPARE(data.emissiveTextureLayer(), 8);
} }
void PbrMetallicRoughnessMaterialDataTest::texturedImplicitPackedMetallicRoughness() { void PbrMetallicRoughnessMaterialDataTest::texturedImplicitPackedMetallicRoughness() {
@ -291,10 +320,12 @@ void PbrMetallicRoughnessMaterialDataTest::texturedImplicitPackedMetallicRoughne
CORRADE_COMPARE(data.roughnessTextureSwizzle(), MaterialTextureSwizzle::G); CORRADE_COMPARE(data.roughnessTextureSwizzle(), MaterialTextureSwizzle::G);
CORRADE_COMPARE(data.roughnessTextureMatrix(), Matrix3{}); CORRADE_COMPARE(data.roughnessTextureMatrix(), Matrix3{});
CORRADE_COMPARE(data.roughnessTextureCoordinates(), 0); CORRADE_COMPARE(data.roughnessTextureCoordinates(), 0);
CORRADE_COMPARE(data.roughnessTextureLayer(), 0);
CORRADE_COMPARE(data.metalnessTexture(), 2); CORRADE_COMPARE(data.metalnessTexture(), 2);
CORRADE_COMPARE(data.metalnessTextureSwizzle(), MaterialTextureSwizzle::B); CORRADE_COMPARE(data.metalnessTextureSwizzle(), MaterialTextureSwizzle::B);
CORRADE_COMPARE(data.metalnessTextureMatrix(), Matrix3{}); CORRADE_COMPARE(data.metalnessTextureMatrix(), Matrix3{});
CORRADE_COMPARE(data.metalnessTextureCoordinates(), 0); CORRADE_COMPARE(data.metalnessTextureCoordinates(), 0);
CORRADE_COMPARE(data.metalnessTextureLayer(), 0);
/* Explicit parameters for everything, but all the same */ /* Explicit parameters for everything, but all the same */
} { } {
@ -303,19 +334,23 @@ void PbrMetallicRoughnessMaterialDataTest::texturedImplicitPackedMetallicRoughne
{MaterialAttribute::RoughnessTextureSwizzle, MaterialTextureSwizzle::G}, {MaterialAttribute::RoughnessTextureSwizzle, MaterialTextureSwizzle::G},
{MaterialAttribute::RoughnessTextureMatrix, Matrix3::scaling({0.5f, 0.5f})}, {MaterialAttribute::RoughnessTextureMatrix, Matrix3::scaling({0.5f, 0.5f})},
{MaterialAttribute::RoughnessTextureCoordinates, 3u}, {MaterialAttribute::RoughnessTextureCoordinates, 3u},
{MaterialAttribute::RoughnessTextureLayer, 17u},
{MaterialAttribute::MetalnessTextureMatrix, Matrix3::scaling({0.5f, 0.5f})}, {MaterialAttribute::MetalnessTextureMatrix, Matrix3::scaling({0.5f, 0.5f})},
{MaterialAttribute::MetalnessTextureSwizzle, MaterialTextureSwizzle::B}, {MaterialAttribute::MetalnessTextureSwizzle, MaterialTextureSwizzle::B},
{MaterialAttribute::MetalnessTextureCoordinates, 3u} {MaterialAttribute::MetalnessTextureCoordinates, 3u},
{MaterialAttribute::MetalnessTextureLayer, 17u},
}}; }};
CORRADE_VERIFY(data.hasNoneRoughnessMetallicTexture()); CORRADE_VERIFY(data.hasNoneRoughnessMetallicTexture());
CORRADE_COMPARE(data.roughnessTexture(), 2); CORRADE_COMPARE(data.roughnessTexture(), 2);
CORRADE_COMPARE(data.roughnessTextureSwizzle(), MaterialTextureSwizzle::G); CORRADE_COMPARE(data.roughnessTextureSwizzle(), MaterialTextureSwizzle::G);
CORRADE_COMPARE(data.roughnessTextureMatrix(), Matrix3::scaling({0.5f, 0.5f})); CORRADE_COMPARE(data.roughnessTextureMatrix(), Matrix3::scaling({0.5f, 0.5f}));
CORRADE_COMPARE(data.roughnessTextureCoordinates(), 3); CORRADE_COMPARE(data.roughnessTextureCoordinates(), 3);
CORRADE_COMPARE(data.roughnessTextureLayer(), 17);
CORRADE_COMPARE(data.metalnessTexture(), 2); CORRADE_COMPARE(data.metalnessTexture(), 2);
CORRADE_COMPARE(data.metalnessTextureSwizzle(), MaterialTextureSwizzle::B); CORRADE_COMPARE(data.metalnessTextureSwizzle(), MaterialTextureSwizzle::B);
CORRADE_COMPARE(data.metalnessTextureMatrix(), Matrix3::scaling({0.5f, 0.5f})); CORRADE_COMPARE(data.metalnessTextureMatrix(), Matrix3::scaling({0.5f, 0.5f}));
CORRADE_COMPARE(data.metalnessTextureCoordinates(), 3); CORRADE_COMPARE(data.metalnessTextureCoordinates(), 3);
CORRADE_COMPARE(data.metalnessTextureLayer(), 17);
/* Swizzle is ignored when the combined texture is specified, so this is /* Swizzle is ignored when the combined texture is specified, so this is
fine */ fine */
@ -341,6 +376,14 @@ void PbrMetallicRoughnessMaterialDataTest::texturedImplicitPackedMetallicRoughne
{MaterialAttribute::RoughnessTextureCoordinates, 1u}, {MaterialAttribute::RoughnessTextureCoordinates, 1u},
}}; }};
CORRADE_VERIFY(!data.hasNoneRoughnessMetallicTexture()); 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::RoughnessTextureSwizzle, MaterialTextureSwizzle::G},
{MaterialAttribute::RoughnessTextureMatrix, Matrix3::scaling({0.5f, 0.5f})}, {MaterialAttribute::RoughnessTextureMatrix, Matrix3::scaling({0.5f, 0.5f})},
{MaterialAttribute::RoughnessTextureCoordinates, 3u}, {MaterialAttribute::RoughnessTextureCoordinates, 3u},
{MaterialAttribute::RoughnessTextureLayer, 7u},
{MaterialAttribute::MetalnessTexture, 2u}, {MaterialAttribute::MetalnessTexture, 2u},
{MaterialAttribute::MetalnessTextureMatrix, Matrix3::scaling({0.5f, 0.5f})}, {MaterialAttribute::MetalnessTextureMatrix, Matrix3::scaling({0.5f, 0.5f})},
{MaterialAttribute::MetalnessTextureSwizzle, MaterialTextureSwizzle::B}, {MaterialAttribute::MetalnessTextureSwizzle, MaterialTextureSwizzle::B},
{MaterialAttribute::MetalnessTextureCoordinates, 3u} {MaterialAttribute::MetalnessTextureCoordinates, 3u},
{MaterialAttribute::MetalnessTextureLayer, 7u}
}}; }};
CORRADE_VERIFY(data.hasNoneRoughnessMetallicTexture()); CORRADE_VERIFY(data.hasNoneRoughnessMetallicTexture());
@ -418,6 +463,17 @@ void PbrMetallicRoughnessMaterialDataTest::texturedExplicitPackedMetallicRoughne
{MaterialAttribute::MetalnessTextureSwizzle, MaterialTextureSwizzle::B}, {MaterialAttribute::MetalnessTextureSwizzle, MaterialTextureSwizzle::B},
}}; }};
CORRADE_VERIFY(!data.hasNoneRoughnessMetallicTexture()); 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::RoughnessTextureSwizzle, MaterialTextureSwizzle::R},
{MaterialAttribute::RoughnessTextureMatrix, Matrix3::scaling({0.5f, 0.5f})}, {MaterialAttribute::RoughnessTextureMatrix, Matrix3::scaling({0.5f, 0.5f})},
{MaterialAttribute::RoughnessTextureCoordinates, 3u}, {MaterialAttribute::RoughnessTextureCoordinates, 3u},
{MaterialAttribute::RoughnessTextureLayer, 7u},
{MaterialAttribute::MetalnessTexture, 2u}, {MaterialAttribute::MetalnessTexture, 2u},
{MaterialAttribute::MetalnessTextureMatrix, Matrix3::scaling({0.5f, 0.5f})}, {MaterialAttribute::MetalnessTextureMatrix, Matrix3::scaling({0.5f, 0.5f})},
{MaterialAttribute::MetalnessTextureSwizzle, MaterialTextureSwizzle::G}, {MaterialAttribute::MetalnessTextureSwizzle, MaterialTextureSwizzle::G},
{MaterialAttribute::MetalnessTextureCoordinates, 3u}, {MaterialAttribute::MetalnessTextureCoordinates, 3u},
{MaterialAttribute::MetalnessTextureLayer, 7u},
{MaterialAttribute::OcclusionTexture, 2u}, {MaterialAttribute::OcclusionTexture, 2u},
{MaterialAttribute::OcclusionTextureSwizzle, MaterialTextureSwizzle::B}, {MaterialAttribute::OcclusionTextureSwizzle, MaterialTextureSwizzle::B},
{MaterialAttribute::OcclusionTextureMatrix, Matrix3::scaling({0.5f, 0.5f})}, {MaterialAttribute::OcclusionTextureMatrix, Matrix3::scaling({0.5f, 0.5f})},
{MaterialAttribute::OcclusionTextureCoordinates, 3u} {MaterialAttribute::OcclusionTextureCoordinates, 3u},
{MaterialAttribute::OcclusionTextureLayer, 7u},
}}; }};
CORRADE_VERIFY(data.hasRoughnessMetallicOcclusionTexture()); CORRADE_VERIFY(data.hasRoughnessMetallicOcclusionTexture());
/* This isn't a superset */ /* This isn't a superset */
@ -506,9 +565,21 @@ void PbrMetallicRoughnessMaterialDataTest::texturedExplicitPackedRoughnessMetall
{MaterialAttribute::RoughnessTexture, 2u}, {MaterialAttribute::RoughnessTexture, 2u},
{MaterialAttribute::MetalnessTexture, 2u}, {MaterialAttribute::MetalnessTexture, 2u},
{MaterialAttribute::MetalnessTextureSwizzle, MaterialTextureSwizzle::G}, {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::OcclusionTexture, 2u},
{MaterialAttribute::OcclusionTextureSwizzle, MaterialTextureSwizzle::B}, {MaterialAttribute::OcclusionTextureSwizzle, MaterialTextureSwizzle::B},
{MaterialAttribute::MetalnessTextureCoordinates, 1u},
}}; }};
CORRADE_VERIFY(!data.hasRoughnessMetallicOcclusionTexture()); CORRADE_VERIFY(!data.hasRoughnessMetallicOcclusionTexture());
} }
@ -604,6 +675,18 @@ void PbrMetallicRoughnessMaterialDataTest::texturedExplicitPackedOcclusionRoughn
{MaterialAttribute::MetalnessTextureCoordinates, 1u}, {MaterialAttribute::MetalnessTextureCoordinates, 1u},
}}; }};
CORRADE_VERIFY(!data.hasOcclusionRoughnessMetallicTexture()); 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}, {MaterialAttribute::MetalnessTextureCoordinates, 1u},
}}; }};
CORRADE_VERIFY(!data.hasNormalRoughnessMetallicTexture()); 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.baseColorTexture();
data.baseColorTextureMatrix(); data.baseColorTextureMatrix();
data.baseColorTextureCoordinates(); data.baseColorTextureCoordinates();
data.baseColorTextureLayer();
data.metalnessTexture(); data.metalnessTexture();
data.metalnessTextureSwizzle(); data.metalnessTextureSwizzle();
data.metalnessTextureMatrix(); data.metalnessTextureMatrix();
data.metalnessTextureCoordinates(); data.metalnessTextureCoordinates();
data.metalnessTextureLayer();
data.roughnessTexture(); data.roughnessTexture();
data.roughnessTextureSwizzle(); data.roughnessTextureSwizzle();
data.roughnessTextureMatrix(); data.roughnessTextureMatrix();
data.roughnessTextureCoordinates(); data.roughnessTextureCoordinates();
data.roughnessTextureLayer();
data.normalTexture(); data.normalTexture();
data.normalTextureScale(); data.normalTextureScale();
data.normalTextureSwizzle(); data.normalTextureSwizzle();
data.normalTextureMatrix(); data.normalTextureMatrix();
data.normalTextureCoordinates(); data.normalTextureCoordinates();
data.normalTextureLayer();
data.occlusionTexture(); data.occlusionTexture();
data.occlusionTextureStrength(); data.occlusionTextureStrength();
data.occlusionTextureSwizzle(); data.occlusionTextureSwizzle();
data.occlusionTextureMatrix(); data.occlusionTextureMatrix();
data.occlusionTextureCoordinates(); data.occlusionTextureCoordinates();
data.occlusionTextureLayer();
data.emissiveTexture(); data.emissiveTexture();
data.emissiveTextureMatrix(); data.emissiveTextureMatrix();
data.emissiveTextureCoordinates(); data.emissiveTextureCoordinates();
data.emissiveTextureLayer();
CORRADE_COMPARE(out.str(), CORRADE_COMPARE(out.str(),
"Trade::MaterialData::attribute(): attribute BaseColorTexture not found in layer 0\n" "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::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::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::metalnessTexture(): the material doesn't have a metalness texture\n"
"Trade::PbrMetallicRoughnessMaterialData::metalnessTextureSwizzle(): 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::metalnessTextureMatrix(): the material doesn't have a metalness texture\n"
"Trade::PbrMetallicRoughnessMaterialData::metalnessTextureCoordinates(): 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::roughnessTexture(): the material doesn't have a roughness texture\n"
"Trade::PbrMetallicRoughnessMaterialData::roughnessTextureSwizzle(): 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::roughnessTextureMatrix(): the material doesn't have a roughness texture\n"
"Trade::PbrMetallicRoughnessMaterialData::roughnessTextureCoordinates(): 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::MaterialData::attribute(): attribute NormalTexture not found in layer 0\n"
"Trade::PbrMetallicRoughnessMaterialData::normalTextureScale(): the material doesn't have a normal texture\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::normalTextureSwizzle(): the material doesn't have a normal texture\n"
"Trade::PbrMetallicRoughnessMaterialData::normalTextureMatrix(): 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::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::MaterialData::attribute(): attribute OcclusionTexture not found in layer 0\n"
"Trade::PbrMetallicRoughnessMaterialData::occlusionTextureStrength(): the material doesn't have an occlusion texture\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::occlusionTextureSwizzle(): the material doesn't have an occlusion texture\n"
"Trade::PbrMetallicRoughnessMaterialData::occlusionTextureMatrix(): 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::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::MaterialData::attribute(): attribute EmissiveTexture not found in layer 0\n"
"Trade::PbrMetallicRoughnessMaterialData::emissiveTextureMatrix(): the material doesn't have an emissive texture\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{{}, {}}; PbrMetallicRoughnessMaterialData a{{}, {}};
CORRADE_VERIFY(a.hasCommonTextureTransformation()); CORRADE_VERIFY(a.hasCommonTextureTransformation());
CORRADE_VERIFY(a.hasCommonTextureCoordinates()); CORRADE_VERIFY(a.hasCommonTextureCoordinates());
CORRADE_VERIFY(a.hasCommonTextureLayer());
CORRADE_COMPARE(a.commonTextureMatrix(), Matrix3{}); CORRADE_COMPARE(a.commonTextureMatrix(), Matrix3{});
CORRADE_COMPARE(a.commonTextureCoordinates(), 0); CORRADE_COMPARE(a.commonTextureCoordinates(), 0);
CORRADE_COMPARE(a.commonTextureLayer(), 0);
PbrMetallicRoughnessMaterialData b{{}, { PbrMetallicRoughnessMaterialData b{{}, {
{MaterialAttribute::TextureMatrix, Matrix3::scaling({0.5f, 0.5f})}, {MaterialAttribute::TextureMatrix, Matrix3::scaling({0.5f, 0.5f})},
{MaterialAttribute::TextureCoordinates, 7u} {MaterialAttribute::TextureCoordinates, 7u},
{MaterialAttribute::TextureLayer, 22u}
}}; }};
CORRADE_VERIFY(b.hasCommonTextureTransformation()); CORRADE_VERIFY(b.hasCommonTextureTransformation());
CORRADE_VERIFY(b.hasCommonTextureCoordinates()); CORRADE_VERIFY(b.hasCommonTextureCoordinates());
CORRADE_VERIFY(b.hasCommonTextureLayer());
CORRADE_COMPARE(b.commonTextureMatrix(), Matrix3::scaling({0.5f, 0.5f})); CORRADE_COMPARE(b.commonTextureMatrix(), Matrix3::scaling({0.5f, 0.5f}));
CORRADE_COMPARE(b.commonTextureCoordinates(), 7); CORRADE_COMPARE(b.commonTextureCoordinates(), 7);
CORRADE_COMPARE(b.commonTextureLayer(), 22);
} }
void PbrMetallicRoughnessMaterialDataTest::commonTransformationCoordinatesOneTexture() { void PbrMetallicRoughnessMaterialDataTest::commonTransformationCoordinatesLayerOneTexture() {
Containers::StringView textureName = PbrMetallicRoughnessTextureData[testCaseInstanceId()]; Containers::StringView textureName = PbrMetallicRoughnessTextureData[testCaseInstanceId()];
setTestCaseDescription(textureName); setTestCaseDescription(textureName);
@ -785,19 +898,23 @@ void PbrMetallicRoughnessMaterialDataTest::commonTransformationCoordinatesOneTex
{textureName, 5u}, {textureName, 5u},
{textureName + "Matrix", Matrix3::scaling({0.5f, 1.0f})}, {textureName + "Matrix", Matrix3::scaling({0.5f, 1.0f})},
{textureName + "Coordinates", 17u}, {textureName + "Coordinates", 17u},
{textureName + "Layer", 22u},
/* These shouldn't affect the above */ /* These shouldn't affect the above */
{MaterialAttribute::TextureMatrix, Matrix3::translation({0.5f, 0.0f})}, {MaterialAttribute::TextureMatrix, Matrix3::translation({0.5f, 0.0f})},
{MaterialAttribute::TextureCoordinates, 3u} {MaterialAttribute::TextureCoordinates, 3u},
{MaterialAttribute::TextureLayer, 66u},
}}; }};
CORRADE_VERIFY(data.hasCommonTextureTransformation()); CORRADE_VERIFY(data.hasCommonTextureTransformation());
CORRADE_COMPARE(data.commonTextureMatrix(), Matrix3::scaling({0.5f, 1.0f})); CORRADE_COMPARE(data.commonTextureMatrix(), Matrix3::scaling({0.5f, 1.0f}));
CORRADE_VERIFY(data.hasCommonTextureCoordinates()); CORRADE_VERIFY(data.hasCommonTextureCoordinates());
CORRADE_COMPARE(data.commonTextureCoordinates(), 17u); 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()]; Containers::StringView textureName = PbrMetallicRoughnessTextureData[testCaseInstanceId()];
setTestCaseDescription(textureName); setTestCaseDescription(textureName);
@ -810,18 +927,21 @@ void PbrMetallicRoughnessMaterialDataTest::commonTransformationCoordinatesOneDif
{MaterialAttribute::EmissiveTexture, 7u}, {MaterialAttribute::EmissiveTexture, 7u},
{textureName + "Matrix", Matrix3::scaling({0.5f, 1.0f})}, {textureName + "Matrix", Matrix3::scaling({0.5f, 1.0f})},
{textureName + "Coordinates", 17u}, {textureName + "Coordinates", 17u},
{textureName + "Layer", 22u},
/* These are used by all textures except the one above, failing the /* These are used by all textures except the one above, failing the
check */ check */
{MaterialAttribute::TextureMatrix, Matrix3::translation({0.5f, 0.0f})}, {MaterialAttribute::TextureMatrix, Matrix3::translation({0.5f, 0.0f})},
{MaterialAttribute::TextureCoordinates, 3u} {MaterialAttribute::TextureCoordinates, 3u},
{MaterialAttribute::TextureLayer, 66u},
}}; }};
CORRADE_VERIFY(!data.hasCommonTextureTransformation()); CORRADE_VERIFY(!data.hasCommonTextureTransformation());
CORRADE_VERIFY(!data.hasCommonTextureCoordinates()); CORRADE_VERIFY(!data.hasCommonTextureCoordinates());
CORRADE_VERIFY(!data.hasCommonTextureLayer());
} }
void PbrMetallicRoughnessMaterialDataTest::commonCoordinatesImplicit() { void PbrMetallicRoughnessMaterialDataTest::commonCoordinatesLayerImplicit() {
Containers::StringView textureName = PbrMetallicRoughnessTextureData[testCaseInstanceId()]; Containers::StringView textureName = PbrMetallicRoughnessTextureData[testCaseInstanceId()];
setTestCaseDescription(textureName); setTestCaseDescription(textureName);
@ -830,16 +950,20 @@ void PbrMetallicRoughnessMaterialDataTest::commonCoordinatesImplicit() {
PbrMetallicRoughnessMaterialData data{{}, { PbrMetallicRoughnessMaterialData data{{}, {
{textureName, 5u}, {textureName, 5u},
{textureName + "Coordinates", 0u} {textureName + "Coordinates", 0u},
{textureName + "Layer", 0u},
}}; }};
/* Zero is treated same as if there would be no attribute at all */ /* Zero is treated same as if there would be no attribute at all */
CORRADE_VERIFY(!data.hasTextureCoordinates()); CORRADE_VERIFY(!data.hasTextureCoordinates());
CORRADE_VERIFY(!data.hasTextureLayer());
CORRADE_VERIFY(data.hasCommonTextureCoordinates()); CORRADE_VERIFY(data.hasCommonTextureCoordinates());
CORRADE_VERIFY(data.hasCommonTextureLayer());
CORRADE_COMPARE(data.commonTextureCoordinates(), 0u); CORRADE_COMPARE(data.commonTextureCoordinates(), 0u);
CORRADE_COMPARE(data.commonTextureLayer(), 0u);
} }
void PbrMetallicRoughnessMaterialDataTest::noCommonTransformationCoordinates() { void PbrMetallicRoughnessMaterialDataTest::noCommonTransformationCoordinatesLayer() {
#ifdef CORRADE_NO_ASSERT #ifdef CORRADE_NO_ASSERT
CORRADE_SKIP("CORRADE_NO_ASSERT defined, can't test assertions"); CORRADE_SKIP("CORRADE_NO_ASSERT defined, can't test assertions");
#endif #endif
@ -850,20 +974,24 @@ void PbrMetallicRoughnessMaterialDataTest::noCommonTransformationCoordinates() {
{MaterialAttribute::BaseColorTextureCoordinates, 3u}, {MaterialAttribute::BaseColorTextureCoordinates, 3u},
{MaterialAttribute::MetalnessTexture, 4u}, {MaterialAttribute::MetalnessTexture, 4u},
{MaterialAttribute::MetalnessTextureMatrix, Matrix3::scaling({0.5f, 1.0f})}, {MaterialAttribute::MetalnessTextureMatrix, Matrix3::scaling({0.5f, 1.0f})},
{MaterialAttribute::MetalnessTextureLayer, 22u},
{MaterialAttribute::RoughnessTexture, 5u}, {MaterialAttribute::RoughnessTexture, 5u},
{MaterialAttribute::RoughnessTextureCoordinates, 17u} {MaterialAttribute::RoughnessTextureCoordinates, 17u}
}}; }};
CORRADE_VERIFY(!data.hasCommonTextureTransformation()); CORRADE_VERIFY(!data.hasCommonTextureTransformation());
CORRADE_VERIFY(!data.hasCommonTextureCoordinates()); CORRADE_VERIFY(!data.hasCommonTextureCoordinates());
CORRADE_VERIFY(!data.hasCommonTextureLayer());
std::ostringstream out; std::ostringstream out;
Error redirectError{&out}; Error redirectError{&out};
data.commonTextureMatrix(); data.commonTextureMatrix();
data.commonTextureCoordinates(); data.commonTextureCoordinates();
data.commonTextureLayer();
CORRADE_COMPARE(out.str(), CORRADE_COMPARE(out.str(),
"Trade::PbrMetallicRoughnessMaterialData::commonTextureMatrix(): the material doesn't have a common texture coordinate transformation\n" "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");
} }
}}}} }}}}

148
src/Magnum/Trade/Test/PbrSpecularGlossinessMaterialDataTest.cpp

@ -44,13 +44,13 @@ class PbrSpecularGlossinessMaterialDataTest: public TestSuite::Tester {
void texturedDefaults(); void texturedDefaults();
void texturedImplicitPackedSpecularGlossiness(); void texturedImplicitPackedSpecularGlossiness();
void texturedExplicitPackedSpecularGlossiness(); void texturedExplicitPackedSpecularGlossiness();
void texturedSingleMatrixCoordinates(); void texturedSingleMatrixCoordinatesLayer();
void invalidTextures(); void invalidTextures();
void commonTransformationCoordinatesNoTextures(); void commonTransformationCoordinatesLayerNoTextures();
void commonTransformationCoordinatesOneTexture(); void commonTransformationCoordinatesLayerOneTexture();
void commonTransformationCoordinatesOneDifferentTexture(); void commonTransformationCoordinatesLayerOneDifferentTexture();
void commonCoordinatesImplicit(); void commonCoordinatesLayerImplicit();
void noCommonTransformationCoordinates(); void noCommonTransformationCoordinatesLayer();
}; };
const Containers::StringView PbrSpecularGlossinessTextureData[] { const Containers::StringView PbrSpecularGlossinessTextureData[] {
@ -69,17 +69,17 @@ PbrSpecularGlossinessMaterialDataTest::PbrSpecularGlossinessMaterialDataTest() {
&PbrSpecularGlossinessMaterialDataTest::texturedDefaults, &PbrSpecularGlossinessMaterialDataTest::texturedDefaults,
&PbrSpecularGlossinessMaterialDataTest::texturedImplicitPackedSpecularGlossiness, &PbrSpecularGlossinessMaterialDataTest::texturedImplicitPackedSpecularGlossiness,
&PbrSpecularGlossinessMaterialDataTest::texturedExplicitPackedSpecularGlossiness, &PbrSpecularGlossinessMaterialDataTest::texturedExplicitPackedSpecularGlossiness,
&PbrSpecularGlossinessMaterialDataTest::texturedSingleMatrixCoordinates, &PbrSpecularGlossinessMaterialDataTest::texturedSingleMatrixCoordinatesLayer,
&PbrSpecularGlossinessMaterialDataTest::invalidTextures, &PbrSpecularGlossinessMaterialDataTest::invalidTextures,
&PbrSpecularGlossinessMaterialDataTest::commonTransformationCoordinatesNoTextures}); &PbrSpecularGlossinessMaterialDataTest::commonTransformationCoordinatesLayerNoTextures});
addInstancedTests({ addInstancedTests({
&PbrSpecularGlossinessMaterialDataTest::commonTransformationCoordinatesOneTexture, &PbrSpecularGlossinessMaterialDataTest::commonTransformationCoordinatesLayerOneTexture,
&PbrSpecularGlossinessMaterialDataTest::commonTransformationCoordinatesOneDifferentTexture, &PbrSpecularGlossinessMaterialDataTest::commonTransformationCoordinatesLayerOneDifferentTexture,
&PbrSpecularGlossinessMaterialDataTest::commonCoordinatesImplicit}, &PbrSpecularGlossinessMaterialDataTest::commonCoordinatesLayerImplicit},
Containers::arraySize(PbrSpecularGlossinessTextureData)); Containers::arraySize(PbrSpecularGlossinessTextureData));
addTests({&PbrSpecularGlossinessMaterialDataTest::noCommonTransformationCoordinates}); addTests({&PbrSpecularGlossinessMaterialDataTest::noCommonTransformationCoordinatesLayer});
} }
using namespace Math::Literals; using namespace Math::Literals;
@ -100,6 +100,7 @@ void PbrSpecularGlossinessMaterialDataTest::basics() {
CORRADE_VERIFY(!data.hasSpecularGlossinessTexture()); CORRADE_VERIFY(!data.hasSpecularGlossinessTexture());
CORRADE_VERIFY(!data.hasTextureTransformation()); CORRADE_VERIFY(!data.hasTextureTransformation());
CORRADE_VERIFY(!data.hasTextureCoordinates()); CORRADE_VERIFY(!data.hasTextureCoordinates());
CORRADE_VERIFY(!data.hasTextureLayer());
CORRADE_COMPARE(data.diffuseColor(), 0xccffbbff_rgbaf); CORRADE_COMPARE(data.diffuseColor(), 0xccffbbff_rgbaf);
CORRADE_COMPARE(data.specularColor(), 0xff336600_rgbaf); CORRADE_COMPARE(data.specularColor(), 0xff336600_rgbaf);
CORRADE_COMPARE(data.glossiness(), 0.79f); CORRADE_COMPARE(data.glossiness(), 0.79f);
@ -117,6 +118,7 @@ void PbrSpecularGlossinessMaterialDataTest::defaults() {
CORRADE_VERIFY(!data.hasSpecularGlossinessTexture()); CORRADE_VERIFY(!data.hasSpecularGlossinessTexture());
CORRADE_VERIFY(!data.hasTextureTransformation()); CORRADE_VERIFY(!data.hasTextureTransformation());
CORRADE_VERIFY(!data.hasTextureCoordinates()); CORRADE_VERIFY(!data.hasTextureCoordinates());
CORRADE_VERIFY(!data.hasTextureLayer());
CORRADE_COMPARE(data.diffuseColor(), 0xffffffff_rgbaf); CORRADE_COMPARE(data.diffuseColor(), 0xffffffff_rgbaf);
CORRADE_COMPARE(data.specularColor(), 0xffffff00_rgbaf); CORRADE_COMPARE(data.specularColor(), 0xffffff00_rgbaf);
CORRADE_COMPARE(data.glossiness(), 1.0f); CORRADE_COMPARE(data.glossiness(), 1.0f);
@ -128,30 +130,36 @@ void PbrSpecularGlossinessMaterialDataTest::textured() {
{MaterialAttribute::DiffuseTexture, 0u}, {MaterialAttribute::DiffuseTexture, 0u},
{MaterialAttribute::DiffuseTextureMatrix, Matrix3::scaling({0.5f, 1.0f})}, {MaterialAttribute::DiffuseTextureMatrix, Matrix3::scaling({0.5f, 1.0f})},
{MaterialAttribute::DiffuseTextureCoordinates, 2u}, {MaterialAttribute::DiffuseTextureCoordinates, 2u},
{MaterialAttribute::DiffuseTextureLayer, 8u},
{MaterialAttribute::SpecularColor, 0x33556600_rgbaf}, {MaterialAttribute::SpecularColor, 0x33556600_rgbaf},
{MaterialAttribute::SpecularTexture, 1u}, {MaterialAttribute::SpecularTexture, 1u},
{MaterialAttribute::SpecularTextureSwizzle, MaterialTextureSwizzle::RGBA}, {MaterialAttribute::SpecularTextureSwizzle, MaterialTextureSwizzle::RGBA},
{MaterialAttribute::SpecularTextureMatrix, Matrix3::scaling({0.5f, 0.5f})}, {MaterialAttribute::SpecularTextureMatrix, Matrix3::scaling({0.5f, 0.5f})},
{MaterialAttribute::SpecularTextureCoordinates, 3u}, {MaterialAttribute::SpecularTextureCoordinates, 3u},
{MaterialAttribute::SpecularTextureLayer, 9u},
{MaterialAttribute::Glossiness, 0.79f}, {MaterialAttribute::Glossiness, 0.79f},
{MaterialAttribute::GlossinessTexture, 2u}, {MaterialAttribute::GlossinessTexture, 2u},
{MaterialAttribute::GlossinessTextureSwizzle, MaterialTextureSwizzle::A}, {MaterialAttribute::GlossinessTextureSwizzle, MaterialTextureSwizzle::A},
{MaterialAttribute::GlossinessTextureMatrix, Matrix3::scaling({1.0f, 1.0f})}, {MaterialAttribute::GlossinessTextureMatrix, Matrix3::scaling({1.0f, 1.0f})},
{MaterialAttribute::GlossinessTextureCoordinates, 4u}, {MaterialAttribute::GlossinessTextureCoordinates, 4u},
{MaterialAttribute::GlossinessTextureLayer, 10u},
{MaterialAttribute::NormalTexture, 3u}, {MaterialAttribute::NormalTexture, 3u},
{MaterialAttribute::NormalTextureScale, 0.35f}, {MaterialAttribute::NormalTextureScale, 0.35f},
{MaterialAttribute::NormalTextureSwizzle, MaterialTextureSwizzle::BA}, {MaterialAttribute::NormalTextureSwizzle, MaterialTextureSwizzle::BA},
{MaterialAttribute::NormalTextureMatrix, Matrix3::scaling({1.0f, 0.5f})}, {MaterialAttribute::NormalTextureMatrix, Matrix3::scaling({1.0f, 0.5f})},
{MaterialAttribute::NormalTextureCoordinates, 5u}, {MaterialAttribute::NormalTextureCoordinates, 5u},
{MaterialAttribute::NormalTextureLayer, 11u},
{MaterialAttribute::OcclusionTexture, 4u}, {MaterialAttribute::OcclusionTexture, 4u},
{MaterialAttribute::OcclusionTextureStrength, 0.66f}, {MaterialAttribute::OcclusionTextureStrength, 0.66f},
{MaterialAttribute::OcclusionTextureSwizzle, MaterialTextureSwizzle::B}, {MaterialAttribute::OcclusionTextureSwizzle, MaterialTextureSwizzle::B},
{MaterialAttribute::OcclusionTextureMatrix, Matrix3::scaling({1.0f, 0.75f})}, {MaterialAttribute::OcclusionTextureMatrix, Matrix3::scaling({1.0f, 0.75f})},
{MaterialAttribute::OcclusionTextureCoordinates, 6u}, {MaterialAttribute::OcclusionTextureCoordinates, 6u},
{MaterialAttribute::OcclusionTextureLayer, 12u},
{MaterialAttribute::EmissiveColor, 0x111111_rgbf}, {MaterialAttribute::EmissiveColor, 0x111111_rgbf},
{MaterialAttribute::EmissiveTexture, 5u}, {MaterialAttribute::EmissiveTexture, 5u},
{MaterialAttribute::EmissiveTextureMatrix, Matrix3::scaling({0.75f, 0.5f})}, {MaterialAttribute::EmissiveTextureMatrix, Matrix3::scaling({0.75f, 0.5f})},
{MaterialAttribute::EmissiveTextureCoordinates, 7u} {MaterialAttribute::EmissiveTextureCoordinates, 7u},
{MaterialAttribute::EmissiveTextureLayer, 13u},
}}; }};
CORRADE_VERIFY(data.hasSpecularTexture()); CORRADE_VERIFY(data.hasSpecularTexture());
@ -159,34 +167,41 @@ void PbrSpecularGlossinessMaterialDataTest::textured() {
CORRADE_VERIFY(!data.hasSpecularGlossinessTexture()); CORRADE_VERIFY(!data.hasSpecularGlossinessTexture());
CORRADE_VERIFY(data.hasTextureTransformation()); CORRADE_VERIFY(data.hasTextureTransformation());
CORRADE_VERIFY(data.hasTextureCoordinates()); CORRADE_VERIFY(data.hasTextureCoordinates());
CORRADE_VERIFY(data.hasTextureLayer());
CORRADE_COMPARE(data.diffuseColor(), 0xccffbbff_rgbaf); CORRADE_COMPARE(data.diffuseColor(), 0xccffbbff_rgbaf);
CORRADE_COMPARE(data.diffuseTexture(), 0); CORRADE_COMPARE(data.diffuseTexture(), 0);
CORRADE_COMPARE(data.diffuseTextureMatrix(), Matrix3::scaling({0.5f, 1.0f})); CORRADE_COMPARE(data.diffuseTextureMatrix(), Matrix3::scaling({0.5f, 1.0f}));
CORRADE_COMPARE(data.diffuseTextureCoordinates(), 2); CORRADE_COMPARE(data.diffuseTextureCoordinates(), 2);
CORRADE_COMPARE(data.diffuseTextureLayer(), 8);
CORRADE_COMPARE(data.specularColor(), 0x33556600_rgbaf); CORRADE_COMPARE(data.specularColor(), 0x33556600_rgbaf);
CORRADE_COMPARE(data.specularTexture(), 1); CORRADE_COMPARE(data.specularTexture(), 1);
CORRADE_COMPARE(data.specularTextureSwizzle(), MaterialTextureSwizzle::RGBA); CORRADE_COMPARE(data.specularTextureSwizzle(), MaterialTextureSwizzle::RGBA);
CORRADE_COMPARE(data.specularTextureMatrix(), Matrix3::scaling({0.5f, 0.5f})); CORRADE_COMPARE(data.specularTextureMatrix(), Matrix3::scaling({0.5f, 0.5f}));
CORRADE_COMPARE(data.specularTextureCoordinates(), 3); CORRADE_COMPARE(data.specularTextureCoordinates(), 3);
CORRADE_COMPARE(data.specularTextureLayer(), 9);
CORRADE_COMPARE(data.glossiness(), 0.79f); CORRADE_COMPARE(data.glossiness(), 0.79f);
CORRADE_COMPARE(data.glossinessTexture(), 2); CORRADE_COMPARE(data.glossinessTexture(), 2);
CORRADE_COMPARE(data.glossinessTextureSwizzle(), MaterialTextureSwizzle::A); CORRADE_COMPARE(data.glossinessTextureSwizzle(), MaterialTextureSwizzle::A);
CORRADE_COMPARE(data.glossinessTextureMatrix(), Matrix3::scaling({1.0f, 1.0f})); CORRADE_COMPARE(data.glossinessTextureMatrix(), Matrix3::scaling({1.0f, 1.0f}));
CORRADE_COMPARE(data.glossinessTextureCoordinates(), 4); CORRADE_COMPARE(data.glossinessTextureCoordinates(), 4);
CORRADE_COMPARE(data.glossinessTextureLayer(), 10);
CORRADE_COMPARE(data.normalTexture(), 3); CORRADE_COMPARE(data.normalTexture(), 3);
CORRADE_COMPARE(data.normalTextureScale(), 0.35f); CORRADE_COMPARE(data.normalTextureScale(), 0.35f);
CORRADE_COMPARE(data.normalTextureSwizzle(), MaterialTextureSwizzle::BA); CORRADE_COMPARE(data.normalTextureSwizzle(), MaterialTextureSwizzle::BA);
CORRADE_COMPARE(data.normalTextureMatrix(), Matrix3::scaling({1.0f, 0.5f})); CORRADE_COMPARE(data.normalTextureMatrix(), Matrix3::scaling({1.0f, 0.5f}));
CORRADE_COMPARE(data.normalTextureCoordinates(), 5); CORRADE_COMPARE(data.normalTextureCoordinates(), 5);
CORRADE_COMPARE(data.normalTextureLayer(), 11);
CORRADE_COMPARE(data.occlusionTexture(), 4); CORRADE_COMPARE(data.occlusionTexture(), 4);
CORRADE_COMPARE(data.occlusionTextureStrength(), 0.66f); CORRADE_COMPARE(data.occlusionTextureStrength(), 0.66f);
CORRADE_COMPARE(data.occlusionTextureMatrix(), Matrix3::scaling({1.0f, 0.75f})); CORRADE_COMPARE(data.occlusionTextureMatrix(), Matrix3::scaling({1.0f, 0.75f}));
CORRADE_COMPARE(data.occlusionTextureSwizzle(), MaterialTextureSwizzle::B); CORRADE_COMPARE(data.occlusionTextureSwizzle(), MaterialTextureSwizzle::B);
CORRADE_COMPARE(data.occlusionTextureCoordinates(), 6); CORRADE_COMPARE(data.occlusionTextureCoordinates(), 6);
CORRADE_COMPARE(data.occlusionTextureLayer(), 12);
CORRADE_COMPARE(data.emissiveColor(), 0x111111_rgbf); CORRADE_COMPARE(data.emissiveColor(), 0x111111_rgbf);
CORRADE_COMPARE(data.emissiveTextureMatrix(), Matrix3::scaling({0.75f, 0.5f})); CORRADE_COMPARE(data.emissiveTextureMatrix(), Matrix3::scaling({0.75f, 0.5f}));
CORRADE_COMPARE(data.emissiveTexture(), 5); CORRADE_COMPARE(data.emissiveTexture(), 5);
CORRADE_COMPARE(data.emissiveTextureCoordinates(), 7); CORRADE_COMPARE(data.emissiveTextureCoordinates(), 7);
CORRADE_COMPARE(data.emissiveTextureLayer(), 13);
} }
void PbrSpecularGlossinessMaterialDataTest::texturedDefaults() { void PbrSpecularGlossinessMaterialDataTest::texturedDefaults() {
@ -204,37 +219,44 @@ void PbrSpecularGlossinessMaterialDataTest::texturedDefaults() {
CORRADE_VERIFY(!data.hasSpecularGlossinessTexture()); CORRADE_VERIFY(!data.hasSpecularGlossinessTexture());
CORRADE_VERIFY(!data.hasTextureTransformation()); CORRADE_VERIFY(!data.hasTextureTransformation());
CORRADE_VERIFY(!data.hasTextureCoordinates()); CORRADE_VERIFY(!data.hasTextureCoordinates());
CORRADE_VERIFY(!data.hasTextureLayer());
CORRADE_COMPARE(data.diffuseColor(), 0xffffffff_rgbaf); CORRADE_COMPARE(data.diffuseColor(), 0xffffffff_rgbaf);
CORRADE_COMPARE(data.diffuseTexture(), 1); CORRADE_COMPARE(data.diffuseTexture(), 1);
CORRADE_COMPARE(data.diffuseTextureMatrix(), Matrix3{}); CORRADE_COMPARE(data.diffuseTextureMatrix(), Matrix3{});
CORRADE_COMPARE(data.diffuseTextureCoordinates(), 0); CORRADE_COMPARE(data.diffuseTextureCoordinates(), 0);
CORRADE_COMPARE(data.diffuseTextureLayer(), 0);
CORRADE_COMPARE(data.specularColor(), 0xffffff00_rgbaf); CORRADE_COMPARE(data.specularColor(), 0xffffff00_rgbaf);
CORRADE_COMPARE(data.specularTexture(), 2); CORRADE_COMPARE(data.specularTexture(), 2);
CORRADE_COMPARE(data.specularTextureSwizzle(), MaterialTextureSwizzle::RGB); CORRADE_COMPARE(data.specularTextureSwizzle(), MaterialTextureSwizzle::RGB);
CORRADE_COMPARE(data.specularTextureMatrix(), Matrix3{}); CORRADE_COMPARE(data.specularTextureMatrix(), Matrix3{});
CORRADE_COMPARE(data.specularTextureCoordinates(), 0); CORRADE_COMPARE(data.specularTextureCoordinates(), 0);
CORRADE_COMPARE(data.specularTextureLayer(), 0);
CORRADE_COMPARE(data.glossiness(), 1.0f); CORRADE_COMPARE(data.glossiness(), 1.0f);
CORRADE_COMPARE(data.glossinessTexture(), 3); CORRADE_COMPARE(data.glossinessTexture(), 3);
CORRADE_COMPARE(data.glossinessTextureSwizzle(), MaterialTextureSwizzle::R); CORRADE_COMPARE(data.glossinessTextureSwizzle(), MaterialTextureSwizzle::R);
CORRADE_COMPARE(data.glossinessTextureMatrix(), Matrix3{}); CORRADE_COMPARE(data.glossinessTextureMatrix(), Matrix3{});
CORRADE_COMPARE(data.glossinessTextureCoordinates(), 0); CORRADE_COMPARE(data.glossinessTextureCoordinates(), 0);
CORRADE_COMPARE(data.glossinessTextureLayer(), 0);
CORRADE_COMPARE(data.normalTexture(), 4); CORRADE_COMPARE(data.normalTexture(), 4);
CORRADE_COMPARE(data.normalTextureScale(), 1.0f); CORRADE_COMPARE(data.normalTextureScale(), 1.0f);
CORRADE_COMPARE(data.normalTextureSwizzle(), MaterialTextureSwizzle::RGB); CORRADE_COMPARE(data.normalTextureSwizzle(), MaterialTextureSwizzle::RGB);
CORRADE_COMPARE(data.normalTextureMatrix(), Matrix3{}); CORRADE_COMPARE(data.normalTextureMatrix(), Matrix3{});
CORRADE_COMPARE(data.normalTextureCoordinates(), 0); CORRADE_COMPARE(data.normalTextureCoordinates(), 0);
CORRADE_COMPARE(data.normalTextureLayer(), 0);
CORRADE_COMPARE(data.occlusionTexture(), 5); CORRADE_COMPARE(data.occlusionTexture(), 5);
CORRADE_COMPARE(data.occlusionTextureStrength(), 1.0f); CORRADE_COMPARE(data.occlusionTextureStrength(), 1.0f);
CORRADE_COMPARE(data.occlusionTextureMatrix(), Matrix3{}); CORRADE_COMPARE(data.occlusionTextureMatrix(), Matrix3{});
CORRADE_COMPARE(data.occlusionTextureSwizzle(), MaterialTextureSwizzle::R); CORRADE_COMPARE(data.occlusionTextureSwizzle(), MaterialTextureSwizzle::R);
CORRADE_COMPARE(data.occlusionTextureCoordinates(), 0); CORRADE_COMPARE(data.occlusionTextureCoordinates(), 0);
CORRADE_COMPARE(data.occlusionTextureLayer(), 0);
CORRADE_COMPARE(data.emissiveColor(), 0x000000_rgbf); CORRADE_COMPARE(data.emissiveColor(), 0x000000_rgbf);
CORRADE_COMPARE(data.emissiveTextureMatrix(), Matrix3{}); CORRADE_COMPARE(data.emissiveTextureMatrix(), Matrix3{});
CORRADE_COMPARE(data.emissiveTexture(), 6); CORRADE_COMPARE(data.emissiveTexture(), 6);
CORRADE_COMPARE(data.emissiveTextureCoordinates(), 0); CORRADE_COMPARE(data.emissiveTextureCoordinates(), 0);
CORRADE_COMPARE(data.emissiveTextureLayer(), 0);
} }
void PbrSpecularGlossinessMaterialDataTest::texturedSingleMatrixCoordinates() { void PbrSpecularGlossinessMaterialDataTest::texturedSingleMatrixCoordinatesLayer() {
PbrSpecularGlossinessMaterialData data{{}, { PbrSpecularGlossinessMaterialData data{{}, {
{MaterialAttribute::DiffuseTexture, 1u}, {MaterialAttribute::DiffuseTexture, 1u},
{MaterialAttribute::SpecularTexture, 2u}, {MaterialAttribute::SpecularTexture, 2u},
@ -243,23 +265,31 @@ void PbrSpecularGlossinessMaterialDataTest::texturedSingleMatrixCoordinates() {
{MaterialAttribute::OcclusionTexture, 5u}, {MaterialAttribute::OcclusionTexture, 5u},
{MaterialAttribute::EmissiveTexture, 6u}, {MaterialAttribute::EmissiveTexture, 6u},
{MaterialAttribute::TextureMatrix, Matrix3::scaling({0.5f, 0.5f})}, {MaterialAttribute::TextureMatrix, Matrix3::scaling({0.5f, 0.5f})},
{MaterialAttribute::TextureCoordinates, 7u} {MaterialAttribute::TextureCoordinates, 7u},
{MaterialAttribute::TextureLayer, 22u},
}}; }};
CORRADE_VERIFY(data.hasTextureTransformation()); CORRADE_VERIFY(data.hasTextureTransformation());
CORRADE_VERIFY(data.hasTextureCoordinates()); CORRADE_VERIFY(data.hasTextureCoordinates());
CORRADE_VERIFY(data.hasTextureLayer());
CORRADE_COMPARE(data.diffuseTextureMatrix(), Matrix3::scaling({0.5f, 0.5f})); CORRADE_COMPARE(data.diffuseTextureMatrix(), Matrix3::scaling({0.5f, 0.5f}));
CORRADE_COMPARE(data.diffuseTextureCoordinates(), 7); CORRADE_COMPARE(data.diffuseTextureCoordinates(), 7);
CORRADE_COMPARE(data.diffuseTextureLayer(), 22);
CORRADE_COMPARE(data.specularTextureMatrix(), Matrix3::scaling({0.5f, 0.5f})); CORRADE_COMPARE(data.specularTextureMatrix(), Matrix3::scaling({0.5f, 0.5f}));
CORRADE_COMPARE(data.specularTextureCoordinates(), 7); CORRADE_COMPARE(data.specularTextureCoordinates(), 7);
CORRADE_COMPARE(data.specularTextureLayer(), 22);
CORRADE_COMPARE(data.glossinessTextureMatrix(), Matrix3::scaling({0.5f, 0.5f})); CORRADE_COMPARE(data.glossinessTextureMatrix(), Matrix3::scaling({0.5f, 0.5f}));
CORRADE_COMPARE(data.glossinessTextureCoordinates(), 7); CORRADE_COMPARE(data.glossinessTextureCoordinates(), 7);
CORRADE_COMPARE(data.glossinessTextureLayer(), 22);
CORRADE_COMPARE(data.normalTextureMatrix(), Matrix3::scaling({0.5f, 0.5f})); CORRADE_COMPARE(data.normalTextureMatrix(), Matrix3::scaling({0.5f, 0.5f}));
CORRADE_COMPARE(data.normalTextureCoordinates(), 7); CORRADE_COMPARE(data.normalTextureCoordinates(), 7);
CORRADE_COMPARE(data.normalTextureLayer(), 22);
CORRADE_COMPARE(data.occlusionTextureMatrix(), Matrix3::scaling({0.5f, 0.5f})); CORRADE_COMPARE(data.occlusionTextureMatrix(), Matrix3::scaling({0.5f, 0.5f}));
CORRADE_COMPARE(data.occlusionTextureCoordinates(), 7); CORRADE_COMPARE(data.occlusionTextureCoordinates(), 7);
CORRADE_COMPARE(data.occlusionTextureLayer(), 22);
CORRADE_COMPARE(data.emissiveTextureMatrix(), Matrix3::scaling({0.5f, 0.5f})); CORRADE_COMPARE(data.emissiveTextureMatrix(), Matrix3::scaling({0.5f, 0.5f}));
CORRADE_COMPARE(data.emissiveTextureCoordinates(), 7); CORRADE_COMPARE(data.emissiveTextureCoordinates(), 7);
CORRADE_COMPARE(data.emissiveTextureLayer(), 22);
} }
void PbrSpecularGlossinessMaterialDataTest::texturedImplicitPackedSpecularGlossiness() { void PbrSpecularGlossinessMaterialDataTest::texturedImplicitPackedSpecularGlossiness() {
@ -273,10 +303,12 @@ void PbrSpecularGlossinessMaterialDataTest::texturedImplicitPackedSpecularGlossi
CORRADE_COMPARE(data.specularTextureSwizzle(), MaterialTextureSwizzle::RGB); CORRADE_COMPARE(data.specularTextureSwizzle(), MaterialTextureSwizzle::RGB);
CORRADE_COMPARE(data.specularTextureMatrix(), Matrix3{}); CORRADE_COMPARE(data.specularTextureMatrix(), Matrix3{});
CORRADE_COMPARE(data.specularTextureCoordinates(), 0); CORRADE_COMPARE(data.specularTextureCoordinates(), 0);
CORRADE_COMPARE(data.specularTextureLayer(), 0);
CORRADE_COMPARE(data.glossinessTexture(), 2); CORRADE_COMPARE(data.glossinessTexture(), 2);
CORRADE_COMPARE(data.glossinessTextureSwizzle(), MaterialTextureSwizzle::A); CORRADE_COMPARE(data.glossinessTextureSwizzle(), MaterialTextureSwizzle::A);
CORRADE_COMPARE(data.glossinessTextureMatrix(), Matrix3{}); CORRADE_COMPARE(data.glossinessTextureMatrix(), Matrix3{});
CORRADE_COMPARE(data.glossinessTextureCoordinates(), 0); CORRADE_COMPARE(data.glossinessTextureCoordinates(), 0);
CORRADE_COMPARE(data.glossinessTextureLayer(), 0);
/* Explicit parameters for everything, but all the same */ /* Explicit parameters for everything, but all the same */
} { } {
@ -285,19 +317,23 @@ void PbrSpecularGlossinessMaterialDataTest::texturedImplicitPackedSpecularGlossi
{MaterialAttribute::SpecularTextureSwizzle, MaterialTextureSwizzle::RGB}, {MaterialAttribute::SpecularTextureSwizzle, MaterialTextureSwizzle::RGB},
{MaterialAttribute::SpecularTextureMatrix, Matrix3::scaling({0.5f, 0.5f})}, {MaterialAttribute::SpecularTextureMatrix, Matrix3::scaling({0.5f, 0.5f})},
{MaterialAttribute::SpecularTextureCoordinates, 3u}, {MaterialAttribute::SpecularTextureCoordinates, 3u},
{MaterialAttribute::SpecularTextureLayer, 17u},
{MaterialAttribute::GlossinessTextureSwizzle, MaterialTextureSwizzle::A}, {MaterialAttribute::GlossinessTextureSwizzle, MaterialTextureSwizzle::A},
{MaterialAttribute::GlossinessTextureMatrix, Matrix3::scaling({0.5f, 0.5f})}, {MaterialAttribute::GlossinessTextureMatrix, Matrix3::scaling({0.5f, 0.5f})},
{MaterialAttribute::GlossinessTextureCoordinates, 3u} {MaterialAttribute::GlossinessTextureCoordinates, 3u},
{MaterialAttribute::GlossinessTextureLayer, 17u}
}}; }};
CORRADE_VERIFY(data.hasSpecularGlossinessTexture()); CORRADE_VERIFY(data.hasSpecularGlossinessTexture());
CORRADE_COMPARE(data.specularTexture(), 2); CORRADE_COMPARE(data.specularTexture(), 2);
CORRADE_COMPARE(data.specularTextureSwizzle(), MaterialTextureSwizzle::RGB); CORRADE_COMPARE(data.specularTextureSwizzle(), MaterialTextureSwizzle::RGB);
CORRADE_COMPARE(data.specularTextureMatrix(), Matrix3::scaling({0.5f, 0.5f})); CORRADE_COMPARE(data.specularTextureMatrix(), Matrix3::scaling({0.5f, 0.5f}));
CORRADE_COMPARE(data.specularTextureCoordinates(), 3); CORRADE_COMPARE(data.specularTextureCoordinates(), 3);
CORRADE_COMPARE(data.specularTextureLayer(), 17);
CORRADE_COMPARE(data.glossinessTexture(), 2); CORRADE_COMPARE(data.glossinessTexture(), 2);
CORRADE_COMPARE(data.glossinessTextureSwizzle(), MaterialTextureSwizzle::A); CORRADE_COMPARE(data.glossinessTextureSwizzle(), MaterialTextureSwizzle::A);
CORRADE_COMPARE(data.glossinessTextureMatrix(), Matrix3::scaling({0.5f, 0.5f})); CORRADE_COMPARE(data.glossinessTextureMatrix(), Matrix3::scaling({0.5f, 0.5f}));
CORRADE_COMPARE(data.glossinessTextureCoordinates(), 3); CORRADE_COMPARE(data.glossinessTextureCoordinates(), 3);
CORRADE_COMPARE(data.glossinessTextureLayer(), 17);
/* Swizzle is ignored when the combined texture is specified, so this is /* Swizzle is ignored when the combined texture is specified, so this is
fine. */ fine. */
@ -323,6 +359,14 @@ void PbrSpecularGlossinessMaterialDataTest::texturedImplicitPackedSpecularGlossi
{MaterialAttribute::GlossinessTextureCoordinates, 1u}, {MaterialAttribute::GlossinessTextureCoordinates, 1u},
}}; }};
CORRADE_VERIFY(!data.hasSpecularGlossinessTexture()); 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.specularTextureSwizzle(), MaterialTextureSwizzle::RGB);
CORRADE_COMPARE(data.specularTextureMatrix(), Matrix3{}); CORRADE_COMPARE(data.specularTextureMatrix(), Matrix3{});
CORRADE_COMPARE(data.specularTextureCoordinates(), 0); CORRADE_COMPARE(data.specularTextureCoordinates(), 0);
CORRADE_COMPARE(data.specularTextureLayer(), 0);
CORRADE_COMPARE(data.glossinessTexture(), 2); CORRADE_COMPARE(data.glossinessTexture(), 2);
CORRADE_COMPARE(data.glossinessTextureSwizzle(), MaterialTextureSwizzle::A); CORRADE_COMPARE(data.glossinessTextureSwizzle(), MaterialTextureSwizzle::A);
CORRADE_COMPARE(data.glossinessTextureMatrix(), Matrix3{}); CORRADE_COMPARE(data.glossinessTextureMatrix(), Matrix3{});
CORRADE_COMPARE(data.glossinessTextureCoordinates(), 0); CORRADE_COMPARE(data.glossinessTextureCoordinates(), 0);
CORRADE_COMPARE(data.glossinessTextureLayer(), 0);
/* Explicit parameters for everything, but all the same */ /* Explicit parameters for everything, but all the same */
} { } {
@ -351,20 +397,24 @@ void PbrSpecularGlossinessMaterialDataTest::texturedExplicitPackedSpecularGlossi
{MaterialAttribute::SpecularTextureSwizzle, MaterialTextureSwizzle::RGB}, {MaterialAttribute::SpecularTextureSwizzle, MaterialTextureSwizzle::RGB},
{MaterialAttribute::SpecularTextureMatrix, Matrix3::scaling({0.5f, 0.5f})}, {MaterialAttribute::SpecularTextureMatrix, Matrix3::scaling({0.5f, 0.5f})},
{MaterialAttribute::SpecularTextureCoordinates, 3u}, {MaterialAttribute::SpecularTextureCoordinates, 3u},
{MaterialAttribute::SpecularTextureLayer, 17u},
{MaterialAttribute::GlossinessTexture, 2u}, {MaterialAttribute::GlossinessTexture, 2u},
{MaterialAttribute::GlossinessTextureSwizzle, MaterialTextureSwizzle::A}, {MaterialAttribute::GlossinessTextureSwizzle, MaterialTextureSwizzle::A},
{MaterialAttribute::GlossinessTextureMatrix, Matrix3::scaling({0.5f, 0.5f})}, {MaterialAttribute::GlossinessTextureMatrix, Matrix3::scaling({0.5f, 0.5f})},
{MaterialAttribute::GlossinessTextureCoordinates, 3u} {MaterialAttribute::GlossinessTextureCoordinates, 3u},
{MaterialAttribute::GlossinessTextureLayer, 17u}
}}; }};
CORRADE_VERIFY(data.hasSpecularGlossinessTexture()); CORRADE_VERIFY(data.hasSpecularGlossinessTexture());
CORRADE_COMPARE(data.specularTexture(), 2); CORRADE_COMPARE(data.specularTexture(), 2);
CORRADE_COMPARE(data.specularTextureSwizzle(), MaterialTextureSwizzle::RGB); CORRADE_COMPARE(data.specularTextureSwizzle(), MaterialTextureSwizzle::RGB);
CORRADE_COMPARE(data.specularTextureMatrix(), Matrix3::scaling({0.5f, 0.5f})); CORRADE_COMPARE(data.specularTextureMatrix(), Matrix3::scaling({0.5f, 0.5f}));
CORRADE_COMPARE(data.specularTextureCoordinates(), 3); CORRADE_COMPARE(data.specularTextureCoordinates(), 3);
CORRADE_COMPARE(data.specularTextureLayer(), 17);
CORRADE_COMPARE(data.glossinessTexture(), 2); CORRADE_COMPARE(data.glossinessTexture(), 2);
CORRADE_COMPARE(data.glossinessTextureSwizzle(), MaterialTextureSwizzle::A); CORRADE_COMPARE(data.glossinessTextureSwizzle(), MaterialTextureSwizzle::A);
CORRADE_COMPARE(data.glossinessTextureMatrix(), Matrix3::scaling({0.5f, 0.5f})); CORRADE_COMPARE(data.glossinessTextureMatrix(), Matrix3::scaling({0.5f, 0.5f}));
CORRADE_COMPARE(data.glossinessTextureCoordinates(), 3); CORRADE_COMPARE(data.glossinessTextureCoordinates(), 3);
CORRADE_COMPARE(data.glossinessTextureLayer(), 17);
/* Different texture ID */ /* Different texture ID */
} { } {
@ -413,6 +463,16 @@ void PbrSpecularGlossinessMaterialDataTest::texturedExplicitPackedSpecularGlossi
{MaterialAttribute::GlossinessTextureCoordinates, 1u} {MaterialAttribute::GlossinessTextureCoordinates, 1u}
}}; }};
CORRADE_VERIFY(!data.hasSpecularGlossinessTexture()); 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.diffuseTexture();
data.diffuseTextureMatrix(); data.diffuseTextureMatrix();
data.diffuseTextureCoordinates(); data.diffuseTextureCoordinates();
data.diffuseTextureLayer();
data.specularTexture(); data.specularTexture();
data.specularTextureSwizzle(); data.specularTextureSwizzle();
data.specularTextureMatrix(); data.specularTextureMatrix();
data.specularTextureCoordinates(); data.specularTextureCoordinates();
data.specularTextureLayer();
data.glossinessTexture(); data.glossinessTexture();
data.glossinessTextureSwizzle(); data.glossinessTextureSwizzle();
data.glossinessTextureMatrix(); data.glossinessTextureMatrix();
data.glossinessTextureCoordinates(); data.glossinessTextureCoordinates();
data.glossinessTextureLayer();
data.normalTexture(); data.normalTexture();
data.normalTextureScale(); data.normalTextureScale();
data.normalTextureSwizzle(); data.normalTextureSwizzle();
data.normalTextureMatrix(); data.normalTextureMatrix();
data.normalTextureCoordinates(); data.normalTextureCoordinates();
data.normalTextureLayer();
data.occlusionTexture(); data.occlusionTexture();
data.occlusionTextureStrength(); data.occlusionTextureStrength();
data.occlusionTextureSwizzle(); data.occlusionTextureSwizzle();
data.occlusionTextureMatrix(); data.occlusionTextureMatrix();
data.occlusionTextureCoordinates(); data.occlusionTextureCoordinates();
data.occlusionTextureLayer();
data.emissiveTexture(); data.emissiveTexture();
data.emissiveTextureMatrix(); data.emissiveTextureMatrix();
data.emissiveTextureCoordinates(); data.emissiveTextureCoordinates();
data.emissiveTextureLayer();
CORRADE_COMPARE(out.str(), CORRADE_COMPARE(out.str(),
"Trade::MaterialData::attribute(): attribute DiffuseTexture not found in layer 0\n" "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::diffuseTextureMatrix(): the material doesn't have a diffuse texture\n"
"Trade::PbrSpecularGlossinessMaterialData::diffuseTextureCoordinates(): 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::specularTexture(): the material doesn't have a specular texture\n"
"Trade::PbrSpecularGlossinessMaterialData::specularTextureSwizzle(): 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::specularTextureMatrix(): the material doesn't have a specular texture\n"
"Trade::PbrSpecularGlossinessMaterialData::specularTextureCoordinates(): 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::glossinessTexture(): the material doesn't have a glossiness texture\n"
"Trade::PbrSpecularGlossinessMaterialData::glossinessTextureSwizzle(): 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::glossinessTextureMatrix(): the material doesn't have a glossiness texture\n"
"Trade::PbrSpecularGlossinessMaterialData::glossinessTextureCoordinates(): 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::MaterialData::attribute(): attribute NormalTexture not found in layer 0\n"
"Trade::PbrSpecularGlossinessMaterialData::normalTextureScale(): the material doesn't have a normal texture\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::normalTextureSwizzle(): the material doesn't have a normal texture\n"
"Trade::PbrSpecularGlossinessMaterialData::normalTextureMatrix(): 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::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::MaterialData::attribute(): attribute OcclusionTexture not found in layer 0\n"
"Trade::PbrSpecularGlossinessMaterialData::occlusionTextureStrength(): the material doesn't have an occlusion texture\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::occlusionTextureSwizzle(): the material doesn't have an occlusion texture\n"
"Trade::PbrSpecularGlossinessMaterialData::occlusionTextureMatrix(): 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::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::MaterialData::attribute(): attribute EmissiveTexture not found in layer 0\n"
"Trade::PbrSpecularGlossinessMaterialData::emissiveTextureMatrix(): the material doesn't have an emissive texture\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{{}, {}}; PbrSpecularGlossinessMaterialData a{{}, {}};
CORRADE_VERIFY(a.hasCommonTextureTransformation()); CORRADE_VERIFY(a.hasCommonTextureTransformation());
CORRADE_VERIFY(a.hasCommonTextureCoordinates()); CORRADE_VERIFY(a.hasCommonTextureCoordinates());
CORRADE_VERIFY(a.hasCommonTextureLayer());
CORRADE_COMPARE(a.commonTextureMatrix(), Matrix3{}); CORRADE_COMPARE(a.commonTextureMatrix(), Matrix3{});
CORRADE_COMPARE(a.commonTextureCoordinates(), 0); CORRADE_COMPARE(a.commonTextureCoordinates(), 0);
CORRADE_COMPARE(a.commonTextureLayer(), 0);
PbrSpecularGlossinessMaterialData b{{}, { PbrSpecularGlossinessMaterialData b{{}, {
{MaterialAttribute::TextureMatrix, Matrix3::scaling({0.5f, 0.5f})}, {MaterialAttribute::TextureMatrix, Matrix3::scaling({0.5f, 0.5f})},
{MaterialAttribute::TextureCoordinates, 7u} {MaterialAttribute::TextureCoordinates, 7u},
{MaterialAttribute::TextureLayer, 22u}
}}; }};
CORRADE_VERIFY(b.hasCommonTextureTransformation()); CORRADE_VERIFY(b.hasCommonTextureTransformation());
CORRADE_VERIFY(b.hasCommonTextureCoordinates()); CORRADE_VERIFY(b.hasCommonTextureCoordinates());
CORRADE_VERIFY(b.hasCommonTextureLayer());
CORRADE_COMPARE(b.commonTextureMatrix(), Matrix3::scaling({0.5f, 0.5f})); CORRADE_COMPARE(b.commonTextureMatrix(), Matrix3::scaling({0.5f, 0.5f}));
CORRADE_COMPARE(b.commonTextureCoordinates(), 7); CORRADE_COMPARE(b.commonTextureCoordinates(), 7);
CORRADE_COMPARE(b.commonTextureLayer(), 22);
} }
void PbrSpecularGlossinessMaterialDataTest::commonTransformationCoordinatesOneTexture() { void PbrSpecularGlossinessMaterialDataTest::commonTransformationCoordinatesLayerOneTexture() {
Containers::StringView textureName = PbrSpecularGlossinessTextureData[testCaseInstanceId()]; Containers::StringView textureName = PbrSpecularGlossinessTextureData[testCaseInstanceId()];
setTestCaseDescription(textureName); setTestCaseDescription(textureName);
@ -501,19 +578,23 @@ void PbrSpecularGlossinessMaterialDataTest::commonTransformationCoordinatesOneTe
{textureName, 5u}, {textureName, 5u},
{textureName + "Matrix", Matrix3::scaling({0.5f, 1.0f})}, {textureName + "Matrix", Matrix3::scaling({0.5f, 1.0f})},
{textureName + "Coordinates", 17u}, {textureName + "Coordinates", 17u},
{textureName + "Layer", 22u},
/* These shouldn't affect the above */ /* These shouldn't affect the above */
{MaterialAttribute::TextureMatrix, Matrix3::translation({0.5f, 0.0f})}, {MaterialAttribute::TextureMatrix, Matrix3::translation({0.5f, 0.0f})},
{MaterialAttribute::TextureCoordinates, 3u} {MaterialAttribute::TextureCoordinates, 3u},
{MaterialAttribute::TextureLayer, 66u},
}}; }};
CORRADE_VERIFY(data.hasCommonTextureTransformation()); CORRADE_VERIFY(data.hasCommonTextureTransformation());
CORRADE_COMPARE(data.commonTextureMatrix(), Matrix3::scaling({0.5f, 1.0f})); CORRADE_COMPARE(data.commonTextureMatrix(), Matrix3::scaling({0.5f, 1.0f}));
CORRADE_VERIFY(data.hasCommonTextureCoordinates()); CORRADE_VERIFY(data.hasCommonTextureCoordinates());
CORRADE_COMPARE(data.commonTextureCoordinates(), 17u); 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()]; Containers::StringView textureName = PbrSpecularGlossinessTextureData[testCaseInstanceId()];
setTestCaseDescription(textureName); setTestCaseDescription(textureName);
@ -526,18 +607,21 @@ void PbrSpecularGlossinessMaterialDataTest::commonTransformationCoordinatesOneDi
{MaterialAttribute::EmissiveTexture, 7u}, {MaterialAttribute::EmissiveTexture, 7u},
{textureName + "Matrix", Matrix3::scaling({0.5f, 1.0f})}, {textureName + "Matrix", Matrix3::scaling({0.5f, 1.0f})},
{textureName + "Coordinates", 17u}, {textureName + "Coordinates", 17u},
{textureName + "Layer", 22u},
/* These are used by all textures except the one above, failing the /* These are used by all textures except the one above, failing the
check */ check */
{MaterialAttribute::TextureMatrix, Matrix3::translation({0.5f, 0.0f})}, {MaterialAttribute::TextureMatrix, Matrix3::translation({0.5f, 0.0f})},
{MaterialAttribute::TextureCoordinates, 3u} {MaterialAttribute::TextureCoordinates, 3u},
{MaterialAttribute::TextureLayer, 66u},
}}; }};
CORRADE_VERIFY(!data.hasCommonTextureTransformation()); CORRADE_VERIFY(!data.hasCommonTextureTransformation());
CORRADE_VERIFY(!data.hasCommonTextureCoordinates()); CORRADE_VERIFY(!data.hasCommonTextureCoordinates());
CORRADE_VERIFY(!data.hasCommonTextureLayer());
} }
void PbrSpecularGlossinessMaterialDataTest::commonCoordinatesImplicit() { void PbrSpecularGlossinessMaterialDataTest::commonCoordinatesLayerImplicit() {
Containers::StringView textureName = PbrSpecularGlossinessTextureData[testCaseInstanceId()]; Containers::StringView textureName = PbrSpecularGlossinessTextureData[testCaseInstanceId()];
setTestCaseDescription(textureName); setTestCaseDescription(textureName);
@ -546,16 +630,20 @@ void PbrSpecularGlossinessMaterialDataTest::commonCoordinatesImplicit() {
PbrSpecularGlossinessMaterialData data{{}, { PbrSpecularGlossinessMaterialData data{{}, {
{textureName, 5u}, {textureName, 5u},
{textureName + "Coordinates", 0u} {textureName + "Coordinates", 0u},
{textureName + "Layer", 0u},
}}; }};
/* Zero is treated same as if there would be no attribute at all */ /* Zero is treated same as if there would be no attribute at all */
CORRADE_VERIFY(!data.hasTextureCoordinates()); CORRADE_VERIFY(!data.hasTextureCoordinates());
CORRADE_VERIFY(!data.hasTextureLayer());
CORRADE_VERIFY(data.hasCommonTextureCoordinates()); CORRADE_VERIFY(data.hasCommonTextureCoordinates());
CORRADE_VERIFY(data.hasCommonTextureLayer());
CORRADE_COMPARE(data.commonTextureCoordinates(), 0u); CORRADE_COMPARE(data.commonTextureCoordinates(), 0u);
CORRADE_COMPARE(data.commonTextureLayer(), 0u);
} }
void PbrSpecularGlossinessMaterialDataTest::noCommonTransformationCoordinates() { void PbrSpecularGlossinessMaterialDataTest::noCommonTransformationCoordinatesLayer() {
#ifdef CORRADE_NO_ASSERT #ifdef CORRADE_NO_ASSERT
CORRADE_SKIP("CORRADE_NO_ASSERT defined, can't test assertions"); CORRADE_SKIP("CORRADE_NO_ASSERT defined, can't test assertions");
#endif #endif
@ -566,20 +654,24 @@ void PbrSpecularGlossinessMaterialDataTest::noCommonTransformationCoordinates()
{MaterialAttribute::DiffuseTextureCoordinates, 3u}, {MaterialAttribute::DiffuseTextureCoordinates, 3u},
{MaterialAttribute::SpecularTexture, 4u}, {MaterialAttribute::SpecularTexture, 4u},
{MaterialAttribute::SpecularTextureMatrix, Matrix3::scaling({0.5f, 1.0f})}, {MaterialAttribute::SpecularTextureMatrix, Matrix3::scaling({0.5f, 1.0f})},
{MaterialAttribute::SpecularTextureLayer, 22u},
{MaterialAttribute::OcclusionTexture, 5u}, {MaterialAttribute::OcclusionTexture, 5u},
{MaterialAttribute::OcclusionTextureCoordinates, 17u} {MaterialAttribute::OcclusionTextureCoordinates, 17u}
}}; }};
CORRADE_VERIFY(!data.hasCommonTextureTransformation()); CORRADE_VERIFY(!data.hasCommonTextureTransformation());
CORRADE_VERIFY(!data.hasCommonTextureCoordinates()); CORRADE_VERIFY(!data.hasCommonTextureCoordinates());
CORRADE_VERIFY(!data.hasCommonTextureLayer());
std::ostringstream out; std::ostringstream out;
Error redirectError{&out}; Error redirectError{&out};
data.commonTextureMatrix(); data.commonTextureMatrix();
data.commonTextureCoordinates(); data.commonTextureCoordinates();
data.commonTextureLayer();
CORRADE_COMPARE(out.str(), CORRADE_COMPARE(out.str(),
"Trade::PbrSpecularGlossinessMaterialData::commonTextureMatrix(): the material doesn't have a common texture coordinate transformation\n" "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");
} }
}}}} }}}}

106
src/Magnum/Trade/Test/PhongMaterialDataTest.cpp

@ -52,14 +52,14 @@ class PhongMaterialDataTest: public TestSuite::Tester {
void defaults(); void defaults();
void textured(); void textured();
void texturedDefaults(); void texturedDefaults();
void texturedSingleMatrixCoordinates(); void texturedSingleMatrixCoordinatesLayer();
void texturedImplicitPackedSpecularGlossiness(); void texturedImplicitPackedSpecularGlossiness();
void invalidTextures(); void invalidTextures();
void commonTransformationCoordinatesNoTextures(); void commonTransformationCoordinatesLayerNoTextures();
void commonTransformationCoordinatesOneTexture(); void commonTransformationCoordinatesLayerOneTexture();
void commonTransformationCoordinatesOneDifferentTexture(); void commonTransformationCoordinatesLayerOneDifferentTexture();
void commonCoordinatesImplicit(); void commonCoordinatesLayerImplicit();
void noCommonTransformationCoordinates(); void noCommonTransformationCoordinatesLayer();
#ifdef MAGNUM_BUILD_DEPRECATED #ifdef MAGNUM_BUILD_DEPRECATED
void debugFlag(); void debugFlag();
@ -90,19 +90,20 @@ PhongMaterialDataTest::PhongMaterialDataTest() {
&PhongMaterialDataTest::defaults, &PhongMaterialDataTest::defaults,
&PhongMaterialDataTest::textured, &PhongMaterialDataTest::textured,
&PhongMaterialDataTest::texturedDefaults, &PhongMaterialDataTest::texturedDefaults,
&PhongMaterialDataTest::texturedSingleMatrixCoordinates, &PhongMaterialDataTest::texturedSingleMatrixCoordinatesLayer,
&PhongMaterialDataTest::texturedImplicitPackedSpecularGlossiness, &PhongMaterialDataTest::texturedImplicitPackedSpecularGlossiness,
&PhongMaterialDataTest::invalidTextures, &PhongMaterialDataTest::invalidTextures,
&PhongMaterialDataTest::commonTransformationCoordinatesNoTextures}); &PhongMaterialDataTest::commonTransformationCoordinatesLayerNoTextures});
addInstancedTests({ addInstancedTests({
&PhongMaterialDataTest::commonTransformationCoordinatesOneTexture, &PhongMaterialDataTest::commonTransformationCoordinatesLayerOneTexture,
&PhongMaterialDataTest::commonTransformationCoordinatesOneDifferentTexture, &PhongMaterialDataTest::commonTransformationCoordinatesLayerOneDifferentTexture,
&PhongMaterialDataTest::commonCoordinatesImplicit}, &PhongMaterialDataTest::commonCoordinatesLayerImplicit},
Containers::arraySize(PhongTextureData)); Containers::arraySize(PhongTextureData));
addTests({ addTests({
&PhongMaterialDataTest::noCommonTransformationCoordinates, &PhongMaterialDataTest::noCommonTransformationCoordinatesLayer,
#ifdef MAGNUM_BUILD_DEPRECATED #ifdef MAGNUM_BUILD_DEPRECATED
&PhongMaterialDataTest::debugFlag, &PhongMaterialDataTest::debugFlag,
&PhongMaterialDataTest::debugFlags &PhongMaterialDataTest::debugFlags
@ -310,6 +311,7 @@ void PhongMaterialDataTest::basics() {
CORRADE_VERIFY(!data.hasSpecularTexture()); CORRADE_VERIFY(!data.hasSpecularTexture());
CORRADE_VERIFY(!data.hasTextureTransformation()); CORRADE_VERIFY(!data.hasTextureTransformation());
CORRADE_VERIFY(!data.hasTextureCoordinates()); CORRADE_VERIFY(!data.hasTextureCoordinates());
CORRADE_VERIFY(!data.hasTextureLayer());
CORRADE_COMPARE(data.ambientColor(), 0xccffbb_rgbf); CORRADE_COMPARE(data.ambientColor(), 0xccffbb_rgbf);
CORRADE_COMPARE(data.diffuseColor(), 0xebefbf_rgbf); CORRADE_COMPARE(data.diffuseColor(), 0xebefbf_rgbf);
CORRADE_COMPARE(data.specularColor(), 0xacabad_rgbf); CORRADE_COMPARE(data.specularColor(), 0xacabad_rgbf);
@ -325,6 +327,7 @@ void PhongMaterialDataTest::defaults() {
CORRADE_VERIFY(!data.hasTextureTransformation()); CORRADE_VERIFY(!data.hasTextureTransformation());
CORRADE_VERIFY(!data.hasTextureCoordinates()); CORRADE_VERIFY(!data.hasTextureCoordinates());
CORRADE_VERIFY(!data.hasTextureLayer());
CORRADE_COMPARE(data.ambientColor(), 0x000000_rgbf); CORRADE_COMPARE(data.ambientColor(), 0x000000_rgbf);
CORRADE_COMPARE(data.diffuseColor(), 0xffffff_rgbf); CORRADE_COMPARE(data.diffuseColor(), 0xffffff_rgbf);
CORRADE_COMPARE(data.specularColor(), 0xffffff00_rgbaf); CORRADE_COMPARE(data.specularColor(), 0xffffff00_rgbaf);
@ -337,43 +340,52 @@ void PhongMaterialDataTest::textured() {
{MaterialAttribute::AmbientTexture, 42u}, {MaterialAttribute::AmbientTexture, 42u},
{MaterialAttribute::AmbientTextureMatrix, Matrix3::scaling({0.5f, 1.0f})}, {MaterialAttribute::AmbientTextureMatrix, Matrix3::scaling({0.5f, 1.0f})},
{MaterialAttribute::AmbientTextureCoordinates, 2u}, {MaterialAttribute::AmbientTextureCoordinates, 2u},
{MaterialAttribute::AmbientTextureLayer, 6u},
{MaterialAttribute::DiffuseTexture, 33u}, {MaterialAttribute::DiffuseTexture, 33u},
{MaterialAttribute::DiffuseColor, 0xeebbffff_rgbaf}, {MaterialAttribute::DiffuseColor, 0xeebbffff_rgbaf},
{MaterialAttribute::DiffuseTextureMatrix, Matrix3::scaling({0.5f, 0.5f})}, {MaterialAttribute::DiffuseTextureMatrix, Matrix3::scaling({0.5f, 0.5f})},
{MaterialAttribute::DiffuseTextureCoordinates, 3u}, {MaterialAttribute::DiffuseTextureCoordinates, 3u},
{MaterialAttribute::DiffuseTextureLayer, 7u},
{MaterialAttribute::SpecularColor, 0xacabadff_rgbaf}, {MaterialAttribute::SpecularColor, 0xacabadff_rgbaf},
{MaterialAttribute::SpecularTexture, 17u}, {MaterialAttribute::SpecularTexture, 17u},
{MaterialAttribute::SpecularTextureSwizzle, MaterialTextureSwizzle::RGBA}, {MaterialAttribute::SpecularTextureSwizzle, MaterialTextureSwizzle::RGBA},
{MaterialAttribute::SpecularTextureMatrix, Matrix3::scaling({1.0f, 1.0f})}, {MaterialAttribute::SpecularTextureMatrix, Matrix3::scaling({1.0f, 1.0f})},
{MaterialAttribute::SpecularTextureCoordinates, 4u}, {MaterialAttribute::SpecularTextureCoordinates, 4u},
{MaterialAttribute::SpecularTextureLayer, 8u},
{MaterialAttribute::NormalTexture, 0u}, {MaterialAttribute::NormalTexture, 0u},
{MaterialAttribute::NormalTextureScale, 0.5f}, {MaterialAttribute::NormalTextureScale, 0.5f},
{MaterialAttribute::NormalTextureSwizzle, MaterialTextureSwizzle::GB}, {MaterialAttribute::NormalTextureSwizzle, MaterialTextureSwizzle::GB},
{MaterialAttribute::NormalTextureMatrix, Matrix3::scaling({1.0f, 0.5f})}, {MaterialAttribute::NormalTextureMatrix, Matrix3::scaling({1.0f, 0.5f})},
{MaterialAttribute::NormalTextureCoordinates, 5u} {MaterialAttribute::NormalTextureCoordinates, 5u},
{MaterialAttribute::NormalTextureLayer, 9u},
}}; }};
CORRADE_VERIFY(data.hasSpecularTexture()); CORRADE_VERIFY(data.hasSpecularTexture());
CORRADE_VERIFY(data.hasTextureTransformation()); CORRADE_VERIFY(data.hasTextureTransformation());
CORRADE_VERIFY(data.hasTextureCoordinates()); CORRADE_VERIFY(data.hasTextureCoordinates());
CORRADE_VERIFY(data.hasTextureLayer());
CORRADE_COMPARE(data.ambientColor(), 0x111111_rgbf); CORRADE_COMPARE(data.ambientColor(), 0x111111_rgbf);
CORRADE_COMPARE(data.ambientTexture(), 42); CORRADE_COMPARE(data.ambientTexture(), 42);
CORRADE_COMPARE(data.ambientTextureMatrix(), Matrix3::scaling({0.5f, 1.0f})); CORRADE_COMPARE(data.ambientTextureMatrix(), Matrix3::scaling({0.5f, 1.0f}));
CORRADE_COMPARE(data.ambientTextureCoordinates(), 2); CORRADE_COMPARE(data.ambientTextureCoordinates(), 2);
CORRADE_COMPARE(data.ambientTextureLayer(), 6);
CORRADE_COMPARE(data.diffuseColor(), 0xeebbff_rgbf); CORRADE_COMPARE(data.diffuseColor(), 0xeebbff_rgbf);
CORRADE_COMPARE(data.diffuseTexture(), 33); CORRADE_COMPARE(data.diffuseTexture(), 33);
CORRADE_COMPARE(data.diffuseTextureMatrix(), Matrix3::scaling({0.5f, 0.5f})); CORRADE_COMPARE(data.diffuseTextureMatrix(), Matrix3::scaling({0.5f, 0.5f}));
CORRADE_COMPARE(data.diffuseTextureCoordinates(), 3); CORRADE_COMPARE(data.diffuseTextureCoordinates(), 3);
CORRADE_COMPARE(data.diffuseTextureLayer(), 7);
CORRADE_COMPARE(data.specularColor(), 0xacabad_rgbf); CORRADE_COMPARE(data.specularColor(), 0xacabad_rgbf);
CORRADE_COMPARE(data.specularTexture(), 17); CORRADE_COMPARE(data.specularTexture(), 17);
CORRADE_COMPARE(data.specularTextureSwizzle(), MaterialTextureSwizzle::RGBA); CORRADE_COMPARE(data.specularTextureSwizzle(), MaterialTextureSwizzle::RGBA);
CORRADE_COMPARE(data.specularTextureMatrix(), Matrix3::scaling({1.0f, 1.0f})); CORRADE_COMPARE(data.specularTextureMatrix(), Matrix3::scaling({1.0f, 1.0f}));
CORRADE_COMPARE(data.specularTextureCoordinates(), 4); CORRADE_COMPARE(data.specularTextureCoordinates(), 4);
CORRADE_COMPARE(data.specularTextureLayer(), 8);
CORRADE_COMPARE(data.normalTexture(), 0); CORRADE_COMPARE(data.normalTexture(), 0);
CORRADE_COMPARE(data.normalTextureScale(), 0.5f); CORRADE_COMPARE(data.normalTextureScale(), 0.5f);
CORRADE_COMPARE(data.normalTextureSwizzle(), MaterialTextureSwizzle::GB); CORRADE_COMPARE(data.normalTextureSwizzle(), MaterialTextureSwizzle::GB);
CORRADE_COMPARE(data.normalTextureMatrix(), Matrix3::scaling({1.0f, 0.5f})); CORRADE_COMPARE(data.normalTextureMatrix(), Matrix3::scaling({1.0f, 0.5f}));
CORRADE_COMPARE(data.normalTextureCoordinates(), 5); CORRADE_COMPARE(data.normalTextureCoordinates(), 5);
CORRADE_COMPARE(data.normalTextureLayer(), 9);
} }
void PhongMaterialDataTest::texturedDefaults() { void PhongMaterialDataTest::texturedDefaults() {
@ -387,46 +399,57 @@ void PhongMaterialDataTest::texturedDefaults() {
CORRADE_VERIFY(data.hasSpecularTexture()); CORRADE_VERIFY(data.hasSpecularTexture());
CORRADE_VERIFY(!data.hasTextureTransformation()); CORRADE_VERIFY(!data.hasTextureTransformation());
CORRADE_VERIFY(!data.hasTextureCoordinates()); CORRADE_VERIFY(!data.hasTextureCoordinates());
CORRADE_VERIFY(!data.hasTextureLayer());
CORRADE_COMPARE(data.ambientColor(), 0xffffffff_rgbaf); CORRADE_COMPARE(data.ambientColor(), 0xffffffff_rgbaf);
CORRADE_COMPARE(data.ambientTexture(), 42); CORRADE_COMPARE(data.ambientTexture(), 42);
CORRADE_COMPARE(data.ambientTextureMatrix(), Matrix3{}); CORRADE_COMPARE(data.ambientTextureMatrix(), Matrix3{});
CORRADE_COMPARE(data.ambientTextureCoordinates(), 0); CORRADE_COMPARE(data.ambientTextureCoordinates(), 0);
CORRADE_COMPARE(data.ambientTextureLayer(), 0);
CORRADE_COMPARE(data.diffuseColor(), 0xffffffff_rgbaf); CORRADE_COMPARE(data.diffuseColor(), 0xffffffff_rgbaf);
CORRADE_COMPARE(data.diffuseTexture(), 33); CORRADE_COMPARE(data.diffuseTexture(), 33);
CORRADE_COMPARE(data.diffuseTextureMatrix(), Matrix3{}); CORRADE_COMPARE(data.diffuseTextureMatrix(), Matrix3{});
CORRADE_COMPARE(data.diffuseTextureCoordinates(), 0); CORRADE_COMPARE(data.diffuseTextureCoordinates(), 0);
CORRADE_COMPARE(data.diffuseTextureLayer(), 0);
CORRADE_COMPARE(data.specularColor(), 0xffffff00_rgbaf); CORRADE_COMPARE(data.specularColor(), 0xffffff00_rgbaf);
CORRADE_COMPARE(data.specularTexture(), 17); CORRADE_COMPARE(data.specularTexture(), 17);
CORRADE_COMPARE(data.specularTextureSwizzle(), MaterialTextureSwizzle::RGB); CORRADE_COMPARE(data.specularTextureSwizzle(), MaterialTextureSwizzle::RGB);
CORRADE_COMPARE(data.specularTextureMatrix(), Matrix3{}); CORRADE_COMPARE(data.specularTextureMatrix(), Matrix3{});
CORRADE_COMPARE(data.specularTextureCoordinates(), 0); CORRADE_COMPARE(data.specularTextureCoordinates(), 0);
CORRADE_COMPARE(data.specularTextureLayer(), 0);
CORRADE_COMPARE(data.normalTexture(), 1); CORRADE_COMPARE(data.normalTexture(), 1);
CORRADE_COMPARE(data.normalTextureScale(), 1.0f); CORRADE_COMPARE(data.normalTextureScale(), 1.0f);
CORRADE_COMPARE(data.normalTextureSwizzle(), MaterialTextureSwizzle::RGB); CORRADE_COMPARE(data.normalTextureSwizzle(), MaterialTextureSwizzle::RGB);
CORRADE_COMPARE(data.normalTextureMatrix(), Matrix3{}); CORRADE_COMPARE(data.normalTextureMatrix(), Matrix3{});
CORRADE_COMPARE(data.normalTextureCoordinates(), 0); CORRADE_COMPARE(data.normalTextureCoordinates(), 0);
CORRADE_COMPARE(data.normalTextureLayer(), 0);
} }
void PhongMaterialDataTest::texturedSingleMatrixCoordinates() { void PhongMaterialDataTest::texturedSingleMatrixCoordinatesLayer() {
PhongMaterialData data{{}, { PhongMaterialData data{{}, {
{MaterialAttribute::AmbientTexture, 42u}, {MaterialAttribute::AmbientTexture, 42u},
{MaterialAttribute::DiffuseTexture, 33u}, {MaterialAttribute::DiffuseTexture, 33u},
{MaterialAttribute::SpecularTexture, 17u}, {MaterialAttribute::SpecularTexture, 17u},
{MaterialAttribute::NormalTexture, 0u}, {MaterialAttribute::NormalTexture, 0u},
{MaterialAttribute::TextureMatrix, Matrix3::translation({0.5f, 1.0f})}, {MaterialAttribute::TextureMatrix, Matrix3::translation({0.5f, 1.0f})},
{MaterialAttribute::TextureCoordinates, 2u} {MaterialAttribute::TextureCoordinates, 2u},
{MaterialAttribute::TextureLayer, 17u},
}}; }};
CORRADE_VERIFY(data.hasTextureTransformation()); CORRADE_VERIFY(data.hasTextureTransformation());
CORRADE_VERIFY(data.hasTextureCoordinates()); CORRADE_VERIFY(data.hasTextureCoordinates());
CORRADE_VERIFY(data.hasTextureLayer());
CORRADE_COMPARE(data.ambientTextureMatrix(), Matrix3::translation({0.5f, 1.0f})); CORRADE_COMPARE(data.ambientTextureMatrix(), Matrix3::translation({0.5f, 1.0f}));
CORRADE_COMPARE(data.ambientTextureCoordinates(), 2); CORRADE_COMPARE(data.ambientTextureCoordinates(), 2);
CORRADE_COMPARE(data.ambientTextureLayer(), 17);
CORRADE_COMPARE(data.diffuseTextureMatrix(), Matrix3::translation({0.5f, 1.0f})); CORRADE_COMPARE(data.diffuseTextureMatrix(), Matrix3::translation({0.5f, 1.0f}));
CORRADE_COMPARE(data.diffuseTextureCoordinates(), 2); CORRADE_COMPARE(data.diffuseTextureCoordinates(), 2);
CORRADE_COMPARE(data.diffuseTextureLayer(), 17);
CORRADE_COMPARE(data.specularTextureMatrix(), Matrix3::translation({0.5f, 1.0f})); CORRADE_COMPARE(data.specularTextureMatrix(), Matrix3::translation({0.5f, 1.0f}));
CORRADE_COMPARE(data.specularTextureCoordinates(), 2); CORRADE_COMPARE(data.specularTextureCoordinates(), 2);
CORRADE_COMPARE(data.specularTextureLayer(), 17);
CORRADE_COMPARE(data.normalTextureMatrix(), Matrix3::translation({0.5f, 1.0f})); CORRADE_COMPARE(data.normalTextureMatrix(), Matrix3::translation({0.5f, 1.0f}));
CORRADE_COMPARE(data.normalTextureCoordinates(), 2); CORRADE_COMPARE(data.normalTextureCoordinates(), 2);
CORRADE_COMPARE(data.normalTextureLayer(), 17);
} }
void PhongMaterialDataTest::texturedImplicitPackedSpecularGlossiness() { void PhongMaterialDataTest::texturedImplicitPackedSpecularGlossiness() {
@ -435,6 +458,7 @@ void PhongMaterialDataTest::texturedImplicitPackedSpecularGlossiness() {
{MaterialAttribute::SpecularGlossinessTexture, 17u}, {MaterialAttribute::SpecularGlossinessTexture, 17u},
{MaterialAttribute::SpecularTextureMatrix, Matrix3::scaling({1.0f, 1.0f})}, {MaterialAttribute::SpecularTextureMatrix, Matrix3::scaling({1.0f, 1.0f})},
{MaterialAttribute::SpecularTextureCoordinates, 4u}, {MaterialAttribute::SpecularTextureCoordinates, 4u},
{MaterialAttribute::SpecularTextureLayer, 22u},
}}; }};
#ifdef MAGNUM_BUILD_DEPRECATED #ifdef MAGNUM_BUILD_DEPRECATED
@ -445,11 +469,13 @@ void PhongMaterialDataTest::texturedImplicitPackedSpecularGlossiness() {
CORRADE_VERIFY(data.hasSpecularTexture()); CORRADE_VERIFY(data.hasSpecularTexture());
CORRADE_VERIFY(data.hasTextureTransformation()); CORRADE_VERIFY(data.hasTextureTransformation());
CORRADE_VERIFY(data.hasTextureCoordinates()); CORRADE_VERIFY(data.hasTextureCoordinates());
CORRADE_VERIFY(data.hasTextureLayer());
CORRADE_COMPARE(data.specularColor(), 0xacabad_rgbf); CORRADE_COMPARE(data.specularColor(), 0xacabad_rgbf);
CORRADE_COMPARE(data.specularTexture(), 17); CORRADE_COMPARE(data.specularTexture(), 17);
CORRADE_COMPARE(data.specularTextureSwizzle(), MaterialTextureSwizzle::RGB); CORRADE_COMPARE(data.specularTextureSwizzle(), MaterialTextureSwizzle::RGB);
CORRADE_COMPARE(data.specularTextureMatrix(), Matrix3::scaling({1.0f, 1.0f})); CORRADE_COMPARE(data.specularTextureMatrix(), Matrix3::scaling({1.0f, 1.0f}));
CORRADE_COMPARE(data.specularTextureCoordinates(), 4); CORRADE_COMPARE(data.specularTextureCoordinates(), 4);
CORRADE_COMPARE(data.specularTextureLayer(), 22);
} }
void PhongMaterialDataTest::invalidTextures() { void PhongMaterialDataTest::invalidTextures() {
@ -464,42 +490,52 @@ void PhongMaterialDataTest::invalidTextures() {
data.ambientTexture(); data.ambientTexture();
data.ambientTextureMatrix(); data.ambientTextureMatrix();
data.ambientTextureCoordinates(); data.ambientTextureCoordinates();
data.ambientTextureLayer();
data.diffuseTexture(); data.diffuseTexture();
data.diffuseTextureMatrix(); data.diffuseTextureMatrix();
data.diffuseTextureCoordinates(); data.diffuseTextureCoordinates();
data.diffuseTextureLayer();
data.specularTexture(); data.specularTexture();
data.specularTextureSwizzle(); data.specularTextureSwizzle();
data.specularTextureMatrix(); data.specularTextureMatrix();
data.specularTextureCoordinates(); data.specularTextureCoordinates();
data.specularTextureLayer();
data.normalTexture(); data.normalTexture();
data.normalTextureScale(); data.normalTextureScale();
data.normalTextureSwizzle(); data.normalTextureSwizzle();
data.normalTextureMatrix(); data.normalTextureMatrix();
data.normalTextureCoordinates(); data.normalTextureCoordinates();
data.normalTextureLayer();
CORRADE_COMPARE(out.str(), CORRADE_COMPARE(out.str(),
"Trade::MaterialData::attribute(): attribute AmbientTexture not found in layer 0\n" "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::ambientTextureMatrix(): the material doesn't have an ambient texture\n"
"Trade::PhongMaterialData::ambientTextureCoordinates(): 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::MaterialData::attribute(): attribute DiffuseTexture not found in layer 0\n"
"Trade::PhongMaterialData::diffuseTextureMatrix(): the material doesn't have a diffuse texture\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::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::specularTexture(): the material doesn't have a specular texture\n"
"Trade::PhongMaterialData::specularTextureSwizzle(): 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::specularTextureMatrix(): the material doesn't have a specular texture\n"
"Trade::PhongMaterialData::specularTextureCoordinates(): 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::MaterialData::attribute(): attribute NormalTexture not found in layer 0\n"
"Trade::PhongMaterialData::normalTextureScale(): the material doesn't have a normal texture\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::normalTextureSwizzle(): the material doesn't have a normal texture\n"
"Trade::PhongMaterialData::normalTextureMatrix(): 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{{}, {}}; PhongMaterialData a{{}, {}};
CORRADE_VERIFY(a.hasCommonTextureTransformation()); CORRADE_VERIFY(a.hasCommonTextureTransformation());
CORRADE_VERIFY(a.hasCommonTextureCoordinates()); CORRADE_VERIFY(a.hasCommonTextureCoordinates());
CORRADE_VERIFY(a.hasCommonTextureLayer());
CORRADE_COMPARE(a.commonTextureMatrix(), Matrix3{}); CORRADE_COMPARE(a.commonTextureMatrix(), Matrix3{});
CORRADE_COMPARE(a.commonTextureCoordinates(), 0); CORRADE_COMPARE(a.commonTextureCoordinates(), 0);
CORRADE_COMPARE(a.commonTextureLayer(), 0);
#ifdef MAGNUM_BUILD_DEPRECATED #ifdef MAGNUM_BUILD_DEPRECATED
/* textureMatrix() should return the common matrix, if possible, and /* textureMatrix() should return the common matrix, if possible, and
@ -511,12 +547,15 @@ void PhongMaterialDataTest::commonTransformationCoordinatesNoTextures() {
PhongMaterialData b{{}, { PhongMaterialData b{{}, {
{MaterialAttribute::TextureMatrix, Matrix3::scaling({0.5f, 0.5f})}, {MaterialAttribute::TextureMatrix, Matrix3::scaling({0.5f, 0.5f})},
{MaterialAttribute::TextureCoordinates, 7u} {MaterialAttribute::TextureCoordinates, 7u},
{MaterialAttribute::TextureLayer, 22u},
}}; }};
CORRADE_VERIFY(b.hasCommonTextureTransformation()); CORRADE_VERIFY(b.hasCommonTextureTransformation());
CORRADE_VERIFY(b.hasCommonTextureCoordinates()); CORRADE_VERIFY(b.hasCommonTextureCoordinates());
CORRADE_VERIFY(b.hasCommonTextureLayer());
CORRADE_COMPARE(b.commonTextureMatrix(), Matrix3::scaling({0.5f, 0.5f})); CORRADE_COMPARE(b.commonTextureMatrix(), Matrix3::scaling({0.5f, 0.5f}));
CORRADE_COMPARE(b.commonTextureCoordinates(), 7); CORRADE_COMPARE(b.commonTextureCoordinates(), 7);
CORRADE_COMPARE(b.commonTextureLayer(), 22);
#ifdef MAGNUM_BUILD_DEPRECATED #ifdef MAGNUM_BUILD_DEPRECATED
/* textureMatrix() should return the common matrix, if possible, and /* textureMatrix() should return the common matrix, if possible, and
@ -527,7 +566,7 @@ void PhongMaterialDataTest::commonTransformationCoordinatesNoTextures() {
#endif #endif
} }
void PhongMaterialDataTest::commonTransformationCoordinatesOneTexture() { void PhongMaterialDataTest::commonTransformationCoordinatesLayerOneTexture() {
Containers::StringView textureName = PhongTextureData[testCaseInstanceId()]; Containers::StringView textureName = PhongTextureData[testCaseInstanceId()];
setTestCaseDescription(textureName); setTestCaseDescription(textureName);
@ -535,16 +574,20 @@ void PhongMaterialDataTest::commonTransformationCoordinatesOneTexture() {
{textureName, 5u}, {textureName, 5u},
{textureName + "Matrix", Matrix3::scaling({0.5f, 1.0f})}, {textureName + "Matrix", Matrix3::scaling({0.5f, 1.0f})},
{textureName + "Coordinates", 17u}, {textureName + "Coordinates", 17u},
{textureName + "Layer", 22u},
/* These shouldn't affect the above */ /* These shouldn't affect the above */
{MaterialAttribute::TextureMatrix, Matrix3::translation({0.5f, 0.0f})}, {MaterialAttribute::TextureMatrix, Matrix3::translation({0.5f, 0.0f})},
{MaterialAttribute::TextureCoordinates, 3u} {MaterialAttribute::TextureCoordinates, 3u},
{MaterialAttribute::TextureLayer, 66u},
}}; }};
CORRADE_VERIFY(data.hasCommonTextureTransformation()); CORRADE_VERIFY(data.hasCommonTextureTransformation());
CORRADE_COMPARE(data.commonTextureMatrix(), Matrix3::scaling({0.5f, 1.0f})); CORRADE_COMPARE(data.commonTextureMatrix(), Matrix3::scaling({0.5f, 1.0f}));
CORRADE_VERIFY(data.hasCommonTextureCoordinates()); CORRADE_VERIFY(data.hasCommonTextureCoordinates());
CORRADE_COMPARE(data.commonTextureCoordinates(), 17u); CORRADE_COMPARE(data.commonTextureCoordinates(), 17u);
CORRADE_VERIFY(data.hasCommonTextureLayer());
CORRADE_COMPARE(data.commonTextureLayer(), 22u);
#ifdef MAGNUM_BUILD_DEPRECATED #ifdef MAGNUM_BUILD_DEPRECATED
/* textureMatrix() should return the common matrix, if possible, and /* textureMatrix() should return the common matrix, if possible, and
@ -555,7 +598,7 @@ void PhongMaterialDataTest::commonTransformationCoordinatesOneTexture() {
#endif #endif
} }
void PhongMaterialDataTest::commonTransformationCoordinatesOneDifferentTexture() { void PhongMaterialDataTest::commonTransformationCoordinatesLayerOneDifferentTexture() {
Containers::StringView textureName = PhongTextureData[testCaseInstanceId()]; Containers::StringView textureName = PhongTextureData[testCaseInstanceId()];
setTestCaseDescription(textureName); setTestCaseDescription(textureName);
@ -566,15 +609,18 @@ void PhongMaterialDataTest::commonTransformationCoordinatesOneDifferentTexture()
{MaterialAttribute::NormalTexture, 5u}, {MaterialAttribute::NormalTexture, 5u},
{textureName + "Matrix", Matrix3::scaling({0.5f, 1.0f})}, {textureName + "Matrix", Matrix3::scaling({0.5f, 1.0f})},
{textureName + "Coordinates", 17u}, {textureName + "Coordinates", 17u},
{textureName + "Layer", 22u},
/* These are used by all textures except the one above, failing the /* These are used by all textures except the one above, failing the
check */ check */
{MaterialAttribute::TextureMatrix, Matrix3::translation({0.5f, 0.0f})}, {MaterialAttribute::TextureMatrix, Matrix3::translation({0.5f, 0.0f})},
{MaterialAttribute::TextureCoordinates, 3u} {MaterialAttribute::TextureCoordinates, 3u},
{MaterialAttribute::TextureLayer, 66u},
}}; }};
CORRADE_VERIFY(!data.hasCommonTextureTransformation()); CORRADE_VERIFY(!data.hasCommonTextureTransformation());
CORRADE_VERIFY(!data.hasCommonTextureCoordinates()); CORRADE_VERIFY(!data.hasCommonTextureCoordinates());
CORRADE_VERIFY(!data.hasCommonTextureLayer());
#ifdef MAGNUM_BUILD_DEPRECATED #ifdef MAGNUM_BUILD_DEPRECATED
/* textureMatrix() should return the common matrix, if possible, and /* textureMatrix() should return the common matrix, if possible, and
@ -585,7 +631,7 @@ void PhongMaterialDataTest::commonTransformationCoordinatesOneDifferentTexture()
#endif #endif
} }
void PhongMaterialDataTest::commonCoordinatesImplicit() { void PhongMaterialDataTest::commonCoordinatesLayerImplicit() {
Containers::StringView textureName = PhongTextureData[testCaseInstanceId()]; Containers::StringView textureName = PhongTextureData[testCaseInstanceId()];
setTestCaseDescription(textureName); setTestCaseDescription(textureName);
@ -594,16 +640,20 @@ void PhongMaterialDataTest::commonCoordinatesImplicit() {
PhongMaterialData data{{}, { PhongMaterialData data{{}, {
{textureName, 5u}, {textureName, 5u},
{textureName + "Coordinates", 0u} {textureName + "Coordinates", 0u},
{textureName + "Layer", 0u}
}}; }};
/* Zero is treated same as if there would be no attribute at all */ /* Zero is treated same as if there would be no attribute at all */
CORRADE_VERIFY(!data.hasTextureCoordinates()); CORRADE_VERIFY(!data.hasTextureCoordinates());
CORRADE_VERIFY(!data.hasTextureLayer());
CORRADE_VERIFY(data.hasCommonTextureCoordinates()); CORRADE_VERIFY(data.hasCommonTextureCoordinates());
CORRADE_VERIFY(data.hasCommonTextureLayer());
CORRADE_COMPARE(data.commonTextureCoordinates(), 0u); CORRADE_COMPARE(data.commonTextureCoordinates(), 0u);
CORRADE_COMPARE(data.commonTextureLayer(), 0u);
} }
void PhongMaterialDataTest::noCommonTransformationCoordinates() { void PhongMaterialDataTest::noCommonTransformationCoordinatesLayer() {
#ifdef CORRADE_NO_ASSERT #ifdef CORRADE_NO_ASSERT
CORRADE_SKIP("CORRADE_NO_ASSERT defined, can't test assertions"); CORRADE_SKIP("CORRADE_NO_ASSERT defined, can't test assertions");
#endif #endif
@ -614,20 +664,24 @@ void PhongMaterialDataTest::noCommonTransformationCoordinates() {
{MaterialAttribute::DiffuseTextureCoordinates, 3u}, {MaterialAttribute::DiffuseTextureCoordinates, 3u},
{MaterialAttribute::SpecularTexture, 4u}, {MaterialAttribute::SpecularTexture, 4u},
{MaterialAttribute::SpecularTextureMatrix, Matrix3::scaling({0.5f, 1.0f})}, {MaterialAttribute::SpecularTextureMatrix, Matrix3::scaling({0.5f, 1.0f})},
{MaterialAttribute::SpecularTextureLayer, 22u},
{MaterialAttribute::NormalTexture, 5u}, {MaterialAttribute::NormalTexture, 5u},
{MaterialAttribute::NormalTextureCoordinates, 17u} {MaterialAttribute::NormalTextureCoordinates, 17u}
}}; }};
CORRADE_VERIFY(!data.hasCommonTextureTransformation()); CORRADE_VERIFY(!data.hasCommonTextureTransformation());
CORRADE_VERIFY(!data.hasCommonTextureCoordinates()); CORRADE_VERIFY(!data.hasCommonTextureCoordinates());
CORRADE_VERIFY(!data.hasCommonTextureLayer());
std::ostringstream out; std::ostringstream out;
Error redirectError{&out}; Error redirectError{&out};
data.commonTextureMatrix(); data.commonTextureMatrix();
data.commonTextureCoordinates(); data.commonTextureCoordinates();
data.commonTextureLayer();
CORRADE_COMPARE(out.str(), CORRADE_COMPARE(out.str(),
"Trade::PhongMaterialData::commonTextureMatrix(): the material doesn't have a common texture coordinate transformation\n" "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 #ifdef MAGNUM_BUILD_DEPRECATED

Loading…
Cancel
Save