Commit dd39a53b authored by David E. DeMarle's avatar David E. DeMarle
Browse files

update to ospray 2's revised material names

To save a bit on runtime cost, we only provide backward
compatibility at material library file parsing. In other words, user
code that calls MakeMaterial() directly may have be updated.
parent c1ed233a
......@@ -24,7 +24,7 @@ namespace RTW
/*
* Basic material
*/
if (this->type == "OBJMaterial" || this->type == "Luminous")
if (this->type == "obj" || this->type == "luminous")
{
this->material = rtx->CreateBasicMaterial();
}
......@@ -57,7 +57,7 @@ namespace RTW
/*
* OBJMaterial (Basic material)
*/
if (this->type == "OBJMaterial" && this->material->GetType() == VisRTX::MaterialType::BASIC)
if (this->type == "obj" && this->material->GetType() == VisRTX::MaterialType::BASIC)
{
VisRTX::BasicMaterial* basicMaterial = dynamic_cast<VisRTX::BasicMaterial*>(this->material);
assert(basicMaterial);
......@@ -98,7 +98,7 @@ namespace RTW
/*
* Luminous (Basic material)
*/
else if (this->type == "Luminous" && this->material->GetType() == VisRTX::MaterialType::BASIC)
else if (this->type == "luminous" && this->material->GetType() == VisRTX::MaterialType::BASIC)
{
VisRTX::BasicMaterial* basicMaterial = dynamic_cast<VisRTX::BasicMaterial*>(this->material);
assert(basicMaterial);
......
......@@ -49,9 +49,9 @@ int TestPathTracerMaterialLibrary(int argc, char* argv[])
return VTK_ERROR;
}
cout << "Found Water material." << endl;
if (lib->LookupImplName("Water") != "Glass")
if (lib->LookupImplName("Water") != "glass")
{
cerr << "Problem, expected Water to be implemented by the Glass material." << endl;
cerr << "Problem, expected Water to be implemented by the glass material." << endl;
return VTK_ERROR;
}
cout << "Water is the right type." << endl;
......@@ -123,9 +123,9 @@ int TestPathTracerMaterialLibrary(int argc, char* argv[])
cerr << "Problem, could not find expected material named mat3." << endl;
return VTK_ERROR;
}
if (lib->LookupImplName("mat3") != "Metal")
if (lib->LookupImplName("mat3") != "metal")
{
cerr << "Problem, expected mat3 to be implemented by the Metal material." << endl;
cerr << "Problem, expected mat3 to be implemented by the metal material." << endl;
return VTK_ERROR;
}
cout << "mat3 is the right type." << endl;
......
......@@ -220,7 +220,7 @@ int TestPathTracerMaterials(int argc, char* argv[])
{
style->AddName("default glass");
ml->AddMaterial("Glass 1", "Glass");
ml->AddMaterial("Glass 1", "glass");
actor = vtkSmartPointer<vtkActor>::New();
actor->SetPosition(xo + xr * 1.15 * i, yo, zo + zr * 1.1 * j);
......@@ -236,7 +236,7 @@ int TestPathTracerMaterials(int argc, char* argv[])
{
style->AddName("high index of refraction glass");
ml->AddMaterial("Glass 2", "Glass");
ml->AddMaterial("Glass 2", "glass");
double eta[1] = { 2.0 };
ml->AddShaderVariable("Glass 2", "etaInside", 1, eta);
......@@ -254,7 +254,7 @@ int TestPathTracerMaterials(int argc, char* argv[])
{
style->AddName("colored glass");
ml->AddMaterial("Glass 3", "Glass");
ml->AddMaterial("Glass 3", "glass");
double green[3] = { 0.0, 1.0, 0.0 };
ml->AddShaderVariable("Glass 3", "attenuationColor", 3, green);
......@@ -297,7 +297,7 @@ int TestPathTracerMaterials(int argc, char* argv[])
{
style->AddName("default metal");
ml->AddMaterial("Metal 1", "Metal");
ml->AddMaterial("Metal 1", "metal");
actor = vtkSmartPointer<vtkActor>::New();
actor->SetPosition(xo + xr * 1.15 * i, yo, zo + zr * 1.1 * j);
......@@ -313,7 +313,7 @@ int TestPathTracerMaterials(int argc, char* argv[])
{
style->AddName("rough metal");
ml->AddMaterial("Metal 2", "Metal");
ml->AddMaterial("Metal 2", "metal");
double roughness[1] = { 0.3 };
ml->AddShaderVariable("Metal 2", "roughness", 1, roughness);
......@@ -331,13 +331,10 @@ int TestPathTracerMaterials(int argc, char* argv[])
{
style->AddName("copper metal");
ml->AddMaterial("Metal 3", "Metal");
ml->AddMaterial("Metal 3", "metal");
double roughness[1] = { 0.0 };
ml->AddShaderVariable("Metal 3", "roughness", 1, roughness);
// for OSP < 1.4 and > 1.4.0
double cuColor[3] = { 0.7843, 0.4588, 0.2 };
ml->AddShaderVariable("Metal 3", "reflectance", 3, cuColor);
// for OSP >= 1.4
// exact
double spectrum[58 * 3] = {
300, 1.347459987, 1.679419071, //
310, 1.321473211, 1.740141215, //
......@@ -399,6 +396,11 @@ int TestPathTracerMaterials(int argc, char* argv[])
870, 0.109423947, 5.718126756 //
};
ml->AddShaderVariable("Metal 3", "ior", 58 * 3, spectrum);
// approximate
double cuEta[3] = { 0.1, 0.8, 1.1 };
double cuK[3] = { 3.5, 2.5, 2.4 };
// ml->AddShaderVariable("Metal 3", "eta", 3, cuEta);
// ml->AddShaderVariable("Metal 3", "k", 3, cuK);
actor = vtkSmartPointer<vtkActor>::New();
actor->SetPosition(xo + xr * 1.15 * i, yo, zo + zr * 1.1 * j);
......@@ -462,7 +464,7 @@ int TestPathTracerMaterials(int argc, char* argv[])
{
style->AddName("default objmaterial");
ml->AddMaterial("OBJMaterial 1", "OBJMaterial");
ml->AddMaterial("OBJMaterial 1", "obj");
actor = vtkSmartPointer<vtkActor>::New();
actor->SetPosition(xo + xr * 1.15 * i, yo, zo + zr * 1.1 * j);
......@@ -478,7 +480,7 @@ int TestPathTracerMaterials(int argc, char* argv[])
{ // todo: validate
style->AddName("alpha objmaterial");
ml->AddMaterial("OBJMaterial 2", "OBJMaterial");
ml->AddMaterial("OBJMaterial 2", "obj");
double alpha[1] = { 0.2 };
ml->AddShaderVariable("OBJMaterial 2", "alpha", 1, alpha);
......@@ -577,7 +579,7 @@ int TestPathTracerMaterials(int argc, char* argv[])
{ // todo: looks 'approximately' right but needs validation
style->AddName("bump map objmaterial");
ml->AddMaterial("OBJMaterial 7", "OBJMaterial");
ml->AddMaterial("OBJMaterial 7", "obj");
ml->AddTexture("OBJMaterial 7", "map_bump", texture);
actor = vtkSmartPointer<vtkActor>::New();
......@@ -594,7 +596,7 @@ int TestPathTracerMaterials(int argc, char* argv[])
{
style->AddName("opacity map objmaterial");
ml->AddMaterial("OBJMaterial 8", "OBJMaterial");
ml->AddMaterial("OBJMaterial 8", "obj");
ml->AddTexture("OBJMaterial 8", "map_d", texture);
actor = vtkSmartPointer<vtkActor>::New();
......@@ -611,7 +613,7 @@ int TestPathTracerMaterials(int argc, char* argv[])
{ // todo: validate
style->AddName("kd map objmaterial");
ml->AddMaterial("OBJMaterial 9", "OBJMaterial");
ml->AddMaterial("OBJMaterial 9", "obj");
ml->AddTexture("OBJMaterial 9", "map_kd", texture);
actor = vtkSmartPointer<vtkActor>::New();
......@@ -669,7 +671,7 @@ int TestPathTracerMaterials(int argc, char* argv[])
{
style->AddName("default thin glass");
ml->AddMaterial("ThinGlass 1", "ThinGlass");
ml->AddMaterial("ThinGlass 1", "thinGlass");
actor = vtkSmartPointer<vtkActor>::New();
actor->SetPosition(xo + xr * 1.15 * i, yo, zo + zr * 1.1 * j);
......@@ -685,7 +687,7 @@ int TestPathTracerMaterials(int argc, char* argv[])
{
style->AddName("shinier thin glass");
ml->AddMaterial("ThinGlass 2", "ThinGlass");
ml->AddMaterial("ThinGlass 2", "thinGlass");
double eta[1] = { 5.5 };
ml->AddShaderVariable("ThinGlass 2", "eta", 1, eta);
......@@ -703,7 +705,7 @@ int TestPathTracerMaterials(int argc, char* argv[])
{
style->AddName("red thin glass");
ml->AddMaterial("ThinGlass 3", "ThinGlass");
ml->AddMaterial("ThinGlass 3", "thinGlass");
double thickness[1] = { 0.000001 };
ml->AddShaderVariable("ThinGlass 3", "thickness", 1, thickness);
double pigmentColor[3] = { 1.0, 0.0, 0.0 };
......@@ -724,7 +726,7 @@ int TestPathTracerMaterials(int argc, char* argv[])
{ //todo: looks no different
style->AddName("thinnish glass");
ml->AddMaterial("ThinGlass 4", "ThinGlass");
ml->AddMaterial("ThinGlass 4", "thinGlass");
double thickness[1] = { 0.1 };
ml->AddShaderVariable("ThinGlass 4", "thickness", 1, thickness);
double pigmentColor[3] = { 1.0, 0.0, 0.0 };
......@@ -748,7 +750,7 @@ int TestPathTracerMaterials(int argc, char* argv[])
{
style->AddName("default car paint");
ml->AddMaterial("CarPaint 1", "CarPaint");
ml->AddMaterial("CarPaint 1", "carPaint");
actor = vtkSmartPointer<vtkActor>::New();
actor->SetPosition(xo + xr * 1.15 * i, yo, zo + zr * 1.1 * j);
......@@ -764,7 +766,7 @@ int TestPathTracerMaterials(int argc, char* argv[])
{
style->AddName("Flakey purpley pink car paint");
ml->AddMaterial("CarPaint 2", "CarPaint");
ml->AddMaterial("CarPaint 2", "carPaint");
ml->AddShaderVariable("CarPaint 2", "baseColor", { 1., .1, .9 });
ml->AddShaderVariable("CarPaint 2", "coatColor", { 1., .1, .9 });
ml->AddShaderVariable("CarPaint 2", "flipflopColor", { .5, .1, .9 });
......@@ -788,7 +790,7 @@ int TestPathTracerMaterials(int argc, char* argv[])
{
style->AddName("Silvery blue car paint");
ml->AddMaterial("CarPaint 3", "CarPaint");
ml->AddMaterial("CarPaint 3", "carPaint");
ml->AddShaderVariable("CarPaint 3", "baseColor", { .4, .4, .6 });
ml->AddShaderVariable("CarPaint 3", "coatColor", { .7, .7, .8 });
ml->AddShaderVariable("CarPaint 3", "coatThickness", { .3 });
......@@ -816,7 +818,7 @@ int TestPathTracerMaterials(int argc, char* argv[])
{
style->AddName("default principled");
ml->AddMaterial("Principled 1", "Principled");
ml->AddMaterial("Principled 1", "principled");
actor = vtkSmartPointer<vtkActor>::New();
actor->SetPosition(xo + xr * 1.15 * i, yo, zo + zr * 1.1 * j);
......@@ -832,7 +834,7 @@ int TestPathTracerMaterials(int argc, char* argv[])
{
style->AddName("green sheen principled");
ml->AddMaterial("Principled 2", "Principled");
ml->AddMaterial("Principled 2", "principled");
ml->AddShaderVariable("Principled 2", "baseColor", { .6, .9, .6 });
ml->AddShaderVariable("Principled 2", "edgeColor", { .1, .9, .2 });
ml->AddShaderVariable("Principled 2", "metallic", { .7 });
......
......@@ -192,8 +192,8 @@ OSPMaterial vtkOSPRayMaterialHelpers::MakeMaterial(
vtkOSPRayMaterialLibrary* ml = vtkOSPRayRendererNode::GetMaterialLibrary(orn->GetRenderer());
if (!ml)
{
vtkGenericWarningMacro("No material Library in this renderer. Using OBJMaterial by default.");
return NewMaterial(orn, oRenderer, "OBJMaterial");
vtkGenericWarningMacro("No material Library in this renderer. Using obj by default.");
return NewMaterial(orn, oRenderer, "obj");
}
const auto& dic = vtkOSPRayMaterialLibrary::GetParametersDictionary();
......@@ -290,8 +290,8 @@ OSPMaterial vtkOSPRayMaterialHelpers::MakeMaterial(
else
{
vtkGenericWarningMacro(
"Warning: unrecognized material \"" << implname.c_str() << "\", using a default OBJMaterial");
return NewMaterial(orn, oRenderer, "OBJMaterial");
"Warning: unrecognized material \"" << implname.c_str() << "\", using a default obj");
return NewMaterial(orn, oRenderer, "obj");
}
return oMaterial;
......@@ -314,8 +314,8 @@ OSPMaterial vtkOSPRayMaterialHelpers::NewMaterial(
if (!result)
{
vtkGenericWarningMacro(
"OSPRay failed to create material: " << ospMatName << ". Trying OBJMaterial instead.");
result = ospNewMaterial(rendererType.c_str(), "OBJMaterial");
"OSPRay failed to create material: " << ospMatName << ". Trying obj instead.");
result = ospNewMaterial(rendererType.c_str(), "obj");
}
return result;
......
......@@ -38,17 +38,17 @@
namespace
{
const std::map<std::string, std::map<std::string, std::string> > Aliases = {
{ "OBJMaterial",
{ "obj",
{ { "colorMap", "map_Kd" }, { "map_kd", "map_Kd" }, { "map_ks", "map_Ks" },
{ "map_ns", "map_Ns" }, { "map_bump", "map_Bump" }, { "normalMap", "map_Bump" },
{ "BumpMap", "map_Bump" }, { "color", "Kd" }, { "kd", "Kd" }, { "alpha", "d" },
{ "ks", "Ks" }, { "ns", "Ns" }, { "tf", "Tf" } } },
{ "ThinGlass", { { "color", "attenuationColor" }, { "transmission", "attenuationColor" } } },
{ "MetallicPaint", { { "color", "baseColor" } } },
{ "Glass",
{ "thinGlass", { { "color", "attenuationColor" }, { "transmission", "attenuationColor" } } },
{ "metallicPaint", { { "color", "baseColor" } } },
{ "glass",
{ { "etaInside", "eta" }, { "etaOutside", "eta" },
{ "attenuationColorOutside", "attenuationColor" } } },
{ "Principled", {} }, { "CarPaint", {} }, { "Metal", {} }, { "Alloy", {} }
{ "principled", {} }, { "carPaint", {} }, { "metal", {} }, { "alloy", {} }
};
std::string FindRealName(const std::string& materialType, const std::string& alias)
......@@ -310,7 +310,40 @@ bool vtkOSPRayMaterialLibrary::InternalParseJSON(
// keep a record so others know this material is available
this->Internal->NickNames.insert(nickname);
const std::string& implname = nextmat["type"].asString();
std::string implname = nextmat["type"].asString();
// backward compatibility over OSPRay 2.0 name changes
if (implname == "Alloy")
{
implname = "alloy";
}
if (implname == "CarPaint")
{
implname = "carPaint";
}
if (implname == "Glass")
{
implname = "glass";
}
if (implname == "Metal")
{
implname = "metal";
}
if (implname == "MetallicPaint")
{
implname = "metallicPaint";
}
if (implname == "OBJMaterial")
{
implname = "obj";
}
if (implname == "Principled")
{
implname = "principled";
}
if (implname == "ThinGlass")
{
implname = "thinGlass";
}
this->Internal->ImplNames[nickname] = implname;
if (nextmat.isMember("textures"))
{
......@@ -400,7 +433,7 @@ bool vtkOSPRayMaterialLibrary::InternalParseMTL(
{
std::string str;
std::string nickname = "";
std::string implname = "OBJMaterial";
std::string implname = "obj";
const std::vector<std::string> singles{ "d ", "Ks ", "alpha ", "roughness ", "eta ",
"thickness " };
......@@ -419,7 +452,7 @@ bool vtkOSPRayMaterialLibrary::InternalParseMTL(
{
nickname = trim(tstr.substr(lkey.size()));
this->Internal->NickNames.insert(nickname);
this->Internal->ImplNames[nickname] = "OBJMaterial";
this->Internal->ImplNames[nickname] = "obj";
}
// ospray type of the material, if not obj
......@@ -431,20 +464,46 @@ bool vtkOSPRayMaterialLibrary::InternalParseMTL(
implname = trim(tstr.substr(lkey.size()));
if (implname == "matte")
{
implname = "OBJMaterial";
implname = "obj";
}
if (implname == "glass")
{
implname = "ThinGlass";
implname = "thinGlass";
}
// backward compatibility over OSPRay 2.0 name changes
if (implname == "Alloy")
{
implname = "alloy";
}
if (implname == "CarPaint")
{
implname = "carPaint";
}
if (implname == "Glass")
{
implname = "glass";
}
if (implname == "metal")
if (implname == "Metal")
{
implname = "Metal";
implname = "metal";
}
if (implname == "metallicPaint")
if (implname == "MetallicPaint")
{
implname = "MetallicPaint";
implname = "metallicPaint";
}
if (implname == "OBJMaterial")
{
implname = "obj";
}
if (implname == "Principled")
{
implname = "principled";
}
if (implname == "ThinGlass")
{
implname = "thinGlass";
}
this->Internal->ImplNames[nickname] = implname;
}
......@@ -738,7 +797,7 @@ vtkOSPRayMaterialLibrary::GetParametersDictionary()
// If attribute name changes with new OSPRay version, keep old name aliases support in functions
// vtkOSPRayMaterialLibrary::AddShaderVariable and vtkOSPRayMaterialLibrary::AddTexture
static std::map<std::string, vtkOSPRayMaterialLibrary::ParametersMap> dic = {
{ "OBJMaterial",
{ "obj",
{
{ "Ka", vtkOSPRayMaterialLibrary::ParameterType::COLOR_RGB },
{ "Kd", vtkOSPRayMaterialLibrary::ParameterType::COLOR_RGB },
......@@ -772,7 +831,7 @@ vtkOSPRayMaterialLibrary::GetParametersDictionary()
{ "map_d.scale", vtkOSPRayMaterialLibrary::ParameterType::VEC2 },
{ "map_d.translation", vtkOSPRayMaterialLibrary::ParameterType::VEC2 },
} },
{ "Principled",
{ "principled",
{
{ "baseColor", vtkOSPRayMaterialLibrary::ParameterType::COLOR_RGB },
{ "edgeColor", vtkOSPRayMaterialLibrary::ParameterType::COLOR_RGB },
......@@ -943,7 +1002,7 @@ vtkOSPRayMaterialLibrary::GetParametersDictionary()
{ "opacityMap.scale", vtkOSPRayMaterialLibrary::ParameterType::VEC2 },
{ "opacityMap.translation", vtkOSPRayMaterialLibrary::ParameterType::VEC2 },
} },
{ "CarPaint",
{ "carPaint",
{
{ "baseColor", vtkOSPRayMaterialLibrary::ParameterType::COLOR_RGB },
{ "roughness", vtkOSPRayMaterialLibrary::ParameterType::NORMALIZED_FLOAT },
......@@ -1042,7 +1101,7 @@ vtkOSPRayMaterialLibrary::GetParametersDictionary()
{ "flipflopFalloffMap.scale", vtkOSPRayMaterialLibrary::ParameterType::VEC2 },
{ "flipflopFalloffMap.translation", vtkOSPRayMaterialLibrary::ParameterType::VEC2 },
} },
{ "Metal",
{ "metal",
{
{ "ior", vtkOSPRayMaterialLibrary::ParameterType::FLOAT_DATA },
{ "eta", vtkOSPRayMaterialLibrary::ParameterType::VEC3 },
......@@ -1054,7 +1113,7 @@ vtkOSPRayMaterialLibrary::GetParametersDictionary()
{ "map_roughness.scale", vtkOSPRayMaterialLibrary::ParameterType::VEC2 },
{ "map_roughness.translation", vtkOSPRayMaterialLibrary::ParameterType::VEC2 },
} },
{ "Alloy",
{ "alloy",
{
{ "color", vtkOSPRayMaterialLibrary::ParameterType::COLOR_RGB },
{ "edgeColor", vtkOSPRayMaterialLibrary::ParameterType::COLOR_RGB },
......@@ -1075,13 +1134,13 @@ vtkOSPRayMaterialLibrary::GetParametersDictionary()
{ "map_roughness.scale", vtkOSPRayMaterialLibrary::ParameterType::VEC2 },
{ "map_roughness.translation", vtkOSPRayMaterialLibrary::ParameterType::VEC2 },
} },
{ "Glass",
{ "glass",
{
{ "eta", vtkOSPRayMaterialLibrary::ParameterType::FLOAT },
{ "attenuationColor", vtkOSPRayMaterialLibrary::ParameterType::COLOR_RGB },
{ "attenuationDistance", vtkOSPRayMaterialLibrary::ParameterType::FLOAT },
} },
{ "ThinGlass",
{ "thinGlass",
{
{ "eta", vtkOSPRayMaterialLibrary::ParameterType::FLOAT },
{ "attenuationColor", vtkOSPRayMaterialLibrary::ParameterType::COLOR_RGB },
......@@ -1093,7 +1152,7 @@ vtkOSPRayMaterialLibrary::GetParametersDictionary()
{ "map_attenuationColor.scale", vtkOSPRayMaterialLibrary::ParameterType::VEC2 },
{ "map_attenuationColor.translation", vtkOSPRayMaterialLibrary::ParameterType::VEC2 },
} },
{ "MetallicPaint",
{ "metallicPaint",
{
{ "baseColor", vtkOSPRayMaterialLibrary::ParameterType::COLOR_RGB },
{ "flakeAmount", vtkOSPRayMaterialLibrary::ParameterType::NORMALIZED_FLOAT },
......
......@@ -318,7 +318,7 @@ OSPGeometricModel RenderAsCylinders(std::vector<osp::vec3f>& vertices,
(*scaleArray->GetTuple(indexArray[i]) + *scaleArray->GetTuple(indexArray[i])) * 0.5;
const double r = MapThroughPWF(avg, scaleFunction);
const osp::vec3f& v = vertices[indexArray[i]];
mdata.emplace_back(osp::vec4f({ v.x, v.y, v.z, r }));
mdata.emplace_back(osp::vec4f({ v.x, v.y, v.z, static_cast<float>(r) }));
}
OSPData _mdata = ospNewCopyData1D(mdata.size(), OSP_VEC4F, mdata.data());
ospCommit(_mdata);
......@@ -612,7 +612,10 @@ OSPGeometricModel RenderAsTriangles(OSPData vertices, std::vector<unsigned int>&
ospRelease(_PointColors);
}
}
ospSetObjectAsData(ospGeoModel, "material", OSP_MATERIAL, actorMaterial);
if (actorMaterial)
{
ospSetObjectAsData(ospGeoModel, "material", OSP_MATERIAL, actorMaterial);
}
ospCommit(ospMesh);
......@@ -641,7 +644,7 @@ OSPMaterial MakeActorMaterial(vtkOSPRayRendererNode* orn, OSPRenderer oRenderer,
static_cast<float>(diffuseColor[2] * property->GetDiffuse()) };
if (lum > 0.0)
{
OSPMaterial oMaterial = vtkOSPRayMaterialHelpers::NewMaterial(orn, oRenderer, "Luminous");
OSPMaterial oMaterial = vtkOSPRayMaterialHelpers::NewMaterial(orn, oRenderer, "luminous");
ospSetVec3f(oMaterial, "color", diffusef[0], diffusef[1], diffusef[2]);
ospSetFloat(oMaterial, "intensity", lum);
return oMaterial;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment