diff --git a/src/bsdfs/mask.cpp b/src/bsdfs/mask.cpp index 3b4f6e3b..0e246b97 100644 --- a/src/bsdfs/mask.cpp +++ b/src/bsdfs/mask.cpp @@ -82,7 +82,7 @@ public: if (sampleTransmission && sampleNested) { if (bRec.sample.x <= probBSDF) { bRec.sample.x /= probBSDF; - result = m_nestedBSDF->sample(bRec) / probBSDF; + result = m_nestedBSDF->sample(bRec); } else { transmit(bRec.wi, bRec.wo); bRec.sampledComponent = m_nestedBSDF->getComponentCount(); @@ -114,7 +114,7 @@ public: if (sampleTransmission && sampleNested) { if (bRec.sample.x <= probBSDF) { bRec.sample.x /= probBSDF; - result = m_nestedBSDF->sample(bRec, pdf); + result = m_nestedBSDF->sample(bRec, pdf) * probBSDF; pdf *= probBSDF; } else { transmit(bRec.wi, bRec.wo); diff --git a/src/converter/obj.cpp b/src/converter/obj.cpp index c11cd1a2..2d56d4ac 100644 --- a/src/converter/obj.cpp +++ b/src/converter/obj.cpp @@ -48,22 +48,38 @@ std::string copyTexture(GeometryConverter *cvt, const std::string &textureDir, s void addMaterial(GeometryConverter *cvt, std::ostream &os, const std::string &mtlName, const std::string &texturesDir, const Spectrum &diffuseValue, - const std::string &diffuseMap) { + const std::string &diffuseMap, const std::string maskMap) { if (mtlName == "") return; SLog(EInfo, "Copying material \"%s\" ..", mtlName.c_str()); - os << "\t" << endl; + std::string indent = ""; + + if (maskMap != "") { + indent = "\t"; + os << "\t" << endl; + os << "\t\t" << endl; + os << "\t\t\t" << endl; + os << "\t\t" << endl; + os << "\t\t" << endl; + } else { + os << "\t" << endl; + } + if (diffuseMap == "") { Float r, g, b; diffuseValue.toLinearRGB(r, g, b); - os << "\t\t" << endl; } else { - os << "\t\t" << endl - << "\t\t\t" << endl - << "\t\t" << endl; + os << indent << "\t\t" << endl + << indent << "\t\t\t" << endl + << indent << "\t\t" << endl; } - os << "\t" << endl << endl; + + os << indent << "\t" << endl << endl; + + if (maskMap != "") + os << "\t" << endl; } void parseMaterials(GeometryConverter *cvt, std::ostream &os, const std::string &texturesDir, @@ -75,15 +91,16 @@ void parseMaterials(GeometryConverter *cvt, std::ostream &os, const std::string std::string buf, line; std::string mtlName; Spectrum diffuse(0.0f); - std::string diffuseMap; + std::string diffuseMap, maskMap; while (is >> buf) { if (buf == "newmtl") { - addMaterial(cvt, os, mtlName, texturesDir, diffuse, diffuseMap); + addMaterial(cvt, os, mtlName, texturesDir, diffuse, diffuseMap, maskMap); std::getline(is, line); mtlName = line.substr(1, line.length()-2); diffuse = Spectrum(0.0f); diffuseMap = ""; + maskMap = ""; } else if (buf == "Kd") { Float r, g, b; is >> r >> g >> b; @@ -94,12 +111,15 @@ void parseMaterials(GeometryConverter *cvt, std::ostream &os, const std::string } else if (buf == "map_Kd") { std::getline(is, line); diffuseMap = line.substr(1, line.length()-2); + } else if (buf == "map_d") { + std::getline(is, line); + maskMap = line.substr(1, line.length()-2); } else { /* Ignore */ std::getline(is, line); } } - addMaterial(cvt, os, mtlName, texturesDir, diffuse, diffuseMap); + addMaterial(cvt, os, mtlName, texturesDir, diffuse, diffuseMap, maskMap); } void GeometryConverter::convertOBJ(const std::string &inputFile,