diff --git a/src/Raw2Gltf.cpp b/src/Raw2Gltf.cpp index ed787cb..44f5a91 100644 --- a/src/Raw2Gltf.cpp +++ b/src/Raw2Gltf.cpp @@ -852,6 +852,9 @@ ModelData *Raw2Gltf( diffuseTex.get(), diffuseFactor, specGlossTex.get(), specularFactor, glossiness)); } + TextureData *normalTexture = simpleTex(RAW_TEXTURE_USAGE_NORMAL).get(); + TextureData *emissiveTexture = simpleTex(RAW_TEXTURE_USAGE_EMISSIVE).get(); + std::shared_ptr khrComMat; if (options.useKHRMatCom) { float shininess; @@ -908,16 +911,33 @@ ModelData *Raw2Gltf( std::shared_ptr khrCmnConstantMat; if (options.useKHRMatCmnConstant) { - khrCmnConstantMat.reset(new KHRCmnConstantMaterial()); + normalTexture = nullptr; - // Set fallback parameters - pbrMetRough.reset(new PBRMetallicRoughness(nullptr, Vec4f(0.0f, 0.0f, 0.0f, 1.0f), 0.0f, 0.0f)); + emissiveTexture = nullptr; + emissiveFactor = Vec3f(0.00f, 0.00f, 0.00f); + + Vec4f diffuseFactor; + std::shared_ptr baseColorTex; + + if (material.info->shadingModel == RAW_SHADING_MODEL_PBR_MET_ROUGH) { + RawMetRoughMatProps *props = (RawMetRoughMatProps *) material.info.get(); + diffuseFactor = props->diffuseFactor; + baseColorTex = simpleTex(RAW_TEXTURE_USAGE_ALBEDO); + } else { + RawTraditionalMatProps *props = ((RawTraditionalMatProps *) material.info.get()); + diffuseFactor = props->diffuseFactor; + baseColorTex = simpleTex(RAW_TEXTURE_USAGE_DIFFUSE); + } + + pbrMetRough.reset(new PBRMetallicRoughness(baseColorTex.get(), nullptr, diffuseFactor, 0.0f, 1.0f)); + + khrCmnConstantMat.reset(new KHRCmnConstantMaterial()); } std::shared_ptr mData = gltf->materials.hold( new MaterialData( material.name, isTransparent, - simpleTex(RAW_TEXTURE_USAGE_NORMAL).get(), simpleTex(RAW_TEXTURE_USAGE_EMISSIVE).get(), + normalTexture, emissiveTexture, emissiveFactor * emissiveIntensity, khrComMat, khrCmnConstantMat, pbrMetRough, pbrSpecGloss)); materialsByName[materialHash(material)] = mData; diff --git a/src/Raw2Gltf.h b/src/Raw2Gltf.h index 40d46fc..21c0684 100644 --- a/src/Raw2Gltf.h +++ b/src/Raw2Gltf.h @@ -30,7 +30,7 @@ using json = nlohmann::basic_json; static const std::string KHR_DRACO_MESH_COMPRESSION = "KHR_draco_mesh_compression"; static const std::string KHR_MATERIALS_COMMON = "KHR_materials_common"; -static const std::string KHR_MATERIALS_CMN_CONSTANT = "KHR_materials_cmnConstant"; +static const std::string KHR_MATERIALS_CMN_CONSTANT = "KHR_materials_unlit"; static const std::string KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS = "KHR_materials_pbrSpecularGlossiness"; static const std::string extBufferFilename = "buffer.bin";