Merge pull request #171 from mtostenson/master

Only create aoMetRoughTex when metalnesss or roughness texture provided.

Following up with tweak commit.
This commit is contained in:
Pär Winzell 2019-03-29 09:31:44 -07:00 committed by GitHub
commit ca78a31b22
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 25 additions and 20 deletions

View File

@ -261,6 +261,11 @@ ModelData* Raw2Gltf(
* Other values translate directly.
*/
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
// texture
aoMetRoughTex = textureBuilder.combine(
@ -272,15 +277,15 @@ ModelData* Raw2Gltf(
"ao_met_rough",
[&](const std::vector<const TextureBuilder::pixel*> pixels) -> TextureBuilder::pixel {
const float occlusion = (*pixels[0])[0];
const float metallic = (*pixels[1])[0];
const float roughness = (*pixels[2])[0];
const float metallic = (*pixels[1])[0] * (hasMetallicMap ? 1 : props->metallic);
const float roughness = (*pixels[2])[0] * (hasRoughnessMap ? 1 : props->roughness);
return {{occlusion,
props->invertRoughnessMap ? 1.0f - roughness : roughness,
metallic,
1}};
},
false);
}
baseColorTex = simpleTex(RAW_TEXTURE_USAGE_ALBEDO);
diffuseFactor = props->diffuseFactor;
metallic = props->metallic;