Generally repair old broken logic around aoMetRough texture.

This commit is contained in:
Par Winzell 2019-03-29 09:59:57 -07:00
parent ca78a31b22
commit d2f7d0e270
1 changed files with 20 additions and 15 deletions

View File

@ -262,12 +262,18 @@ ModelData* Raw2Gltf(
*/ */
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,10 +281,12 @@ 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,
@ -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.
if (material.textures[RAW_TEXTURE_USAGE_OCCLUSION] >= 0) {
occlusionTexture = aoMetRoughTex.get(); occlusionTexture = aoMetRoughTex.get();
}
} else { } else {
/** /**
* Traditional FBX Material -> PBR Met/Rough glTF. * Traditional FBX Material -> PBR Met/Rough glTF.