Added missing parameter.
aMat->SetDoubleSided (isDoubleSided == '1');
aMat->SetAlphaMode (alphaModeFromChar (anAlphaMode), anAlphaCutOff);
- bool hasPbrMat = false;
- theSource.GetBoolean (hasPbrMat);
- if (hasPbrMat)
+ XCAFDoc_VisMaterialPBR aPbrMat;
+ theSource.GetBoolean (aPbrMat.IsDefined);
+ if (aPbrMat.IsDefined)
{
- XCAFDoc_VisMaterialPBR aPbrMat;
- aPbrMat.IsDefined = true;
readColor (theSource, aPbrMat.BaseColor);
readVec3 (theSource, aPbrMat.EmissiveFactor);
theSource.GetShortReal (aPbrMat.Metallic);
readTexture (theSource, aComMat.DiffuseTexture);
aMat->SetCommonMaterial (aComMat);
}
+
+ if (aVerMaj > MaterialVersionMajor_1
+ || (aVerMaj == MaterialVersionMajor_1
+ && aVerMin >= MaterialVersionMinor_1))
+ {
+ if (aPbrMat.IsDefined)
+ {
+ theSource.GetShortReal (aPbrMat.RefractionIndex);
+ }
+ }
+
+ if (aPbrMat.IsDefined)
+ {
+ aMat->SetPbrMaterial (aPbrMat);
+ }
+
return Standard_True;
}
theTarget.PutShortReal (aComMat.Transparency);
writeTexture (theTarget, aComMat.DiffuseTexture);
}
+
+ if (aMat->HasPbrMaterial())
+ {
+ theTarget.PutShortReal (aMat->PbrMaterial().RefractionIndex);
+ }
}
DEFINE_STANDARD_RTTIEXT(BinMXCAFDoc_VisMaterialDriver, BinMDF_ADriver)
//! Persistence version (major for breaking changes, minor for adding new fields at end).
- enum { MaterialVersionMajor = 1, MaterialVersionMinor = 0 };
+ enum
+ {
+ MaterialVersionMajor_1 = 1,
+ MaterialVersionMinor_0 = 0,
+ MaterialVersionMinor_1 = 1, //!< added IOR
+
+ MaterialVersionMajor = MaterialVersionMajor_1,
+ MaterialVersionMinor = MaterialVersionMinor_1
+ };
public:
//! Main constructor.
const Standard_ShortReal aRougness2 = thePbr.NormalizedRoughness() * thePbr.NormalizedRoughness();
Graphic3d_BSDF aBsdf;
- aBsdf.FresnelBase = Graphic3d_Fresnel::CreateSchlick (aDiff * thePbr.Metallic());
- aBsdf.Ks.SetValues (Graphic3d_Vec3 (thePbr.Alpha()), aRougness2);
- aBsdf.Kt = Graphic3d_Vec3 (1.0f - thePbr.Alpha());
- aBsdf.Kd = aDiff * (1.0f - thePbr.Metallic());
aBsdf.Le = thePbr.Emission();
+ if (thePbr.IOR() > 1.0f
+ && thePbr.Alpha() < 1.0f
+ && thePbr.Metallic() <= ShortRealEpsilon())
+ {
+ aBsdf.FresnelCoat = Graphic3d_Fresnel::CreateDielectric (thePbr.IOR());
+ aBsdf.Kt = Graphic3d_Vec3(1.0f);
+ aBsdf.Kc.r() = aBsdf.Kt.r();
+ aBsdf.Kc.g() = aBsdf.Kt.g();
+ aBsdf.Kc.b() = aBsdf.Kt.b();
+ aBsdf.Absorption.SetValues (thePbr.Color().GetRGB(), thePbr.Alpha() * 0.25f);
+ }
+ else
+ {
+ aBsdf.FresnelBase = Graphic3d_Fresnel::CreateSchlick (aDiff * thePbr.Metallic());
+ aBsdf.Ks.SetValues (Graphic3d_Vec3 (thePbr.Alpha()), aRougness2);
+ aBsdf.Kt = Graphic3d_Vec3 (1.0f - thePbr.Alpha());
+ aBsdf.Kd = aDiff * (1.0f - thePbr.Metallic());
+ }
+
return aBsdf;
}
const RWGltf_JsonValue* aDoubleSidedVal = findObjectMember (theMatNode, "doubleSided");
const RWGltf_JsonValue* anAlphaModeVal = findObjectMember (theMatNode, "alphaMode");
const RWGltf_JsonValue* anAlphaCutoffVal = findObjectMember (theMatNode, "alphaCutoff");
+ // TODO ADOBE_materials_thin_transparency extension can be used to read IOR (Index of Refraction for transparent materials)
if (aMetalRoughVal == NULL)
{
return false;
aPbr.SetMetallic (myPbrMat.Metallic);
aPbr.SetRoughness(myPbrMat.Roughness);
aPbr.SetEmission (myPbrMat.EmissiveFactor);
+ aPbr.SetIOR (myPbrMat.RefractionIndex);
+ theAspect.SetRefractionIndex (myPbrMat.RefractionIndex);
theAspect.SetPBRMaterial (aPbr);
theAspect.SetBSDF (Graphic3d_BSDF::CreateMetallicRoughness (aPbr));
}
Graphic3d_Vec3 EmissiveFactor; //!< emissive color; [0.0, 0.0, 0.0] by default
Standard_ShortReal Metallic; //!< metalness (or scale factor to the texture) within range [0.0, 1.0]; 1.0 by default
Standard_ShortReal Roughness; //!< roughness (or scale factor to the texture) within range [0.0, 1.0]; 1.0 by default
+ Standard_ShortReal RefractionIndex; //!< IOR (index of refraction) within range [1.0, 3.0]; 1.5 by default
Standard_Boolean IsDefined; //!< defined flag; FALSE by default
//! Empty constructor.
EmissiveFactor (0.0f, 0.0f, 0.0f),
Metallic (1.0f),
Roughness (1.0f),
+ RefractionIndex (1.5f),
IsDefined (Standard_False) {}
//! Compare two materials.
&& theOther.BaseColor == BaseColor
&& theOther.EmissiveFactor == EmissiveFactor
&& theOther.Metallic == Metallic
- && theOther.Roughness == Roughness;
+ && theOther.Roughness == Roughness
+ && theOther.RefractionIndex == RefractionIndex;
}
};
const XCAFDoc_VisMaterialPBR& aMatPbr = aMat->PbrMaterial();
theDI << "PBR.BaseColor: " << (Graphic3d_Vec3 )aMatPbr.BaseColor.GetRGB() << "\n";
theDI << "PBR.Transparency: " << (1.0 - aMatPbr.BaseColor.Alpha()) << "\n";
+ theDI << "PBR.RefractionIndex: " << aMatPbr.RefractionIndex << "\n";
if (!aMatPbr.BaseColorTexture.IsNull())
{
theDI << "PBR.BaseColorTexture: " << aMatPbr.BaseColorTexture->TextureId() << "\n";
}
aMatPbr.BaseColor.SetAlpha (1.0f - aMatCom.Transparency);
}
+ else if (anArgIter + 1 < theNbArgs
+ && (anArg == "-refractionindex" || anArg == "-ior"))
+ {
+ aMatPbr.RefractionIndex = (Standard_ShortReal )Draw::Atof (theArgVec[anArgIter + 1]);
+ if (aMatPbr.RefractionIndex < 1.0f || aMatPbr.RefractionIndex > 3.0f)
+ {
+ std::cout << "Syntax error at '" << anArg << "'\n";
+ return 1;
+ }
+
+ ++anArgIter;
+ aMatPbr.IsDefined = true;
+ }
else if (anArg == "-alphaMode"
&& anArgIter + 2 < theNbArgs
&& parseNormalizedReal (theArgVec[anArgIter + 2], aRealValue))
__FILE__, XGetVisMaterial, g);
di.Add ("XAddVisMaterial",
"Doc Material"
- "\n\t\t: [-transparency 0..1] [-alphaMode {Opaque|Mask|Blend|BlendAuto} CutOffValue]"
+ "\n\t\t: [-transparency 0..1] [-alphaMode {Opaque|Mask|Blend|BlendAuto} CutOffValue] [-refractionIndex 1..3]"
"\n\t\t: [-diffuse RGB] [-diffuseTexture ImagePath]"
"\n\t\t: [-specular RGB] [-ambient RGB] [-emissive RGB] [-shininess 0..1]"
"\n\t\t: [-baseColor RGB] [-baseColorTexture ImagePath]"
IMPLEMENT_DOMSTRING(AlphaCutOff, "alpha_cutoff")
//
IMPLEMENT_DOMSTRING(BaseColor, "base_color")
+IMPLEMENT_DOMSTRING(RefractionIndex, "ior")
IMPLEMENT_DOMSTRING(EmissiveFactor, "emissive_factor")
IMPLEMENT_DOMSTRING(Metallic, "metallic")
IMPLEMENT_DOMSTRING(Roughness, "roughness")
readVec3 (theSource, ::EmissiveFactor(), aPbrMat.EmissiveFactor);
readReal (theSource, ::Metallic(), aPbrMat.Metallic);
readReal (theSource, ::Roughness(), aPbrMat.Roughness);
+ readReal (theSource, ::RefractionIndex(), aPbrMat.RefractionIndex);
readTexture (theSource, ::BaseColorTexture(), aPbrMat.BaseColorTexture);
readTexture (theSource, ::MetallicRoughnessTexture(), aPbrMat.MetallicRoughnessTexture);
readTexture (theSource, ::EmissiveTexture(), aPbrMat.EmissiveTexture);
writeVec3 (theTarget, ::EmissiveFactor(), aPbrMat.EmissiveFactor);
writeReal (theTarget, ::Metallic(), aPbrMat.Metallic);
writeReal (theTarget, ::Roughness(), aPbrMat.Roughness);
+ writeReal (theTarget, ::RefractionIndex(), aPbrMat.RefractionIndex);
writeTexture (theTarget, ::BaseColorTexture(), aPbrMat.BaseColorTexture);
writeTexture (theTarget, ::MetallicRoughnessTexture(), aPbrMat.MetallicRoughnessTexture);
writeTexture (theTarget, ::EmissiveTexture(), aPbrMat.EmissiveTexture);
--- /dev/null
+puts "========"
+puts "0031284: Visualization - XCAFDoc_VisMaterialPBR lacks Index of Refraction"
+puts "========"
+
+pload MODELING XDE OCAF VISUALIZATION
+box b 0.5 1.0 -0.5 3 1 1
+psphere s1 0.5
+psphere s2 0.5
+psphere s3 0.5
+ttranslate s1 1 0 0
+ttranslate s2 2 0 0
+ttranslate s3 3 0 0
+catch { Close D }
+XNewDoc D
+set l0 [XAddShape D b 0]
+set l1 [XAddShape D s1 0]
+set l2 [XAddShape D s2 0]
+set l3 [XAddShape D s3 0]
+XAddVisMaterial D m1 -baseColor GREEN -refractionIndex 1.0 -transparency 0.5 -metallic 0 -roughness 0
+XAddVisMaterial D m2 -baseColor GREEN -refractionIndex 1.3 -transparency 0.5 -metallic 0 -roughness 0
+XAddVisMaterial D m3 -baseColor GREEN -refractionIndex 2.5 -transparency 0.5 -metallic 0 -roughness 0
+XSetVisMaterial D $l1 m1
+XSetVisMaterial D $l2 m2
+XSetVisMaterial D $l3 m3
+
+vclear
+vinit View1
+vcamera -persp
+vfront
+XDisplay -dispMode 1 D
+vfit
+vviewparams -scale 245 -proj -0 -0.75 -0.66 -up 0 -0.66 0.75 -at 2.0 0.84 0.04
+vlight -change 0 -intensity 2.5
+vlight -change 1 -intensity 1.0
+set aCubeMap [locate_data_file Circus_CubeMap_V.png]
+vbackground -cubemap $aCubeMap
+
+vrenderparams -shadingModel PBR -raster
+vdump $imagedir/${casename}_pbr.png
+
+vrenderparams -raytrace -gi 0 -reflections 1 -rayDepth 10
+vfps 200
+vdump $imagedir/${casename}_rt.png
+
+vrenderparams -raytrace -gi 1
+vfps 200
+vdump $imagedir/${casename}_pt.png