mirror of
https://github.com/overte-org/overte.git
synced 2025-04-20 04:44:11 +02:00
Merge branch 'orange' of github.com:samcake/hifi
This commit is contained in:
commit
5361c3d6a4
15 changed files with 162 additions and 65 deletions
|
@ -1102,8 +1102,9 @@ FBXGeometry* FBXReader::extractFBXGeometry(const QVariantHash& mapping, const QS
|
|||
diffuseTextures.insert(getID(connection.properties, 2), getID(connection.properties, 1));
|
||||
} else if (type.contains("tex_color_map")) {
|
||||
diffuseTextures.insert(getID(connection.properties, 2), getID(connection.properties, 1));
|
||||
} else if (type.contains("transparentcolor")) { // it should be TransparentColor...
|
||||
// THis is how Maya assign a texture that affect diffuse color AND transparency ?
|
||||
} else if (type.contains("transparentcolor")) { // Maya way of passing TransparentMap
|
||||
transparentTextures.insert(getID(connection.properties, 2), getID(connection.properties, 1));
|
||||
} else if (type.contains("transparencyfactor")) { // Blender way of passing TransparentMap
|
||||
transparentTextures.insert(getID(connection.properties, 2), getID(connection.properties, 1));
|
||||
} else if (type.contains("bump")) {
|
||||
bumpTextures.insert(getID(connection.properties, 2), getID(connection.properties, 1));
|
||||
|
|
|
@ -102,16 +102,20 @@ void FBXReader::consolidateFBXMaterials() {
|
|||
detectDifferentUVs = (diffuseTexture.texcoordSet != 0) || (!diffuseTexture.transform.isIdentity());
|
||||
}
|
||||
|
||||
|
||||
FBXTexture transparentTexture;
|
||||
QString transparentTextureID = transparentTextures.value(material.materialID);
|
||||
// If PBS Material, systematically bind the albedo texture as transparency texture and check for the alpha channel
|
||||
if (material.isPBSMaterial) {
|
||||
transparentTextureID = diffuseTextureID;
|
||||
}
|
||||
if (!transparentTextureID.isNull()) {
|
||||
transparentTexture = getTexture(transparentTextureID);
|
||||
|
||||
material.opacityTexture = transparentTexture;
|
||||
detectDifferentUVs |= (transparentTexture.texcoordSet != 0) || (!transparentTexture.transform.isIdentity());
|
||||
}
|
||||
|
||||
|
||||
|
||||
FBXTexture normalTexture;
|
||||
QString bumpTextureID = bumpTextures.value(material.materialID);
|
||||
QString normalTextureID = normalTextures.value(material.materialID);
|
||||
|
|
|
@ -152,11 +152,10 @@ bool NetworkGeometry::isLoadedWithTextures() const {
|
|||
return false;
|
||||
}
|
||||
if (material->albedoTexture && material->albedoTexture->getGPUTexture()) {
|
||||
// Reset the materialKey transparentTexture key only, as it is albedoTexture-dependent
|
||||
// Reassign the texture to make sure that itsalbedo alpha channel material key is detected correctly
|
||||
material->_material->setTextureMap(model::MaterialKey::ALBEDO_MAP, material->_material->getTextureMap(model::MaterialKey::ALBEDO_MAP));
|
||||
const auto& usage = material->albedoTexture->getGPUTexture()->getUsage();
|
||||
bool isTransparentTexture = usage.isAlpha() && !usage.isAlphaMask();
|
||||
material->_material->setTransparentTexture(isTransparentTexture);
|
||||
// FIXME: Materials with *some* transparent textures seem to give all *other* textures alphas of 0.
|
||||
_hasTransparentTextures = isTransparentTexture && _hasTransparentTextures;
|
||||
}
|
||||
}
|
||||
|
@ -212,10 +211,10 @@ void NetworkGeometry::setTextureWithNameToURL(const QString& name, const QUrl& u
|
|||
|
||||
networkMaterial->setTextureMap(model::MaterialKey::EMISSIVE_MAP, emissiveMap);
|
||||
} else if (material->lightmapTextureName == name) {
|
||||
material->emissiveTexture = textureCache->getTexture(url, LIGHTMAP_TEXTURE);
|
||||
material->lightmapTexture = textureCache->getTexture(url, LIGHTMAP_TEXTURE);
|
||||
|
||||
auto lightmapMap = model::TextureMapPointer(new model::TextureMap());
|
||||
lightmapMap->setTextureSource(material->emissiveTexture->_textureSource);
|
||||
lightmapMap->setTextureSource(material->lightmapTexture->_textureSource);
|
||||
lightmapMap->setTextureTransform(
|
||||
oldTextureMaps[model::MaterialKey::LIGHTMAP_MAP]->getTextureTransform());
|
||||
glm::vec2 oldOffsetScale =
|
||||
|
@ -380,9 +379,20 @@ static NetworkMaterial* buildNetworkMaterial(NetworkGeometry* geometry, const FB
|
|||
auto albedoMap = setupNetworkTextureMap(geometry, textureBaseUrl, material.albedoTexture, DEFAULT_TEXTURE,
|
||||
networkMaterial->albedoTexture, networkMaterial->albedoTextureName);
|
||||
albedoMap->setTextureTransform(material.albedoTexture.transform);
|
||||
|
||||
if (!material.opacityTexture.filename.isEmpty()) {
|
||||
if (material.albedoTexture.filename == material.opacityTexture.filename) {
|
||||
// Best case scenario, just indicating that the albedo map contains transparency
|
||||
albedoMap->setUseAlphaChannel(true);
|
||||
} else {
|
||||
// Opacity Map is different from the Abledo map, not supported
|
||||
}
|
||||
}
|
||||
|
||||
material._material->setTextureMap(model::MaterialKey::ALBEDO_MAP, albedoMap);
|
||||
}
|
||||
|
||||
|
||||
if (!material.normalTexture.filename.isEmpty()) {
|
||||
auto normalMap = setupNetworkTextureMap(geometry, textureBaseUrl, material.normalTexture,
|
||||
(material.normalTexture.isBumpmap ? BUMP_TEXTURE : NORMAL_TEXTURE),
|
||||
|
|
|
@ -199,7 +199,6 @@ public:
|
|||
QSharedPointer<NetworkTexture> occlusionTexture;
|
||||
QString lightmapTextureName;
|
||||
QSharedPointer<NetworkTexture> lightmapTexture;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -51,7 +51,7 @@ void Material::setEmissive(const Color& emissive, bool isSRGB) {
|
|||
}
|
||||
|
||||
void Material::setOpacity(float opacity) {
|
||||
_key.setTransparent((opacity < 1.0f));
|
||||
_key.setTranslucentFactor((opacity < 1.0f));
|
||||
_schemaBuffer.edit<Schema>()._key = (uint32)_key._flags.to_ulong();
|
||||
_schemaBuffer.edit<Schema>()._opacity = opacity;
|
||||
}
|
||||
|
@ -80,19 +80,56 @@ void Material::setMetallic(float metallic) {
|
|||
_schemaBuffer.edit<Schema>()._metallic = metallic;
|
||||
}
|
||||
|
||||
void Material::setTransparentTexture(bool isTransparent) {
|
||||
_key.setTransparentTexture(isTransparent);
|
||||
_schemaBuffer.edit<Schema>()._key = (uint32)_key._flags.to_ulong();
|
||||
}
|
||||
|
||||
void Material::setTextureMap(MapChannel channel, const TextureMapPointer& textureMap) {
|
||||
if (textureMap) {
|
||||
_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()) {
|
||||
if (textureMap->isDefined()) {
|
||||
if (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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_schemaBuffer.edit<Schema>()._key = (uint32)_key._flags.to_ulong();
|
||||
_textureMaps[channel] = textureMap;
|
||||
} else {
|
||||
_key.setMapChannel(channel, (false));
|
||||
|
||||
if (channel == MaterialKey::ALBEDO_MAP) {
|
||||
_key.setOpacityMaskMap(false);
|
||||
_key.setTranslucentMap(false);
|
||||
}
|
||||
|
||||
_schemaBuffer.edit<Schema>()._key = (uint32)_key._flags.to_ulong();
|
||||
_textureMaps.erase(channel);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
const TextureMapPointer Material::getTextureMap(MapChannel channel) const {
|
||||
auto result = _textureMaps.find(channel);
|
||||
if (result != _textureMaps.end()) {
|
||||
return (result->second);
|
||||
} else {
|
||||
return TextureMapPointer();
|
||||
}
|
||||
}
|
|
@ -31,14 +31,15 @@ public:
|
|||
ALBEDO_VAL_BIT,
|
||||
METALLIC_VAL_BIT,
|
||||
GLOSSY_VAL_BIT,
|
||||
TRANSPARENT_VAL_BIT,
|
||||
TRANSPARENT_TEX_VAL_BIT,
|
||||
OPACITY_VAL_BIT,
|
||||
OPACITY_MASK_MAP_BIT, // OPacity Map and Opacity MASK map are mutually exclusive
|
||||
OPACITY_TRANSLUCENT_MAP_BIT,
|
||||
|
||||
// THe map bits must be in the smae sequence as the enum names for the map channels
|
||||
EMISSIVE_MAP_BIT,
|
||||
ALBEDO_MAP_BIT,
|
||||
METALLIC_MAP_BIT,
|
||||
ROUGHNESS_MAP_BIT,
|
||||
TRANSPARENT_MAP_BIT,
|
||||
NORMAL_MAP_BIT,
|
||||
OCCLUSION_MAP_BIT,
|
||||
LIGHTMAP_MAP_BIT,
|
||||
|
@ -52,7 +53,6 @@ public:
|
|||
ALBEDO_MAP,
|
||||
METALLIC_MAP,
|
||||
ROUGHNESS_MAP,
|
||||
TRANSPARENT_MAP,
|
||||
NORMAL_MAP,
|
||||
OCCLUSION_MAP,
|
||||
LIGHTMAP_MAP,
|
||||
|
@ -77,13 +77,15 @@ public:
|
|||
Builder& withAlbedo() { _flags.set(ALBEDO_VAL_BIT); return (*this); }
|
||||
Builder& withMetallic() { _flags.set(METALLIC_VAL_BIT); return (*this); }
|
||||
Builder& withGlossy() { _flags.set(GLOSSY_VAL_BIT); return (*this); }
|
||||
Builder& withTransparent() { _flags.set(TRANSPARENT_VAL_BIT); return (*this); }
|
||||
Builder& withTranslucentFactor() { _flags.set(OPACITY_VAL_BIT); return (*this); }
|
||||
|
||||
Builder& withEmissiveMap() { _flags.set(EMISSIVE_MAP_BIT); return (*this); }
|
||||
Builder& withAlbedoMap() { _flags.set(ALBEDO_MAP_BIT); return (*this); }
|
||||
Builder& withMetallicMap() { _flags.set(METALLIC_MAP_BIT); return (*this); }
|
||||
Builder& withRoughnessMap() { _flags.set(ROUGHNESS_MAP_BIT); return (*this); }
|
||||
Builder& withTransparentMap() { _flags.set(TRANSPARENT_MAP_BIT); return (*this); }
|
||||
|
||||
Builder& withTranslucentMap() { _flags.set(OPACITY_TRANSLUCENT_MAP_BIT); return (*this); }
|
||||
Builder& withMaskMap() { _flags.set(OPACITY_MASK_MAP_BIT); return (*this); }
|
||||
|
||||
Builder& withNormalMap() { _flags.set(NORMAL_MAP_BIT); return (*this); }
|
||||
Builder& withOcclusionMap() { _flags.set(OCCLUSION_MAP_BIT); return (*this); }
|
||||
|
@ -102,9 +104,6 @@ public:
|
|||
void setAlbedo(bool value) { _flags.set(ALBEDO_VAL_BIT, value); }
|
||||
bool isAlbedo() const { return _flags[ALBEDO_VAL_BIT]; }
|
||||
|
||||
void setTransparentTexture(bool value) { _flags.set(TRANSPARENT_TEX_VAL_BIT, value); }
|
||||
bool isTransparentTexture() const { return _flags[TRANSPARENT_TEX_VAL_BIT]; }
|
||||
|
||||
void setAlbedoMap(bool value) { _flags.set(ALBEDO_MAP_BIT, value); }
|
||||
bool isAlbedoMap() const { return _flags[ALBEDO_MAP_BIT]; }
|
||||
|
||||
|
@ -121,13 +120,15 @@ public:
|
|||
void setRoughnessMap(bool value) { _flags.set(ROUGHNESS_MAP_BIT, value); }
|
||||
bool isRoughnessMap() const { return _flags[ROUGHNESS_MAP_BIT]; }
|
||||
|
||||
void setTransparent(bool value) { _flags.set(TRANSPARENT_VAL_BIT, value); }
|
||||
bool isTransparent() const { return _flags[TRANSPARENT_VAL_BIT]; }
|
||||
bool isOpaque() const { return !_flags[TRANSPARENT_VAL_BIT]; }
|
||||
void setTranslucentFactor(bool value) { _flags.set(OPACITY_VAL_BIT, value); }
|
||||
bool isTranslucentFactor() const { return _flags[OPACITY_VAL_BIT]; }
|
||||
|
||||
void setTransparentMap(bool value) { _flags.set(TRANSPARENT_MAP_BIT, value); }
|
||||
bool isTransparentMap() const { return _flags[TRANSPARENT_MAP_BIT]; }
|
||||
void setTranslucentMap(bool value) { _flags.set(OPACITY_TRANSLUCENT_MAP_BIT, value); }
|
||||
bool isTranslucentMap() const { return _flags[OPACITY_TRANSLUCENT_MAP_BIT]; }
|
||||
|
||||
void setOpacityMaskMap(bool value) { _flags.set(OPACITY_MASK_MAP_BIT, value); }
|
||||
bool isOpacityMaskMap() const { return _flags[OPACITY_MASK_MAP_BIT]; }
|
||||
|
||||
void setNormalMap(bool value) { _flags.set(NORMAL_MAP_BIT, value); }
|
||||
bool isNormalMap() const { return _flags[NORMAL_MAP_BIT]; }
|
||||
|
||||
|
@ -140,6 +141,12 @@ public:
|
|||
void setMapChannel(MapChannel channel, bool value) { _flags.set(EMISSIVE_MAP_BIT + channel, value); }
|
||||
bool isMapChannel(MapChannel channel) const { return _flags[EMISSIVE_MAP_BIT + channel]; }
|
||||
|
||||
|
||||
// Translucency and Opacity Heuristics are combining several flags:
|
||||
bool isTranslucent() const { return isTranslucentFactor() || isTranslucentMap(); }
|
||||
bool isOpaque() const { return !isTranslucent(); }
|
||||
bool isSurfaceOpaque() const { return isOpaque() && !isOpacityMaskMap(); }
|
||||
bool isTexelOpaque() const { return isOpaque() && isOpacityMaskMap(); }
|
||||
};
|
||||
|
||||
|
||||
|
@ -168,9 +175,6 @@ public:
|
|||
Builder& withoutAlbedo() { _value.reset(MaterialKey::ALBEDO_VAL_BIT); _mask.set(MaterialKey::ALBEDO_VAL_BIT); return (*this); }
|
||||
Builder& withAlbedo() { _value.set(MaterialKey::ALBEDO_VAL_BIT); _mask.set(MaterialKey::ALBEDO_VAL_BIT); return (*this); }
|
||||
|
||||
Builder& withoutTransparentTexture() { _value.reset(MaterialKey::TRANSPARENT_TEX_VAL_BIT); _mask.set(MaterialKey::TRANSPARENT_TEX_VAL_BIT); return (*this); }
|
||||
Builder& withTransparentTexture() { _value.set(MaterialKey::TRANSPARENT_TEX_VAL_BIT); _mask.set(MaterialKey::TRANSPARENT_TEX_VAL_BIT); return (*this); }
|
||||
|
||||
Builder& withoutAlbedoMap() { _value.reset(MaterialKey::ALBEDO_MAP_BIT); _mask.set(MaterialKey::ALBEDO_MAP_BIT); return (*this); }
|
||||
Builder& withAlbedoMap() { _value.set(MaterialKey::ALBEDO_MAP_BIT); _mask.set(MaterialKey::ALBEDO_MAP_BIT); return (*this); }
|
||||
|
||||
|
@ -186,11 +190,14 @@ public:
|
|||
Builder& withoutRoughnessMap() { _value.reset(MaterialKey::ROUGHNESS_MAP_BIT); _mask.set(MaterialKey::ROUGHNESS_MAP_BIT); return (*this); }
|
||||
Builder& withRoughnessMap() { _value.set(MaterialKey::ROUGHNESS_MAP_BIT); _mask.set(MaterialKey::ROUGHNESS_MAP_BIT); return (*this); }
|
||||
|
||||
Builder& withoutTransparent() { _value.reset(MaterialKey::TRANSPARENT_VAL_BIT); _mask.set(MaterialKey::TRANSPARENT_VAL_BIT); return (*this); }
|
||||
Builder& withTransparent() { _value.set(MaterialKey::TRANSPARENT_VAL_BIT); _mask.set(MaterialKey::TRANSPARENT_VAL_BIT); return (*this); }
|
||||
Builder& withoutTranslucentFactor() { _value.reset(MaterialKey::OPACITY_VAL_BIT); _mask.set(MaterialKey::OPACITY_VAL_BIT); return (*this); }
|
||||
Builder& withTranslucentFactor() { _value.set(MaterialKey::OPACITY_VAL_BIT); _mask.set(MaterialKey::OPACITY_VAL_BIT); return (*this); }
|
||||
|
||||
Builder& withoutTransparentMap() { _value.reset(MaterialKey::TRANSPARENT_MAP_BIT); _mask.set(MaterialKey::TRANSPARENT_MAP_BIT); return (*this); }
|
||||
Builder& withTransparentMap() { _value.set(MaterialKey::TRANSPARENT_MAP_BIT); _mask.set(MaterialKey::TRANSPARENT_MAP_BIT); return (*this); }
|
||||
Builder& withoutTranslucentMap() { _value.reset(MaterialKey::OPACITY_TRANSLUCENT_MAP_BIT); _mask.set(MaterialKey::OPACITY_TRANSLUCENT_MAP_BIT); return (*this); }
|
||||
Builder& withTranslucentMap() { _value.set(MaterialKey::OPACITY_TRANSLUCENT_MAP_BIT); _mask.set(MaterialKey::OPACITY_TRANSLUCENT_MAP_BIT); return (*this); }
|
||||
|
||||
Builder& withoutMaskMap() { _value.reset(MaterialKey::OPACITY_MASK_MAP_BIT); _mask.set(MaterialKey::OPACITY_MASK_MAP_BIT); return (*this); }
|
||||
Builder& withMaskMap() { _value.set(MaterialKey::OPACITY_MASK_MAP_BIT); _mask.set(MaterialKey::OPACITY_MASK_MAP_BIT); return (*this); }
|
||||
|
||||
Builder& withoutNormalMap() { _value.reset(MaterialKey::NORMAL_MAP_BIT); _mask.set(MaterialKey::NORMAL_MAP_BIT); return (*this); }
|
||||
Builder& withNormalMap() { _value.set(MaterialKey::NORMAL_MAP_BIT); _mask.set(MaterialKey::NORMAL_MAP_BIT); return (*this); }
|
||||
|
@ -202,7 +209,7 @@ public:
|
|||
Builder& withLightmapMap() { _value.set(MaterialKey::LIGHTMAP_MAP_BIT); _mask.set(MaterialKey::LIGHTMAP_MAP_BIT); return (*this); }
|
||||
|
||||
// Convenient standard keys that we will keep on using all over the place
|
||||
static MaterialFilter opaqueAlbedo() { return Builder().withAlbedo().withoutTransparent().build(); }
|
||||
static MaterialFilter opaqueAlbedo() { return Builder().withAlbedo().withoutTranslucentFactor().build(); }
|
||||
};
|
||||
|
||||
// Item Filter operator testing if a key pass the filter
|
||||
|
@ -255,7 +262,6 @@ public:
|
|||
void setRoughness(float roughness);
|
||||
float getRoughness() const { return _schemaBuffer.get<Schema>()._roughness; }
|
||||
|
||||
void setTransparentTexture(bool isTransparent);
|
||||
|
||||
// Schema to access the attribute values of the material
|
||||
class Schema {
|
||||
|
@ -283,6 +289,7 @@ public:
|
|||
// The texture map to channel association
|
||||
void setTextureMap(MapChannel channel, const TextureMapPointer& textureMap);
|
||||
const TextureMaps& getTextureMaps() const { return _textureMaps; }
|
||||
const TextureMapPointer getTextureMap(MapChannel channel) const;
|
||||
|
||||
// conversion from legacy material properties to PBR equivalent
|
||||
static float shininessToRoughness(float shininess) { return 1.0f - shininess / 100.0f; }
|
||||
|
|
|
@ -39,21 +39,21 @@ float getMaterialShininess(Material m) { return 1.0 - getMaterialRoughness(m); }
|
|||
|
||||
int getMaterialKey(Material m) { return floatBitsToInt(m._spareKey.w); }
|
||||
|
||||
const int EMISSIVE_VAL_BIT = 0x00000001;
|
||||
const int ALBEDO_VAL_BIT = 0x00000002;
|
||||
const int METALLIC_VAL_BIT = 0x00000004;
|
||||
const int GLOSSY_VAL_BIT = 0x00000008;
|
||||
const int TRANSPARENT_VAL_BIT = 0x00000010;
|
||||
const int TRANSPARENT_TEX_VAL_BIT = 0x00000020;
|
||||
const int EMISSIVE_VAL_BIT = 0x00000001;
|
||||
const int ALBEDO_VAL_BIT = 0x00000002;
|
||||
const int METALLIC_VAL_BIT = 0x00000004;
|
||||
const int GLOSSY_VAL_BIT = 0x00000008;
|
||||
const int OPACITY_VAL_BIT = 0x00000010;
|
||||
const int OPACITY_MASK_MAP_BIT = 0x00000020;
|
||||
const int OPACITY_TRANSLUCENT_MAP_BIT = 0x00000040;
|
||||
|
||||
const int EMISSIVE_MAP_BIT = 0x00000040;
|
||||
const int ALBEDO_MAP_BIT = 0x00000080;
|
||||
const int METALLIC_MAP_BIT = 0x00000100;
|
||||
const int ROUGHNESS_MAP_BIT = 0x00000200;
|
||||
const int TRANSPARENT_MAP_BIT = 0x00000400;
|
||||
const int NORMAL_MAP_BIT = 0x00000800;
|
||||
const int OCCLUSION_MAP_BIT = 0x00001000;
|
||||
const int EMISSIVE_MAP_BIT = 0x00000080;
|
||||
const int ALBEDO_MAP_BIT = 0x00000100;
|
||||
const int METALLIC_MAP_BIT = 0x00000200;
|
||||
const int ROUGHNESS_MAP_BIT = 0x00000400;
|
||||
const int NORMAL_MAP_BIT = 0x00000800;
|
||||
const int OCCLUSION_MAP_BIT = 0x00001000;
|
||||
const int LIGHTMAP_MAP_BIT = 0x00002000;
|
||||
|
||||
const int LIGHTMAP_MAP_BIT = 0x00002000;
|
||||
|
||||
<@endif@>
|
||||
|
|
|
@ -56,6 +56,9 @@ public:
|
|||
void setTextureTransform(const Transform& texcoordTransform);
|
||||
const Transform& getTextureTransform() const { return _texcoordTransform; }
|
||||
|
||||
void setUseAlphaChannel(bool useAlpha) { _useAlphaChannel = useAlpha; }
|
||||
bool useAlphaChannel() const { return _useAlphaChannel; }
|
||||
|
||||
void setLightmapOffsetScale(float offset, float scale);
|
||||
const glm::vec2& getLightmapOffsetScale() const { return _lightmapOffsetScale; }
|
||||
|
||||
|
@ -64,6 +67,8 @@ protected:
|
|||
|
||||
Transform _texcoordTransform;
|
||||
glm::vec2 _lightmapOffsetScale{ 0.0f, 1.0f };
|
||||
|
||||
bool _useAlphaChannel{ false };
|
||||
};
|
||||
typedef std::shared_ptr< TextureMap > TextureMapPointer;
|
||||
|
||||
|
|
|
@ -59,7 +59,7 @@ float fetchOcclusionMap(vec2 uv) {
|
|||
|
||||
<@func fetchMaterialTextures(matKey, texcoord0, albedo, roughness, normal, metallic, emissive, occlusion)@>
|
||||
<@if albedo@>
|
||||
vec4 <$albedo$> = (((<$matKey$> & ALBEDO_MAP_BIT) != 0) ? fetchAlbedoMap(<$texcoord0$>) : vec4(1.0));
|
||||
vec4 <$albedo$> = (((<$matKey$> & (ALBEDO_MAP_BIT | OPACITY_MASK_MAP_BIT | OPACITY_TRANSLUCENT_MAP_BIT)) != 0) ? fetchAlbedoMap(<$texcoord0$>) : vec4(1.0));
|
||||
<@endif@>
|
||||
<@if roughness@>
|
||||
float <$roughness$> = (((<$matKey$> & ROUGHNESS_MAP_BIT) != 0) ? fetchRoughnessMap(<$texcoord0$>) : 1.0);
|
||||
|
@ -112,6 +112,23 @@ vec3 fetchLightmapMap(vec2 uv) {
|
|||
}
|
||||
<@endfunc@>
|
||||
|
||||
<@func evalMaterialOpacity(fetchedOpacity, materialOpacity, matKey, opacity)@>
|
||||
{
|
||||
const float OPACITY_MASK_THRESHOLD = 0.5;
|
||||
<$opacity$> = (((<$matKey$> & (OPACITY_TRANSLUCENT_MAP_BIT | OPACITY_MASK_MAP_BIT)) != 0) ?
|
||||
(((<$matKey$> & OPACITY_MASK_MAP_BIT) != 0) ? step(OPACITY_MASK_THRESHOLD, <$fetchedOpacity$>) : <$fetchedOpacity$>) :
|
||||
1.0) * <$materialOpacity$>;
|
||||
}
|
||||
<@endfunc@>
|
||||
|
||||
<@func $discardTransparent(opacity)@>
|
||||
{
|
||||
if (<$opacity$> < 1.0) {
|
||||
discard;
|
||||
}
|
||||
}
|
||||
<@endfunc@>
|
||||
|
||||
<@func evalMaterialRoughness(fetchedRoughness, materialRoughness, matKey, roughness)@>
|
||||
{
|
||||
<$roughness$> = (((<$matKey$> & ROUGHNESS_MAP_BIT) != 0) ? <$fetchedRoughness$> : <$materialRoughness$>);
|
||||
|
|
|
@ -81,7 +81,7 @@ ItemKey MeshPartPayload::getKey() const {
|
|||
|
||||
if (_drawMaterial) {
|
||||
auto matKey = _drawMaterial->getKey();
|
||||
if (matKey.isTransparent() || matKey.isTransparentTexture() || matKey.isTransparentMap()) {
|
||||
if (matKey.isTranslucentFactor() || matKey.isTranslucentMap()) {
|
||||
builder.withTransparent();
|
||||
}
|
||||
}
|
||||
|
@ -100,7 +100,7 @@ ShapeKey MeshPartPayload::getShapeKey() const {
|
|||
}
|
||||
|
||||
ShapeKey::Builder builder;
|
||||
if (drawMaterialKey.isTransparent() || drawMaterialKey.isTransparentTexture() || drawMaterialKey.isTransparentMap()) {
|
||||
if (drawMaterialKey.isTranslucent()) {
|
||||
builder.withTranslucent();
|
||||
}
|
||||
if (drawMaterialKey.isNormalMap()) {
|
||||
|
@ -365,7 +365,7 @@ ItemKey ModelMeshPartPayload::getKey() const {
|
|||
|
||||
if (_drawMaterial) {
|
||||
auto matKey = _drawMaterial->getKey();
|
||||
if (matKey.isTransparent() || matKey.isTransparentTexture() || matKey.isTransparentMap()) {
|
||||
if (matKey.isTranslucent()) {
|
||||
builder.withTransparent();
|
||||
}
|
||||
}
|
||||
|
@ -412,8 +412,7 @@ ShapeKey ModelMeshPartPayload::getShapeKey() const {
|
|||
drawMaterialKey = _drawMaterial->getKey();
|
||||
}
|
||||
|
||||
bool isTranslucent =
|
||||
drawMaterialKey.isTransparent() || drawMaterialKey.isTransparentTexture() || drawMaterialKey.isTransparentMap();
|
||||
bool isTranslucent = drawMaterialKey.isTranslucent();
|
||||
bool hasTangents = drawMaterialKey.isNormalMap() && !mesh.tangents.isEmpty();
|
||||
bool hasSpecular = drawMaterialKey.isMetallicMap();
|
||||
bool hasLightmap = drawMaterialKey.isLightmapMap();
|
||||
|
|
|
@ -29,6 +29,10 @@ void main(void) {
|
|||
int matKey = getMaterialKey(mat);
|
||||
<$fetchMaterialTextures(matKey, _texCoord0, albedoTex, roughnessTex, _SCRIBE_NULL, _SCRIBE_NULL, emissiveTex, occlusionTex)$>
|
||||
|
||||
float opacity = 1.0;
|
||||
<$evalMaterialOpacity(albedoTex.a, opacity, matKey, opacity)&>;
|
||||
<$discardTransparent(opacity)$>;
|
||||
|
||||
vec3 albedo = getMaterialAlbedo(mat);
|
||||
<$evalMaterialAlbedo(albedoTex, albedo, matKey, albedo)$>;
|
||||
albedo *= _color;
|
||||
|
@ -41,7 +45,7 @@ void main(void) {
|
|||
|
||||
packDeferredFragment(
|
||||
normalize(_normal.xyz),
|
||||
evalOpaqueFinalAlpha(getMaterialOpacity(mat), albedoTex.a),
|
||||
opacity,
|
||||
albedo,
|
||||
roughness,
|
||||
getMaterialMetallic(mat),
|
||||
|
|
|
@ -30,6 +30,10 @@ void main(void) {
|
|||
int matKey = getMaterialKey(mat);
|
||||
<$fetchMaterialTextures(matKey, _texCoord0, albedoTex, roughnessTex, normalTex, _SCRIBE_NULL, emissiveTex, occlusionTex)$>
|
||||
|
||||
float opacity = 1.0;
|
||||
<$evalMaterialOpacity(albedoTex.a, opacity, matKey, opacity)&>;
|
||||
<$discardTransparent(opacity)$>;
|
||||
|
||||
vec3 albedo = getMaterialAlbedo(mat);
|
||||
<$evalMaterialAlbedo(albedoTex, albedo, matKey, albedo)$>;
|
||||
albedo *= _color;
|
||||
|
@ -45,7 +49,7 @@ void main(void) {
|
|||
|
||||
packDeferredFragment(
|
||||
viewNormal,
|
||||
evalOpaqueFinalAlpha(getMaterialOpacity(mat), albedoTex.a),
|
||||
opacity,
|
||||
albedo,
|
||||
roughness,
|
||||
getMaterialMetallic(mat),
|
||||
|
|
|
@ -30,6 +30,10 @@ void main(void) {
|
|||
int matKey = getMaterialKey(mat);
|
||||
<$fetchMaterialTextures(matKey, _texCoord0, albedoTex, roughnessTex, normalTex, metallicTex, emissiveTex, occlusionTex)$>
|
||||
|
||||
float opacity = 1.0;
|
||||
<$evalMaterialOpacity(albedoTex.a, opacity, matKey, opacity)&>;
|
||||
<$discardTransparent(opacity)$>;
|
||||
|
||||
vec3 albedo = getMaterialAlbedo(mat);
|
||||
<$evalMaterialAlbedo(albedoTex, albedo, matKey, albedo)$>;
|
||||
albedo *= _color;
|
||||
|
@ -49,7 +53,7 @@ void main(void) {
|
|||
|
||||
packDeferredFragment(
|
||||
normalize(viewNormal.xyz),
|
||||
evalOpaqueFinalAlpha(getMaterialOpacity(mat), albedoTex.a),
|
||||
opacity,
|
||||
albedo,
|
||||
roughness,
|
||||
metallic,
|
||||
|
|
|
@ -30,6 +30,10 @@ void main(void) {
|
|||
int matKey = getMaterialKey(mat);
|
||||
<$fetchMaterialTextures(matKey, _texCoord0, albedoTex, roughnessTex, _SCRIBE_NULL, metallicTex, emissiveTex, occlusionTex)$>
|
||||
|
||||
float opacity = 1.0;
|
||||
<$evalMaterialOpacity(albedoTex.a, opacity, matKey, opacity)&>;
|
||||
<$discardTransparent(opacity)$>;
|
||||
|
||||
vec3 albedo = getMaterialAlbedo(mat);
|
||||
<$evalMaterialAlbedo(albedoTex, albedo, matKey, albedo)$>;
|
||||
albedo *= _color;
|
||||
|
@ -45,7 +49,7 @@ void main(void) {
|
|||
|
||||
packDeferredFragment(
|
||||
normalize(_normal),
|
||||
evalOpaqueFinalAlpha(getMaterialOpacity(mat), albedoTex.a),
|
||||
opacity,
|
||||
albedo,
|
||||
roughness,
|
||||
metallic,
|
||||
|
|
|
@ -36,6 +36,10 @@ void main(void) {
|
|||
int matKey = getMaterialKey(mat);
|
||||
<$fetchMaterialTextures(matKey, _texCoord0, albedoTex, roughnessTex, _SCRIBE_NULL, _SCRIBE_NULL, emissiveTex, occlusionTex)$>
|
||||
|
||||
float opacity = getMaterialOpacity(mat) * _alpha;
|
||||
<$evalMaterialOpacity(albedoTex.a, opacity, matKey, opacity)&>;
|
||||
<$discardTransparent(opacity)$>;
|
||||
|
||||
vec3 albedo = getMaterialAlbedo(mat);
|
||||
<$evalMaterialAlbedo(albedoTex, albedo, matKey, albedo)$>;
|
||||
albedo *= _color;
|
||||
|
@ -52,8 +56,6 @@ void main(void) {
|
|||
vec3 fragPosition = _position.xyz;
|
||||
vec3 fragNormal = normalize(_normal);
|
||||
|
||||
float fragOpacity = getMaterialOpacity(mat) * albedoTex.a * _alpha;
|
||||
|
||||
TransformCamera cam = getTransformCamera();
|
||||
|
||||
_fragColor = vec4(evalAmbientSphereGlobalColor(
|
||||
|
@ -66,5 +68,5 @@ void main(void) {
|
|||
metallic,
|
||||
emissive,
|
||||
roughness),
|
||||
fragOpacity);
|
||||
opacity);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue