Generally repair old broken logic around aoMetRough texture.
This commit is contained in:
parent
ca78a31b22
commit
d2f7d0e270
|
@ -261,13 +261,19 @@ ModelData* Raw2Gltf(
|
||||||
* Other values translate directly.
|
* Other values translate directly.
|
||||||
*/
|
*/
|
||||||
RawMetRoughMatProps* props = (RawMetRoughMatProps*)material.info.get();
|
RawMetRoughMatProps* props = (RawMetRoughMatProps*)material.info.get();
|
||||||
|
|
||||||
// If either a metallic or roughness map has been provided, generate the aoMetRoughTex.
|
// determine if we need to generate a combined map
|
||||||
bool hasMetallicMap = material.textures[RAW_TEXTURE_USAGE_METALLIC] >= 0;
|
bool hasMetallicMap = material.textures[RAW_TEXTURE_USAGE_METALLIC] >= 0;
|
||||||
bool hasRoughnessMap = material.textures[RAW_TEXTURE_USAGE_ROUGHNESS] >= 0;
|
bool hasRoughnessMap = material.textures[RAW_TEXTURE_USAGE_ROUGHNESS] >= 0;
|
||||||
if (hasMetallicMap || hasRoughnessMap) {
|
bool hasOcclusionMap = material.textures[RAW_TEXTURE_USAGE_OCCLUSION] >= 0;
|
||||||
// merge metallic into the blue channel and roughness into the green, of a new combinatory
|
aoMetRoughTex = hasMetallicMap
|
||||||
// texture
|
? simpleTex(RAW_TEXTURE_USAGE_METALLIC)
|
||||||
|
: (hasRoughnessMap
|
||||||
|
? simpleTex(RAW_TEXTURE_USAGE_ROUGHNESS)
|
||||||
|
: (hasOcclusionMap ? simpleTex(RAW_TEXTURE_USAGE_OCCLUSION) : nullptr));
|
||||||
|
if (aoMetRoughTex == nullptr) {
|
||||||
|
// merge occlusion into the red channel, metallic into blue channel, and
|
||||||
|
// roughness into the green, of a new combinatory texture
|
||||||
aoMetRoughTex = textureBuilder.combine(
|
aoMetRoughTex = textureBuilder.combine(
|
||||||
{
|
{
|
||||||
material.textures[RAW_TEXTURE_USAGE_OCCLUSION],
|
material.textures[RAW_TEXTURE_USAGE_OCCLUSION],
|
||||||
|
@ -275,14 +281,16 @@ ModelData* Raw2Gltf(
|
||||||
material.textures[RAW_TEXTURE_USAGE_ROUGHNESS],
|
material.textures[RAW_TEXTURE_USAGE_ROUGHNESS],
|
||||||
},
|
},
|
||||||
"ao_met_rough",
|
"ao_met_rough",
|
||||||
[&](const std::vector<const TextureBuilder::pixel*> pixels) -> TextureBuilder::pixel {
|
[&](const std::vector<const TextureBuilder::pixel*> pixels)
|
||||||
|
-> TextureBuilder::pixel {
|
||||||
const float occlusion = (*pixels[0])[0];
|
const float occlusion = (*pixels[0])[0];
|
||||||
const float metallic = (*pixels[1])[0] * (hasMetallicMap ? 1 : props->metallic);
|
const float metallic = (*pixels[1])[0] * (hasMetallicMap ? 1 : props->metallic);
|
||||||
const float roughness = (*pixels[2])[0] * (hasRoughnessMap ? 1 : props->roughness);
|
const float roughness =
|
||||||
|
(*pixels[2])[0] * (hasRoughnessMap ? 1 : props->roughness);
|
||||||
return {{occlusion,
|
return {{occlusion,
|
||||||
props->invertRoughnessMap ? 1.0f - roughness : roughness,
|
props->invertRoughnessMap ? 1.0f - roughness : roughness,
|
||||||
metallic,
|
metallic,
|
||||||
1}};
|
1}};
|
||||||
},
|
},
|
||||||
false);
|
false);
|
||||||
}
|
}
|
||||||
|
@ -292,11 +300,8 @@ ModelData* Raw2Gltf(
|
||||||
roughness = props->roughness;
|
roughness = props->roughness;
|
||||||
emissiveFactor = props->emissiveFactor;
|
emissiveFactor = props->emissiveFactor;
|
||||||
emissiveIntensity = props->emissiveIntensity;
|
emissiveIntensity = props->emissiveIntensity;
|
||||||
// add the occlusion texture only if actual occlusion pixels exist in the aoNetRough
|
// this will set occlusionTexture to null, if no actual occlusion map exists
|
||||||
// texture.
|
occlusionTexture = aoMetRoughTex.get();
|
||||||
if (material.textures[RAW_TEXTURE_USAGE_OCCLUSION] >= 0) {
|
|
||||||
occlusionTexture = aoMetRoughTex.get();
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
/**
|
/**
|
||||||
* Traditional FBX Material -> PBR Met/Rough glTF.
|
* Traditional FBX Material -> PBR Met/Rough glTF.
|
||||||
|
|
Loading…
Reference in New Issue