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,26 +261,31 @@ ModelData* Raw2Gltf(
* Other values translate directly. * Other values translate directly.
*/ */
RawMetRoughMatProps* props = (RawMetRoughMatProps*)material.info.get(); RawMetRoughMatProps* props = (RawMetRoughMatProps*)material.info.get();
// merge metallic into the blue channel and roughness into the green, of a new combinatory
// texture // If either a metallic or roughness map has been provided, generate the aoMetRoughTex.
aoMetRoughTex = textureBuilder.combine( bool hasMetallicMap = material.textures[RAW_TEXTURE_USAGE_METALLIC] >= 0;
{ bool hasRoughnessMap = material.textures[RAW_TEXTURE_USAGE_ROUGHNESS] >= 0;
material.textures[RAW_TEXTURE_USAGE_OCCLUSION], if (hasMetallicMap || hasRoughnessMap) {
material.textures[RAW_TEXTURE_USAGE_METALLIC], // merge metallic into the blue channel and roughness into the green, of a new combinatory
material.textures[RAW_TEXTURE_USAGE_ROUGHNESS], // texture
}, aoMetRoughTex = textureBuilder.combine(
"ao_met_rough", {
[&](const std::vector<const TextureBuilder::pixel*> pixels) -> TextureBuilder::pixel { material.textures[RAW_TEXTURE_USAGE_OCCLUSION],
const float occlusion = (*pixels[0])[0]; material.textures[RAW_TEXTURE_USAGE_METALLIC],
const float metallic = (*pixels[1])[0]; material.textures[RAW_TEXTURE_USAGE_ROUGHNESS],
const float roughness = (*pixels[2])[0]; },
return {{occlusion, "ao_met_rough",
props->invertRoughnessMap ? 1.0f - roughness : roughness, [&](const std::vector<const TextureBuilder::pixel*> pixels) -> TextureBuilder::pixel {
metallic, const float occlusion = (*pixels[0])[0];
1}}; const float metallic = (*pixels[1])[0] * (hasMetallicMap ? 1 : props->metallic);
}, const float roughness = (*pixels[2])[0] * (hasRoughnessMap ? 1 : props->roughness);
false); return {{occlusion,
props->invertRoughnessMap ? 1.0f - roughness : roughness,
metallic,
1}};
},
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;