mirror of
https://github.com/overte-org/overte.git
synced 2025-08-04 07:03:41 +02:00
Move tex alpha detection to cv method
This commit is contained in:
parent
16c5971a7f
commit
fc8b34f8c7
2 changed files with 41 additions and 32 deletions
|
@ -83,41 +83,48 @@ void Material::setMetallic(float metallic) {
|
||||||
void Material::setTextureMap(MapChannel channel, const TextureMapPointer& textureMap) {
|
void Material::setTextureMap(MapChannel channel, const TextureMapPointer& textureMap) {
|
||||||
if (textureMap) {
|
if (textureMap) {
|
||||||
_key.setMapChannel(channel, (true));
|
_key.setMapChannel(channel, (true));
|
||||||
|
|
||||||
if (channel == MaterialKey::ALBEDO_MAP) {
|
|
||||||
// clear the previous flags whatever they were:
|
|
||||||
_key.setOpacityMaskMap(false);
|
|
||||||
_key.setTranslucentMap(false);
|
|
||||||
|
|
||||||
if (textureMap->useAlphaChannel() && textureMap->isDefined() && textureMap->getTextureView().isValid()) {
|
|
||||||
auto usage = textureMap->getTextureView()._texture->getUsage();
|
|
||||||
if (usage.isAlpha()) {
|
|
||||||
// Texture has alpha, is not just a mask or a true transparent channel
|
|
||||||
if (usage.isAlphaMask()) {
|
|
||||||
_key.setOpacityMaskMap(true);
|
|
||||||
_key.setTranslucentMap(false);
|
|
||||||
} else {
|
|
||||||
_key.setOpacityMaskMap(false);
|
|
||||||
_key.setTranslucentMap(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
_textureMaps[channel] = textureMap;
|
_textureMaps[channel] = textureMap;
|
||||||
} else {
|
} else {
|
||||||
_key.setMapChannel(channel, (false));
|
_key.setMapChannel(channel, (false));
|
||||||
|
|
||||||
if (channel == MaterialKey::ALBEDO_MAP) {
|
|
||||||
_key.setOpacityMaskMap(false);
|
|
||||||
_key.setTranslucentMap(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
_textureMaps.erase(channel);
|
_textureMaps.erase(channel);
|
||||||
}
|
}
|
||||||
|
|
||||||
_schemaBuffer.edit<Schema>()._key = (uint32)_key._flags.to_ulong();
|
_schemaBuffer.edit<Schema>()._key = (uint32)_key._flags.to_ulong();
|
||||||
|
|
||||||
|
if (channel == MaterialKey::ALBEDO_MAP) {
|
||||||
|
resetOpacityMap();
|
||||||
|
}
|
||||||
|
|
||||||
|
_schemaBuffer.edit<Schema>()._key = (uint32)_key._flags.to_ulong();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void Material::resetOpacityMap() const {
|
||||||
|
// Clear the previous flags
|
||||||
|
_key.setOpacityMaskMap(false);
|
||||||
|
_key.setTranslucentMap(false);
|
||||||
|
|
||||||
|
const auto& textureMap = getTextureMap(MaterialKey::ALBEDO_MAP);
|
||||||
|
if (textureMap &&
|
||||||
|
textureMap->useAlphaChannel() &&
|
||||||
|
textureMap->isDefined() &&
|
||||||
|
textureMap->getTextureView().isValid()) {
|
||||||
|
|
||||||
|
auto usage = textureMap->getTextureView()._texture->getUsage();
|
||||||
|
if (usage.isAlpha()) {
|
||||||
|
if (usage.isAlphaMask()) {
|
||||||
|
// Texture has alpha, but it is just a mask
|
||||||
|
_key.setOpacityMaskMap(true);
|
||||||
|
_key.setTranslucentMap(false);
|
||||||
|
} else {
|
||||||
|
// Texture has alpha, it is a true translucency channel
|
||||||
|
_key.setOpacityMaskMap(false);
|
||||||
|
_key.setTranslucentMap(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_schemaBuffer.edit<Schema>()._key = (uint32)_key._flags.to_ulong();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -291,15 +291,17 @@ public:
|
||||||
const TextureMaps& getTextureMaps() const { return _textureMaps; }
|
const TextureMaps& getTextureMaps() const { return _textureMaps; }
|
||||||
const TextureMapPointer getTextureMap(MapChannel channel) const;
|
const TextureMapPointer getTextureMap(MapChannel channel) const;
|
||||||
|
|
||||||
|
// Albedo maps cannot have opacity detected until they are loaded
|
||||||
|
// This method allows const changing of the key/schemaBuffer without touching the map
|
||||||
|
void resetOpacityMap() const;
|
||||||
|
|
||||||
// conversion from legacy material properties to PBR equivalent
|
// conversion from legacy material properties to PBR equivalent
|
||||||
static float shininessToRoughness(float shininess) { return 1.0f - shininess / 100.0f; }
|
static float shininessToRoughness(float shininess) { return 1.0f - shininess / 100.0f; }
|
||||||
|
|
||||||
protected:
|
private:
|
||||||
|
mutable MaterialKey _key;
|
||||||
MaterialKey _key;
|
mutable UniformBufferView _schemaBuffer;
|
||||||
UniformBufferView _schemaBuffer;
|
|
||||||
TextureMaps _textureMaps;
|
TextureMaps _textureMaps;
|
||||||
|
|
||||||
};
|
};
|
||||||
typedef std::shared_ptr< Material > MaterialPointer;
|
typedef std::shared_ptr< Material > MaterialPointer;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue