1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-04-05 18:16:23 +03:00

0031284: Visualization - XCAFDoc_VisMaterialPBR lacks Index of Refraction

Added missing parameter.
This commit is contained in:
kgv 2019-12-27 14:24:58 +03:00 committed by bugmaster
parent 89d855ba58
commit 0858125fd4
9 changed files with 124 additions and 12 deletions

View File

@ -163,12 +163,10 @@ Standard_Boolean BinMXCAFDoc_VisMaterialDriver::Paste (const BinObjMgt_Persisten
aMat->SetDoubleSided (isDoubleSided == '1'); aMat->SetDoubleSided (isDoubleSided == '1');
aMat->SetAlphaMode (alphaModeFromChar (anAlphaMode), anAlphaCutOff); aMat->SetAlphaMode (alphaModeFromChar (anAlphaMode), anAlphaCutOff);
bool hasPbrMat = false; XCAFDoc_VisMaterialPBR aPbrMat;
theSource.GetBoolean (hasPbrMat); theSource.GetBoolean (aPbrMat.IsDefined);
if (hasPbrMat) if (aPbrMat.IsDefined)
{ {
XCAFDoc_VisMaterialPBR aPbrMat;
aPbrMat.IsDefined = true;
readColor (theSource, aPbrMat.BaseColor); readColor (theSource, aPbrMat.BaseColor);
readVec3 (theSource, aPbrMat.EmissiveFactor); readVec3 (theSource, aPbrMat.EmissiveFactor);
theSource.GetShortReal (aPbrMat.Metallic); theSource.GetShortReal (aPbrMat.Metallic);
@ -196,6 +194,22 @@ Standard_Boolean BinMXCAFDoc_VisMaterialDriver::Paste (const BinObjMgt_Persisten
readTexture (theSource, aComMat.DiffuseTexture); readTexture (theSource, aComMat.DiffuseTexture);
aMat->SetCommonMaterial (aComMat); 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; return Standard_True;
} }
@ -242,4 +256,9 @@ void BinMXCAFDoc_VisMaterialDriver::Paste (const Handle(TDF_Attribute)& theSourc
theTarget.PutShortReal (aComMat.Transparency); theTarget.PutShortReal (aComMat.Transparency);
writeTexture (theTarget, aComMat.DiffuseTexture); writeTexture (theTarget, aComMat.DiffuseTexture);
} }
if (aMat->HasPbrMaterial())
{
theTarget.PutShortReal (aMat->PbrMaterial().RefractionIndex);
}
} }

View File

@ -27,7 +27,15 @@ class BinMXCAFDoc_VisMaterialDriver : public BinMDF_ADriver
DEFINE_STANDARD_RTTIEXT(BinMXCAFDoc_VisMaterialDriver, BinMDF_ADriver) DEFINE_STANDARD_RTTIEXT(BinMXCAFDoc_VisMaterialDriver, BinMDF_ADriver)
//! Persistence version (major for breaking changes, minor for adding new fields at end). //! 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: public:
//! Main constructor. //! Main constructor.

View File

@ -204,10 +204,25 @@ Graphic3d_BSDF Graphic3d_BSDF::CreateMetallicRoughness (const Graphic3d_PBRMater
const Standard_ShortReal aRougness2 = thePbr.NormalizedRoughness() * thePbr.NormalizedRoughness(); const Standard_ShortReal aRougness2 = thePbr.NormalizedRoughness() * thePbr.NormalizedRoughness();
Graphic3d_BSDF aBsdf; 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(); 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; return aBsdf;
} }

View File

@ -542,6 +542,7 @@ bool RWGltf_GltfJsonParser::gltfParsePbrMaterial (Handle(RWGltf_MaterialMetallic
const RWGltf_JsonValue* aDoubleSidedVal = findObjectMember (theMatNode, "doubleSided"); const RWGltf_JsonValue* aDoubleSidedVal = findObjectMember (theMatNode, "doubleSided");
const RWGltf_JsonValue* anAlphaModeVal = findObjectMember (theMatNode, "alphaMode"); const RWGltf_JsonValue* anAlphaModeVal = findObjectMember (theMatNode, "alphaMode");
const RWGltf_JsonValue* anAlphaCutoffVal = findObjectMember (theMatNode, "alphaCutoff"); 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) if (aMetalRoughVal == NULL)
{ {
return false; return false;

View File

@ -237,6 +237,8 @@ void XCAFDoc_VisMaterial::FillMaterialAspect (Graphic3d_MaterialAspect& theAspec
aPbr.SetMetallic (myPbrMat.Metallic); aPbr.SetMetallic (myPbrMat.Metallic);
aPbr.SetRoughness(myPbrMat.Roughness); aPbr.SetRoughness(myPbrMat.Roughness);
aPbr.SetEmission (myPbrMat.EmissiveFactor); aPbr.SetEmission (myPbrMat.EmissiveFactor);
aPbr.SetIOR (myPbrMat.RefractionIndex);
theAspect.SetRefractionIndex (myPbrMat.RefractionIndex);
theAspect.SetPBRMaterial (aPbr); theAspect.SetPBRMaterial (aPbr);
theAspect.SetBSDF (Graphic3d_BSDF::CreateMetallicRoughness (aPbr)); theAspect.SetBSDF (Graphic3d_BSDF::CreateMetallicRoughness (aPbr));
} }

View File

@ -31,6 +31,7 @@ struct XCAFDoc_VisMaterialPBR
Graphic3d_Vec3 EmissiveFactor; //!< emissive color; [0.0, 0.0, 0.0] by default 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 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 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 Standard_Boolean IsDefined; //!< defined flag; FALSE by default
//! Empty constructor. //! Empty constructor.
@ -39,6 +40,7 @@ struct XCAFDoc_VisMaterialPBR
EmissiveFactor (0.0f, 0.0f, 0.0f), EmissiveFactor (0.0f, 0.0f, 0.0f),
Metallic (1.0f), Metallic (1.0f),
Roughness (1.0f), Roughness (1.0f),
RefractionIndex (1.5f),
IsDefined (Standard_False) {} IsDefined (Standard_False) {}
//! Compare two materials. //! Compare two materials.
@ -65,7 +67,8 @@ struct XCAFDoc_VisMaterialPBR
&& theOther.BaseColor == BaseColor && theOther.BaseColor == BaseColor
&& theOther.EmissiveFactor == EmissiveFactor && theOther.EmissiveFactor == EmissiveFactor
&& theOther.Metallic == Metallic && theOther.Metallic == Metallic
&& theOther.Roughness == Roughness; && theOther.Roughness == Roughness
&& theOther.RefractionIndex == RefractionIndex;
} }
}; };

View File

@ -878,6 +878,7 @@ static Standard_Integer XGetVisMaterial (Draw_Interpretor& theDI, Standard_Integ
const XCAFDoc_VisMaterialPBR& aMatPbr = aMat->PbrMaterial(); const XCAFDoc_VisMaterialPBR& aMatPbr = aMat->PbrMaterial();
theDI << "PBR.BaseColor: " << (Graphic3d_Vec3 )aMatPbr.BaseColor.GetRGB() << "\n"; theDI << "PBR.BaseColor: " << (Graphic3d_Vec3 )aMatPbr.BaseColor.GetRGB() << "\n";
theDI << "PBR.Transparency: " << (1.0 - aMatPbr.BaseColor.Alpha()) << "\n"; theDI << "PBR.Transparency: " << (1.0 - aMatPbr.BaseColor.Alpha()) << "\n";
theDI << "PBR.RefractionIndex: " << aMatPbr.RefractionIndex << "\n";
if (!aMatPbr.BaseColorTexture.IsNull()) if (!aMatPbr.BaseColorTexture.IsNull())
{ {
theDI << "PBR.BaseColorTexture: " << aMatPbr.BaseColorTexture->TextureId() << "\n"; theDI << "PBR.BaseColorTexture: " << aMatPbr.BaseColorTexture->TextureId() << "\n";
@ -952,6 +953,19 @@ static Standard_Integer XAddVisMaterial (Draw_Interpretor& , Standard_Integer th
} }
aMatPbr.BaseColor.SetAlpha (1.0f - aMatCom.Transparency); 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" else if (anArg == "-alphaMode"
&& anArgIter + 2 < theNbArgs && anArgIter + 2 < theNbArgs
&& parseNormalizedReal (theArgVec[anArgIter + 2], aRealValue)) && parseNormalizedReal (theArgVec[anArgIter + 2], aRealValue))
@ -1301,7 +1315,7 @@ void XDEDRAW_Colors::InitCommands(Draw_Interpretor& di)
__FILE__, XGetVisMaterial, g); __FILE__, XGetVisMaterial, g);
di.Add ("XAddVisMaterial", di.Add ("XAddVisMaterial",
"Doc Material" "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: [-diffuse RGB] [-diffuseTexture ImagePath]"
"\n\t\t: [-specular RGB] [-ambient RGB] [-emissive RGB] [-shininess 0..1]" "\n\t\t: [-specular RGB] [-ambient RGB] [-emissive RGB] [-shininess 0..1]"
"\n\t\t: [-baseColor RGB] [-baseColorTexture ImagePath]" "\n\t\t: [-baseColor RGB] [-baseColorTexture ImagePath]"

View File

@ -25,6 +25,7 @@ IMPLEMENT_DOMSTRING(AlphaMode, "alpha_mode")
IMPLEMENT_DOMSTRING(AlphaCutOff, "alpha_cutoff") IMPLEMENT_DOMSTRING(AlphaCutOff, "alpha_cutoff")
// //
IMPLEMENT_DOMSTRING(BaseColor, "base_color") IMPLEMENT_DOMSTRING(BaseColor, "base_color")
IMPLEMENT_DOMSTRING(RefractionIndex, "ior")
IMPLEMENT_DOMSTRING(EmissiveFactor, "emissive_factor") IMPLEMENT_DOMSTRING(EmissiveFactor, "emissive_factor")
IMPLEMENT_DOMSTRING(Metallic, "metallic") IMPLEMENT_DOMSTRING(Metallic, "metallic")
IMPLEMENT_DOMSTRING(Roughness, "roughness") IMPLEMENT_DOMSTRING(Roughness, "roughness")
@ -253,6 +254,7 @@ Standard_Boolean XmlMXCAFDoc_VisMaterialDriver::Paste (const XmlObjMgt_Persisten
readVec3 (theSource, ::EmissiveFactor(), aPbrMat.EmissiveFactor); readVec3 (theSource, ::EmissiveFactor(), aPbrMat.EmissiveFactor);
readReal (theSource, ::Metallic(), aPbrMat.Metallic); readReal (theSource, ::Metallic(), aPbrMat.Metallic);
readReal (theSource, ::Roughness(), aPbrMat.Roughness); readReal (theSource, ::Roughness(), aPbrMat.Roughness);
readReal (theSource, ::RefractionIndex(), aPbrMat.RefractionIndex);
readTexture (theSource, ::BaseColorTexture(), aPbrMat.BaseColorTexture); readTexture (theSource, ::BaseColorTexture(), aPbrMat.BaseColorTexture);
readTexture (theSource, ::MetallicRoughnessTexture(), aPbrMat.MetallicRoughnessTexture); readTexture (theSource, ::MetallicRoughnessTexture(), aPbrMat.MetallicRoughnessTexture);
readTexture (theSource, ::EmissiveTexture(), aPbrMat.EmissiveTexture); readTexture (theSource, ::EmissiveTexture(), aPbrMat.EmissiveTexture);
@ -298,6 +300,7 @@ void XmlMXCAFDoc_VisMaterialDriver::Paste (const Handle(TDF_Attribute)& theSourc
writeVec3 (theTarget, ::EmissiveFactor(), aPbrMat.EmissiveFactor); writeVec3 (theTarget, ::EmissiveFactor(), aPbrMat.EmissiveFactor);
writeReal (theTarget, ::Metallic(), aPbrMat.Metallic); writeReal (theTarget, ::Metallic(), aPbrMat.Metallic);
writeReal (theTarget, ::Roughness(), aPbrMat.Roughness); writeReal (theTarget, ::Roughness(), aPbrMat.Roughness);
writeReal (theTarget, ::RefractionIndex(), aPbrMat.RefractionIndex);
writeTexture (theTarget, ::BaseColorTexture(), aPbrMat.BaseColorTexture); writeTexture (theTarget, ::BaseColorTexture(), aPbrMat.BaseColorTexture);
writeTexture (theTarget, ::MetallicRoughnessTexture(), aPbrMat.MetallicRoughnessTexture); writeTexture (theTarget, ::MetallicRoughnessTexture(), aPbrMat.MetallicRoughnessTexture);
writeTexture (theTarget, ::EmissiveTexture(), aPbrMat.EmissiveTexture); writeTexture (theTarget, ::EmissiveTexture(), aPbrMat.EmissiveTexture);

47
tests/v3d/materials/ior Normal file
View File

@ -0,0 +1,47 @@
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