Only create aoMetRoughTex when metalnesss or roughness texture provided

This commit is contained in:
Michael Tostenson 2019-03-26 17:28:10 -07:00
parent 678a9bf844
commit 9c114ffa49
1 changed files with 25 additions and 20 deletions

View File

@ -261,6 +261,11 @@ 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.
bool hasMetallicMap = material.textures[RAW_TEXTURE_USAGE_METALLIC] >= 0;
bool hasRoughnessMap = material.textures[RAW_TEXTURE_USAGE_ROUGHNESS] >= 0;
if (hasMetallicMap || hasRoughnessMap) {
// merge metallic into the blue channel and roughness into the green, of a new combinatory // merge metallic into the blue channel and roughness into the green, of a new combinatory
// texture // texture
aoMetRoughTex = textureBuilder.combine( aoMetRoughTex = textureBuilder.combine(
@ -272,15 +277,15 @@ ModelData* Raw2Gltf(
"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]; const float metallic = (*pixels[1])[0] * (hasMetallicMap ? 1 : props->metallic);
const float roughness = (*pixels[2])[0]; 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);
}
baseColorTex = simpleTex(RAW_TEXTURE_USAGE_ALBEDO); baseColorTex = simpleTex(RAW_TEXTURE_USAGE_ALBEDO);
diffuseFactor = props->diffuseFactor; diffuseFactor = props->diffuseFactor;
metallic = props->metallic; metallic = props->metallic;