From 20b1bd7051c67113a13300edaa2998e2c7587e63 Mon Sep 17 00:00:00 2001 From: Par Winzell Date: Sun, 4 Feb 2018 14:42:57 -0800 Subject: [PATCH] Semi-randomly tweak Phong->PBR conversion. I stole expressions from Gary Hsu's PBR conversion routines here: https://github.com/KhronosGroup/glTF/blob/3606e79717a8d5b0a8ecd4db8a8cc4a2c17c6509/extensions/Khronos/KHR_materials_pbrSpecularGlossiness/examples/convert-between-workflows/js/three.pbrUtilities.js which is experimental enough as it is, but I had gone further into the domain of madness and uses this with *old* diffuse/specular values, not PBR specular/glossness. As a result a lot of old content was coming up with 100% metal values quite often, which in turn means completely ignoring diffuse when assembling a new base colour... I should rip out this whole conversion. But not just now... --- src/Raw2Gltf.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/Raw2Gltf.cpp b/src/Raw2Gltf.cpp index 04e823a..5239f2d 100644 --- a/src/Raw2Gltf.cpp +++ b/src/Raw2Gltf.cpp @@ -701,10 +701,7 @@ ModelData *Raw2Gltf( /** * Traditional FBX Material -> PBR Met/Rough glTF. * - * Diffuse channel is used as base colour. No metallic/roughness texture is attempted. Constant - * metallic/roughness values are hard-coded. - * - * TODO: If we have specular & optional shininess map, we can generate a reasonable rough/met map. + * Diffuse channel is used as base colour. */ const RawTraditionalMatProps *props = ((RawTraditionalMatProps *) material.info.get()); diffuseFactor = props->diffuseFactor; @@ -731,7 +728,8 @@ ModelData *Raw2Gltf( metRoughTex = merge3Tex("rough_met", RAW_TEXTURE_USAGE_SPECULAR, RAW_TEXTURE_USAGE_SHININESS, RAW_TEXTURE_USAGE_DIFFUSE, [&](const std::vector pixels) -> pixel { - const Vec3f specular = pixels[0] ? toVec3f(*pixels[0]) : props->specularFactor; + const Vec3f specular = Vec3f(0.4f, 0.4f, 0.4f) + + 0.2f * (pixels[0] ? toVec3f(*pixels[0]) : props->specularFactor); float shininess = pixels[1] ? (*pixels[1])[0] : props->shininess; const Vec4f diffuse = pixels[2] ? toVec4f(*pixels[2]) : props->diffuseFactor; @@ -748,7 +746,8 @@ ModelData *Raw2Gltf( baseColorTex = merge2Tex("base_col", RAW_TEXTURE_USAGE_DIFFUSE, RAW_TEXTURE_USAGE_SPECULAR, [&](const std::vector pixels) -> pixel { const Vec4f diffuse = pixels[0] ? toVec4f(*pixels[0]) : props->diffuseFactor; - const Vec3f specular = pixels[1] ? toVec3f(*pixels[1]) : props->specularFactor; + const Vec3f specular = Vec3f(0.4f, 0.4f, 0.4f) + + 0.2f * (pixels[1] ? toVec3f(*pixels[1]) : props->specularFactor); float oneMinus = 1 - getMaxComponent(specular);