From 611684187de2a7b7c59c33f7da9ca51afa64a326 Mon Sep 17 00:00:00 2001 From: kgv Date: Fri, 30 Aug 2019 21:52:12 +0300 Subject: [PATCH] 0029516: Visualization - eliminate redundant property Graphic3d_MaterialAspect::ReflectionMode() Decomposition of Ambient, Diffuse, Specular and Emissive properties has been eliminated within *Graphic3d_MaterialAspect* definition, so that following methods of *Graphic3d_MaterialAspect* class have been removed: SetReflectionMode(), SetReflectionModeOn(), Ambient(), Diffuse(), Emissive(), Specular(), SetAmbient(), SetDiffuse(), SetSpecular(), SetEmissive(). Graphic3d_NOM_NEON_GNC non-physical material definition has been corrected and define WHITE emission color coefficient instead of YELLOW. Added method Graphic3d_ClipPlane::SetCappingColor() for more straight-forward modification of Capping color in case of non-physical material. Prs3d_ShadingAspect::Color() has been fixed to return InteriorColor instead of material color coefficient in case of non-physical material. --- dox/dev_guides/upgrade/upgrade.md | 34 ++ samples/mfc/standard/Common/User_Cylinder.cxx | 8 +- src/AIS/AIS_Dimension.cxx | 12 +- src/AIS/AIS_Manipulator.cxx | 17 +- src/AIS/AIS_Shape.cxx | 2 +- src/AIS/AIS_Triangulation.cxx | 2 +- src/AIS/AIS_ViewCube.cxx | 8 +- src/Graphic3d/Graphic3d_ClipPlane.cxx | 20 +- src/Graphic3d/Graphic3d_ClipPlane.hxx | 6 + src/Graphic3d/Graphic3d_MaterialAspect.cxx | 476 +++++++----------- src/Graphic3d/Graphic3d_MaterialAspect.hxx | 114 ++--- .../MeshVS_ElementalColorPrsBuilder.cxx | 38 +- src/MeshVS/MeshVS_MeshPrsBuilder.cxx | 16 +- src/MeshVS/MeshVS_NodalColorPrsBuilder.cxx | 30 +- src/OpenGl/OpenGl_Aspects.cxx | 12 +- src/OpenGl/OpenGl_Material.hxx | 8 + src/OpenGl/OpenGl_SceneGeometry.cxx | 60 --- src/OpenGl/OpenGl_SceneGeometry.hxx | 100 +--- src/OpenGl/OpenGl_View.hxx | 1 - src/OpenGl/OpenGl_View_Raytrace.cxx | 117 ++--- src/OpenGl/OpenGl_Workspace.cxx | 62 +-- src/Prs3d/Prs3d_ShadingAspect.cxx | 8 +- src/QABugs/QABugs_17.cxx | 8 +- src/QABugs/QABugs_PresentableObject.cxx | 8 +- src/V3d/V3d_Trihedron.cxx | 2 +- src/ViewerTest/ViewerTest.cxx | 22 +- src/ViewerTest/ViewerTest_ObjectCommands.cxx | 4 +- src/ViewerTest/ViewerTest_OpenGlCommands.cxx | 16 +- src/ViewerTest/ViewerTest_ViewerCommands.cxx | 35 +- 29 files changed, 479 insertions(+), 767 deletions(-) diff --git a/dox/dev_guides/upgrade/upgrade.md b/dox/dev_guides/upgrade/upgrade.md index 191c665680..09bc12a249 100644 --- a/dox/dev_guides/upgrade/upgrade.md +++ b/dox/dev_guides/upgrade/upgrade.md @@ -1716,6 +1716,40 @@ aGroup->SetPrimitivesAspect (myDrawer->LineAspect()->Aspect()); //!< next array aGroup->AddPrimitiveArray (aLines); ~~~~ +@subsection upgrade_740_materials Material definition + +Decomposition of Ambient, Diffuse, Specular and Emissive properties has been eliminated within *Graphic3d_MaterialAspect* definition. +As result, the following methods of *Graphic3d_MaterialAspect* class have been removed: SetReflectionMode(), SetReflectionModeOn(), Ambient(), Diffuse(), Emissive(), Specular(), SetAmbient(), SetDiffuse(), SetSpecular(), SetEmissive(). + +Previously, computation of final value required the following code: +~~~~ +Graphic3d_MaterialAspect theMaterial; Quantity_Color theInteriorColor; +Graphic3d_Vec3 anAmbient (0.0f); +if (theMaterial.ReflectionMode (Graphic3d_TOR_AMBIENT)) +{ + anAmbient = theMaterial.MaterialType (Graphic3d_MATERIAL_ASPECT) + ? (Graphic3d_Vec3 )theInteriorColor * theMaterial.Ambient() + : (Graphic3d_Vec3 )theMaterial.AmbientColor() * theMaterial.Ambient(); +} +~~~~ + +New code looks like this: +~~~~ +Graphic3d_MaterialAspect theMaterial; Quantity_Color theInteriorColor; +Graphic3d_Vec3 anAmbient = theMaterial.AmbientColor(); +if (theMaterial.MaterialType (Graphic3d_MATERIAL_ASPECT)) { anAmbient *= (Graphic3d_Vec3 )theInteriorColor; } +~~~~ + +Existing code should be updated to: +- Replace Graphic3d_MaterialAspect::SetReflectionModeOff() with setting black color; SetReflectionModeOn() calls can be simply removed. + R.g. theMaterial.SetAmbientColor(Quantity_NOC_BLACK). +- Replace Graphic3d_MaterialAspect::Ambient(), SetAmbient(), Diffuse(), SetDiffuse(), Specular(), SetSpecular(), Emissive(), SetEmissive() with methods working with pre-multiplied color. + E.g. theMaterial.SetAmbientColor(Graphic3d_Vec3 (1.0f, 0.0f, 0.0f) * 0.2f). +- Avoid using Graphic3d_MaterialAspect::Color() and SetColor() with non-physical materials (Graphic3d_MATERIAL_ASPECT). + These materials do not include color definition, because it is taken from Graphic3d_Aspects::InteriorColor() - this has not been changed. + However, previously it was possible storing the color with SetColor() call and then fetching it with Color() by application code (the rendering ignored this value); + now SetColor() explicitly ignores call for Graphic3d_MATERIAL_ASPECT materials and Color() returns DiffuseColor() multiplication coefficients. + @subsection upgrade_740_text Changes in Graphic3d_Text and OpenGl_Text API Parameters of *Text* in *Graphic3d_Group* are moved into a new *Graphic3d_Text* class. *AddText* of *Graphic3d_Group* should be used instead of the previous *Text*. diff --git a/samples/mfc/standard/Common/User_Cylinder.cxx b/samples/mfc/standard/Common/User_Cylinder.cxx index da2986150b..94adb35aa8 100755 --- a/samples/mfc/standard/Common/User_Cylinder.cxx +++ b/samples/mfc/standard/Common/User_Cylinder.cxx @@ -79,10 +79,10 @@ case 6: //color Handle(Graphic3d_Group) mygroup = Prs3d_Root::CurrentGroup(aPresentation); myAspect = (new Prs3d_ShadingAspect())->Aspect(); Graphic3d_MaterialAspect material = myAspect->FrontMaterial(); - material.SetReflectionModeOff(Graphic3d_TOR_AMBIENT); - material.SetReflectionModeOff(Graphic3d_TOR_DIFFUSE); - material.SetReflectionModeOff(Graphic3d_TOR_SPECULAR); - material.SetReflectionModeOff(Graphic3d_TOR_EMISSION); + material.SetAmbientColor (Quantity_NOC_BLACK); + material.SetDiffuseColor (Quantity_NOC_BLACK); + material.SetSpecularColor(Quantity_NOC_BLACK); + material.SetEmissiveColor(Quantity_NOC_BLACK); myAspect->SetFrontMaterial(material); mygroup->SetPrimitivesAspect(myAspect); diff --git a/src/AIS/AIS_Dimension.cxx b/src/AIS/AIS_Dimension.cxx index 25473a029d..7668b4a6b4 100755 --- a/src/AIS/AIS_Dimension.cxx +++ b/src/AIS/AIS_Dimension.cxx @@ -404,9 +404,9 @@ void AIS_Dimension::DrawArrow (const Handle(Prs3d_Presentation)& thePresentation // Set aspect for arrow triangles Graphic3d_MaterialAspect aShadeMat (Graphic3d_NOM_DEFAULT); - aShadeMat.SetReflectionModeOff (Graphic3d_TOR_AMBIENT); - aShadeMat.SetReflectionModeOff (Graphic3d_TOR_DIFFUSE); - aShadeMat.SetReflectionModeOff (Graphic3d_TOR_SPECULAR); + aShadeMat.SetAmbientColor (Quantity_NOC_BLACK); + aShadeMat.SetDiffuseColor (Quantity_NOC_BLACK); + aShadeMat.SetSpecularColor(Quantity_NOC_BLACK); Handle(Prs3d_ShadingAspect) aShadingStyle = new Prs3d_ShadingAspect(); aShadingStyle->SetColor (myDrawer->DimensionAspect()->ArrowAspect()->Aspect()->Color()); @@ -530,9 +530,9 @@ void AIS_Dimension::drawText (const Handle(Prs3d_Presentation)& thePresentation, } Graphic3d_MaterialAspect aShadeMat (Graphic3d_NOM_DEFAULT); - aShadeMat.SetReflectionModeOff (Graphic3d_TOR_AMBIENT); - aShadeMat.SetReflectionModeOff (Graphic3d_TOR_DIFFUSE); - aShadeMat.SetReflectionModeOff (Graphic3d_TOR_SPECULAR); + aShadeMat.SetAmbientColor (Quantity_NOC_BLACK); + aShadeMat.SetDiffuseColor (Quantity_NOC_BLACK); + aShadeMat.SetSpecularColor(Quantity_NOC_BLACK); myDrawer->ShadingAspect()->Aspect()->SetInteriorColor (aColor); myDrawer->ShadingAspect()->Aspect()->SetBackInteriorColor (aColor); myDrawer->ShadingAspect()->SetMaterial (aShadeMat); diff --git a/src/AIS/AIS_Manipulator.cxx b/src/AIS/AIS_Manipulator.cxx index 248e61d648..a7503e71b2 100644 --- a/src/AIS/AIS_Manipulator.cxx +++ b/src/AIS/AIS_Manipulator.cxx @@ -132,7 +132,7 @@ void AIS_Manipulator::init() myAxes[2] = Axis (gp::OZ(), Quantity_NOC_BLUE1); Graphic3d_MaterialAspect aShadingMaterial; - aShadingMaterial.SetReflectionModeOff (Graphic3d_TOR_SPECULAR); + aShadingMaterial.SetSpecularColor(Quantity_NOC_BLACK); aShadingMaterial.SetMaterialType (Graphic3d_MATERIAL_ASPECT); myDrawer->SetShadingAspect (new Prs3d_ShadingAspect()); @@ -142,10 +142,10 @@ void AIS_Manipulator::init() Graphic3d_MaterialAspect aHilightMaterial; aHilightMaterial.SetColor (Quantity_NOC_AZURE); - aHilightMaterial.SetReflectionModeOff (Graphic3d_TOR_AMBIENT); - aHilightMaterial.SetReflectionModeOff (Graphic3d_TOR_DIFFUSE); - aHilightMaterial.SetReflectionModeOff (Graphic3d_TOR_SPECULAR); - aHilightMaterial.SetReflectionModeOff (Graphic3d_TOR_EMISSION); + aHilightMaterial.SetAmbientColor (Quantity_NOC_BLACK); + aHilightMaterial.SetDiffuseColor (Quantity_NOC_BLACK); + aHilightMaterial.SetSpecularColor(Quantity_NOC_BLACK); + aHilightMaterial.SetEmissiveColor(Quantity_NOC_BLACK); aHilightMaterial.SetMaterialType (Graphic3d_MATERIAL_ASPECT); myHighlightAspect = new Prs3d_ShadingAspect(); @@ -153,11 +153,10 @@ void AIS_Manipulator::init() myHighlightAspect->SetMaterial (aHilightMaterial); Graphic3d_MaterialAspect aDraggerMaterial; - aDraggerMaterial.SetReflectionModeOff(Graphic3d_TOR_DIFFUSE); - aDraggerMaterial.SetReflectionModeOff(Graphic3d_TOR_SPECULAR); - aDraggerMaterial.SetReflectionModeOff(Graphic3d_TOR_EMISSION); + aDraggerMaterial.SetAmbientColor (Quantity_NOC_BLACK); + aDraggerMaterial.SetDiffuseColor (Quantity_NOC_BLACK); + aDraggerMaterial.SetSpecularColor(Quantity_NOC_BLACK); aDraggerMaterial.SetMaterialType(Graphic3d_MATERIAL_ASPECT); - aDraggerMaterial.SetAmbient(1.0); myDraggerHighlight = new Prs3d_ShadingAspect(); myDraggerHighlight->Aspect()->SetInteriorStyle(Aspect_IS_SOLID); diff --git a/src/AIS/AIS_Shape.cxx b/src/AIS/AIS_Shape.cxx index adfd5cc43e..72674e733d 100644 --- a/src/AIS/AIS_Shape.cxx +++ b/src/AIS/AIS_Shape.cxx @@ -637,7 +637,7 @@ void AIS_Shape::setMaterial (const Handle(Prs3d_Drawer)& theDrawer, const Standard_Boolean theToKeepColor, const Standard_Boolean theToKeepTransp) const { - const Quantity_Color aColor = theDrawer->ShadingAspect()->Material (myCurrentFacingModel).Color(); + const Quantity_Color aColor = theDrawer->ShadingAspect()->Color (myCurrentFacingModel); const Standard_Real aTransp = theDrawer->ShadingAspect()->Transparency (myCurrentFacingModel); theDrawer->SetupOwnShadingAspect(); theDrawer->ShadingAspect()->SetMaterial (theMaterial, myCurrentFacingModel); diff --git a/src/AIS/AIS_Triangulation.cxx b/src/AIS/AIS_Triangulation.cxx index 20e39471e6..dfc0d1e8f1 100644 --- a/src/AIS/AIS_Triangulation.cxx +++ b/src/AIS/AIS_Triangulation.cxx @@ -137,7 +137,7 @@ void AIS_Triangulation::Compute(const Handle(PrsMgr_PresentationManager3d)& /*aP Standard_Integer i; Standard_Integer j; - Standard_Real ambient = aspect->FrontMaterial().Ambient(); + const Standard_Real ambient = 0.2; if (hasVNormals) { const TShort_Array1OfShortReal& normals = myTriangulation->Normals(); diff --git a/src/AIS/AIS_ViewCube.cxx b/src/AIS/AIS_ViewCube.cxx index 3fdc7ce564..efa57800db 100644 --- a/src/AIS/AIS_ViewCube.cxx +++ b/src/AIS/AIS_ViewCube.cxx @@ -223,10 +223,10 @@ void AIS_ViewCube::setDefaultAttributes() void AIS_ViewCube::setDefaultHighlightAttributes() { Graphic3d_MaterialAspect aHighlightMaterial; - aHighlightMaterial.SetReflectionModeOff (Graphic3d_TOR_AMBIENT); - aHighlightMaterial.SetReflectionModeOff (Graphic3d_TOR_DIFFUSE); - aHighlightMaterial.SetReflectionModeOff (Graphic3d_TOR_SPECULAR); - aHighlightMaterial.SetReflectionModeOff (Graphic3d_TOR_EMISSION); + aHighlightMaterial.SetAmbientColor (Quantity_NOC_BLACK); + aHighlightMaterial.SetDiffuseColor (Quantity_NOC_BLACK); + aHighlightMaterial.SetSpecularColor(Quantity_NOC_BLACK); + aHighlightMaterial.SetEmissiveColor(Quantity_NOC_BLACK); aHighlightMaterial.SetMaterialType (Graphic3d_MATERIAL_ASPECT); myDynHilightDrawer->SetShadingAspect (new Prs3d_ShadingAspect()); myDynHilightDrawer->ShadingAspect()->SetMaterial (aHighlightMaterial); diff --git a/src/Graphic3d/Graphic3d_ClipPlane.cxx b/src/Graphic3d/Graphic3d_ClipPlane.cxx index 22ac56c4b6..4cc44913e2 100755 --- a/src/Graphic3d/Graphic3d_ClipPlane.cxx +++ b/src/Graphic3d/Graphic3d_ClipPlane.cxx @@ -27,13 +27,13 @@ namespace static Handle(Graphic3d_AspectFillArea3d) defaultAspect() { - const Graphic3d_MaterialAspect aMaterial (Graphic3d_NOM_DEFAULT); + Graphic3d_MaterialAspect aMaterial (Graphic3d_NOM_DEFAULT); Handle(Graphic3d_AspectFillArea3d) anAspect = new Graphic3d_AspectFillArea3d(); anAspect->SetDistinguishOff(); anAspect->SetFrontMaterial (aMaterial); anAspect->SetHatchStyle (Aspect_HS_HORIZONTAL); anAspect->SetInteriorStyle (Aspect_IS_SOLID); - anAspect->SetInteriorColor (aMaterial.Color()); + anAspect->SetInteriorColor (Quantity_NOC_GRAY20); anAspect->SetSuppressBackFaces (false); return anAspect; } @@ -177,6 +177,17 @@ Handle(Graphic3d_ClipPlane) Graphic3d_ClipPlane::Clone() const return new Graphic3d_ClipPlane(*this); } +// ======================================================================= +// function : SetCappingColor +// purpose : +// ======================================================================= +void Graphic3d_ClipPlane::SetCappingColor (const Quantity_Color& theColor) +{ + myAspect->SetInteriorColor (theColor); + myAspect->ChangeFrontMaterial().SetColor (theColor); + ++myAspectMod; +} + // ======================================================================= // function : SetCappingMaterial // purpose : @@ -184,7 +195,10 @@ Handle(Graphic3d_ClipPlane) Graphic3d_ClipPlane::Clone() const void Graphic3d_ClipPlane::SetCappingMaterial (const Graphic3d_MaterialAspect& theMat) { myAspect->SetFrontMaterial (theMat); - myAspect->SetInteriorColor (theMat.Color()); + if (myAspect->FrontMaterial().MaterialType() != Graphic3d_MATERIAL_ASPECT) + { + myAspect->SetInteriorColor (theMat.Color()); + } ++myAspectMod; } diff --git a/src/Graphic3d/Graphic3d_ClipPlane.hxx b/src/Graphic3d/Graphic3d_ClipPlane.hxx index 41259dbee2..595034e507 100755 --- a/src/Graphic3d/Graphic3d_ClipPlane.hxx +++ b/src/Graphic3d/Graphic3d_ClipPlane.hxx @@ -166,6 +166,12 @@ public: public: // @name user-defined graphical attributes + //! Return color for rendering capping surface. + Quantity_Color CappingColor() const { return myAspect->FrontMaterial().MaterialType() == Graphic3d_MATERIAL_ASPECT ? myAspect->FrontMaterial().Color() : myAspect->InteriorColor(); } + + //! Set color for rendering capping surface. + Standard_EXPORT void SetCappingColor (const Quantity_Color& theColor); + //! Set material for rendering capping surface. //! @param theMat [in] the material. Standard_EXPORT void SetCappingMaterial (const Graphic3d_MaterialAspect& theMat); diff --git a/src/Graphic3d/Graphic3d_MaterialAspect.cxx b/src/Graphic3d/Graphic3d_MaterialAspect.cxx index 8888c83a64..9e9624be2d 100644 --- a/src/Graphic3d/Graphic3d_MaterialAspect.cxx +++ b/src/Graphic3d/Graphic3d_MaterialAspect.cxx @@ -25,14 +25,14 @@ namespace { const char* StringName; Graphic3d_BSDF BSDF; - Quantity_Color Colors [Graphic3d_TypeOfReflection_NB]; - Standard_ShortReal ColorCoef[Graphic3d_TypeOfReflection_NB]; + Quantity_Color Colors[Graphic3d_TypeOfReflection_NB]; Standard_ShortReal TransparencyCoef; Standard_ShortReal RefractionIndex; Standard_ShortReal Shininess; + Standard_ShortReal AmbientCoef; //!< coefficient for Graphic3d_MaterialAspect::SetColor() + Standard_ShortReal DiffuseCoef; //!< coefficient for Graphic3d_MaterialAspect::SetColor() Graphic3d_TypeOfMaterial MaterialType; Graphic3d_NameOfMaterial MaterialName; - Standard_Boolean ReflActivity[Graphic3d_TypeOfReflection_NB]; RawMaterial (Graphic3d_NameOfMaterial theName, const char* theStringName); @@ -80,62 +80,59 @@ RawMaterial::RawMaterial (Graphic3d_NameOfMaterial theName, const char* theStrin TransparencyCoef(0.0f), RefractionIndex (1.0f), Shininess (0.039f), + AmbientCoef (0.25f), + DiffuseCoef (1.0f), MaterialType (Graphic3d_MATERIAL_ASPECT), MaterialName (theName) { - ReflActivity[Graphic3d_TOR_AMBIENT] = Standard_True; - ReflActivity[Graphic3d_TOR_DIFFUSE] = Standard_True; - ReflActivity[Graphic3d_TOR_SPECULAR] = Standard_True; - ReflActivity[Graphic3d_TOR_EMISSION] = Standard_False; - - ColorCoef[Graphic3d_TOR_AMBIENT] = 0.3f; - ColorCoef[Graphic3d_TOR_DIFFUSE] = 0.65f; - ColorCoef[Graphic3d_TOR_SPECULAR] = 0.0f; - ColorCoef[Graphic3d_TOR_EMISSION] = 0.0f; - - Colors[Graphic3d_TOR_AMBIENT] = Quantity_Color (Graphic3d_Vec3 (0.2f, 0.2f, 0.2f)); - Colors[Graphic3d_TOR_DIFFUSE] = Quantity_Color (Graphic3d_Vec3 (0.2f, 0.2f, 0.2f)); - Colors[Graphic3d_TOR_SPECULAR] = Quantity_Color (Graphic3d_Vec3 (1.0f, 1.0f, 1.0f)); switch (theName) { case Graphic3d_NOM_PLASTIC: - Shininess = 0.0078125f; - ColorCoef[Graphic3d_TOR_AMBIENT] = 0.50f; - ColorCoef[Graphic3d_TOR_DIFFUSE] = 0.24f; - ColorCoef[Graphic3d_TOR_SPECULAR] = 0.06f; + MaterialType = Graphic3d_MATERIAL_ASPECT; - BSDF.Kd = static_cast (Colors[Graphic3d_TOR_DIFFUSE]); + Shininess = 0.0078125f; + Colors[Graphic3d_TOR_AMBIENT] = Quantity_Color (Graphic3d_Vec3 (0.50f)); + Colors[Graphic3d_TOR_DIFFUSE] = Quantity_Color (Graphic3d_Vec3 (0.24f)); + Colors[Graphic3d_TOR_SPECULAR] = Quantity_Color (Graphic3d_Vec3 (0.06f)); + Colors[Graphic3d_TOR_EMISSION] = Quantity_Color (Graphic3d_Vec3 (0.0f)); + + BSDF.Kd = Graphic3d_Vec3 (0.2f); BSDF.Ks = Graphic3d_Vec4 (0.00784314f, 0.00784314f, 0.00784314f, 0.25f); BSDF.Normalize(); break; case Graphic3d_NOM_SHINY_PLASTIC: - Shininess = 1.00f; - ColorCoef[Graphic3d_TOR_AMBIENT] = 0.44f; - ColorCoef[Graphic3d_TOR_DIFFUSE] = 0.50f; - ColorCoef[Graphic3d_TOR_SPECULAR] = 1.00f; + MaterialType = Graphic3d_MATERIAL_ASPECT; - BSDF.Kd = static_cast (Colors[Graphic3d_TOR_DIFFUSE]); + Shininess = 1.00f; + Colors[Graphic3d_TOR_AMBIENT] = Quantity_Color (Graphic3d_Vec3 (0.44f)); + Colors[Graphic3d_TOR_DIFFUSE] = Quantity_Color (Graphic3d_Vec3 (0.50f)); + Colors[Graphic3d_TOR_SPECULAR] = Quantity_Color (Graphic3d_Vec3 (1.0f)); + Colors[Graphic3d_TOR_EMISSION] = Quantity_Color (Graphic3d_Vec3 (0.0f)); + + BSDF.Kd = Graphic3d_Vec3 (0.2f); BSDF.Ks = Graphic3d_Vec4 (0.145f, 0.145f, 0.145f, 0.17f); BSDF.Normalize(); break; case Graphic3d_NOM_SATIN: - Shininess = 0.09375f; - ColorCoef[Graphic3d_TOR_AMBIENT] = 0.33f; - ColorCoef[Graphic3d_TOR_DIFFUSE] = 0.40f; - ColorCoef[Graphic3d_TOR_SPECULAR] = 0.44f; + MaterialType = Graphic3d_MATERIAL_ASPECT; + + Shininess = 0.09375f; + Colors[Graphic3d_TOR_AMBIENT] = Quantity_Color (Graphic3d_Vec3 (0.33f)); + Colors[Graphic3d_TOR_DIFFUSE] = Quantity_Color (Graphic3d_Vec3 (0.40f)); + Colors[Graphic3d_TOR_SPECULAR] = Quantity_Color (Graphic3d_Vec3 (0.44f)); + Colors[Graphic3d_TOR_EMISSION] = Quantity_Color (Graphic3d_Vec3 (0.0f)); BSDF.Kd = Graphic3d_Vec3 (0.2f); BSDF.Ks = Graphic3d_Vec4 (0.6f); - break; case Graphic3d_NOM_NEON_GNC: - Shininess = 0.05f; - ColorCoef[Graphic3d_TOR_AMBIENT] = 1.00f; - ColorCoef[Graphic3d_TOR_DIFFUSE] = 1.00f; - ColorCoef[Graphic3d_TOR_SPECULAR] = 0.62f; - ColorCoef[Graphic3d_TOR_EMISSION] = 1.00f; - ReflActivity[Graphic3d_TOR_AMBIENT] = Standard_False; - ReflActivity[Graphic3d_TOR_EMISSION] = Standard_True; + MaterialType = Graphic3d_MATERIAL_ASPECT; + + Shininess = 0.05f; + Colors[Graphic3d_TOR_AMBIENT] = Quantity_Color (Graphic3d_Vec3 (0.0f)); + Colors[Graphic3d_TOR_DIFFUSE] = Quantity_Color (Graphic3d_Vec3 (1.0f)); + Colors[Graphic3d_TOR_SPECULAR] = Quantity_Color (Graphic3d_Vec3 (0.62f)); + Colors[Graphic3d_TOR_EMISSION] = Quantity_Color (Graphic3d_Vec3 (1.0f)); BSDF.Kd = Graphic3d_Vec3 (0.0f); BSDF.Ks = Graphic3d_Vec4 (0.5f, 0.5f, 0.5f, 0.f); @@ -143,199 +140,160 @@ RawMaterial::RawMaterial (Graphic3d_NameOfMaterial theName, const char* theStrin BSDF.FresnelBase = Graphic3d_Fresnel::CreateDielectric (1.5f); break; case Graphic3d_NOM_METALIZED: - Shininess = 0.13f; - ColorCoef[Graphic3d_TOR_AMBIENT] = 0.90f; - ColorCoef[Graphic3d_TOR_DIFFUSE] = 0.47f; - ColorCoef[Graphic3d_TOR_SPECULAR] = 0.45f; - ReflActivity[Graphic3d_TOR_AMBIENT] = Standard_False; - { - const Graphic3d_Vec3 aColor = (Graphic3d_Vec3 )Colors[Graphic3d_TOR_DIFFUSE]; - BSDF = Graphic3d_BSDF::CreateMetallic (Graphic3d_Vec3 (0.985f, 0.985f, 0.985f), - Graphic3d_Fresnel::CreateSchlick (aColor), 0.045f); - } + MaterialType = Graphic3d_MATERIAL_ASPECT; + + Shininess = 0.13f; + Colors[Graphic3d_TOR_AMBIENT] = Quantity_Color (Graphic3d_Vec3 (0.0f)); + Colors[Graphic3d_TOR_DIFFUSE] = Quantity_Color (Graphic3d_Vec3 (0.47f)); + Colors[Graphic3d_TOR_SPECULAR] = Quantity_Color (Graphic3d_Vec3 (0.45f)); + Colors[Graphic3d_TOR_EMISSION] = Quantity_Color (Graphic3d_Vec3 (0.0f)); + + BSDF = Graphic3d_BSDF::CreateMetallic (Graphic3d_Vec3 (0.985f, 0.985f, 0.985f), + Graphic3d_Fresnel::CreateSchlick (Graphic3d_Vec3 (0.2f)), 0.045f); break; - // Ascending Compatibility physical materials. The same definition is taken as in the next constructor. case Graphic3d_NOM_BRASS: MaterialType = Graphic3d_MATERIAL_PHYSIC; - Shininess = 0.65f; - ColorCoef[Graphic3d_TOR_AMBIENT] = 1.00f; - ColorCoef[Graphic3d_TOR_DIFFUSE] = 1.00f; - ColorCoef[Graphic3d_TOR_SPECULAR] = 1.00f; - BSDF = Graphic3d_BSDF::CreateMetallic (Graphic3d_Vec3 (0.985f, 0.985f, 0.985f), Graphic3d_Fresnel::CreateSchlick (Graphic3d_Vec3 (0.58f, 0.42f, 0.20f)), 0.045f); + Shininess = 0.65f; Colors[Graphic3d_TOR_AMBIENT] = Quantity_Color (Graphic3d_Vec3 (0.329f, 0.224f, 0.027f)); Colors[Graphic3d_TOR_DIFFUSE] = Quantity_Color (Graphic3d_Vec3 (0.780f, 0.569f, 0.114f)); Colors[Graphic3d_TOR_SPECULAR] = Quantity_Color (Graphic3d_Vec3 (0.992f, 0.941f, 0.808f)); + Colors[Graphic3d_TOR_EMISSION] = Quantity_Color (Graphic3d_Vec3 (0.0f)); break; case Graphic3d_NOM_BRONZE: MaterialType = Graphic3d_MATERIAL_PHYSIC; - Shininess = 0.65f; - ColorCoef[Graphic3d_TOR_AMBIENT] = 1.00f; - ColorCoef[Graphic3d_TOR_DIFFUSE] = 1.00f; - ColorCoef[Graphic3d_TOR_SPECULAR] = 1.00f; - BSDF = Graphic3d_BSDF::CreateMetallic (Graphic3d_Vec3 (0.985f, 0.985f, 0.985f), Graphic3d_Fresnel::CreateSchlick (Graphic3d_Vec3 (0.65f, 0.35f, 0.15f)), 0.045f); + Shininess = 0.65f; Colors[Graphic3d_TOR_AMBIENT] = Quantity_Color (Graphic3d_Vec3 (0.213f, 0.128f, 0.054f)); Colors[Graphic3d_TOR_DIFFUSE] = Quantity_Color (Graphic3d_Vec3 (0.714f, 0.428f, 0.181f)); Colors[Graphic3d_TOR_SPECULAR] = Quantity_Color (Graphic3d_Vec3 (0.590f, 0.408f, 0.250f)); + Colors[Graphic3d_TOR_EMISSION] = Quantity_Color (Graphic3d_Vec3 (0.0f)); break; case Graphic3d_NOM_COPPER: MaterialType = Graphic3d_MATERIAL_PHYSIC; - Shininess = 0.65f; - ColorCoef[Graphic3d_TOR_AMBIENT] = 1.00f; - ColorCoef[Graphic3d_TOR_DIFFUSE] = 1.00f; - ColorCoef[Graphic3d_TOR_SPECULAR] = 1.00f; - BSDF = Graphic3d_BSDF::CreateMetallic (Graphic3d_Vec3 (0.985f, 0.985f, 0.985f), Graphic3d_Fresnel::CreateSchlick (Graphic3d_Vec3 (0.955008f, 0.637427f, 0.538163f)), 0.045f); + Shininess = 0.65f; Colors[Graphic3d_TOR_AMBIENT] = Quantity_Color (Graphic3d_Vec3 (0.191f, 0.074f, 0.023f)); Colors[Graphic3d_TOR_DIFFUSE] = Quantity_Color (Graphic3d_Vec3 (0.604f, 0.270f, 0.083f)); Colors[Graphic3d_TOR_SPECULAR] = Quantity_Color (Graphic3d_Vec3 (0.950f, 0.640f, 0.540f)); + Colors[Graphic3d_TOR_EMISSION] = Quantity_Color (Graphic3d_Vec3 (0.0f)); break; case Graphic3d_NOM_GOLD: MaterialType = Graphic3d_MATERIAL_PHYSIC; - Shininess = 0.80f; - ColorCoef[Graphic3d_TOR_AMBIENT] = 1.00f; - ColorCoef[Graphic3d_TOR_DIFFUSE] = 1.00f; - ColorCoef[Graphic3d_TOR_SPECULAR] = 1.00f; - BSDF = Graphic3d_BSDF::CreateMetallic (Graphic3d_Vec3 (0.985f, 0.985f, 0.985f), Graphic3d_Fresnel::CreateSchlick (Graphic3d_Vec3 (1.000000f, 0.765557f, 0.336057f)), 0.045f); + Shininess = 0.80f; Colors[Graphic3d_TOR_AMBIENT] = Quantity_Color (Graphic3d_Vec3 (0.300f, 0.230f, 0.095f)); Colors[Graphic3d_TOR_DIFFUSE] = Quantity_Color (Graphic3d_Vec3 (0.752f, 0.580f, 0.100f)); Colors[Graphic3d_TOR_SPECULAR] = Quantity_Color (Graphic3d_Vec3 (1.000f, 0.710f, 0.290f)); + Colors[Graphic3d_TOR_EMISSION] = Quantity_Color (Graphic3d_Vec3 (0.0f)); break; case Graphic3d_NOM_PEWTER: MaterialType = Graphic3d_MATERIAL_PHYSIC; - Shininess = 0.50f; - ColorCoef[Graphic3d_TOR_AMBIENT] = 1.00f; - ColorCoef[Graphic3d_TOR_DIFFUSE] = 1.00f; - ColorCoef[Graphic3d_TOR_SPECULAR] = 1.00f; - BSDF = Graphic3d_BSDF::CreateMetallic (Graphic3d_Vec3 (0.985f, 0.985f, 0.985f), Graphic3d_Fresnel::CreateConductor (1.8800f, 3.4900f), 0.045f); + Shininess = 0.50f; Colors[Graphic3d_TOR_AMBIENT] = Quantity_Color (Graphic3d_Vec3 (0.106f, 0.059f, 0.114f)); Colors[Graphic3d_TOR_DIFFUSE] = Quantity_Color (Graphic3d_Vec3 (0.427f, 0.471f, 0.541f)); Colors[Graphic3d_TOR_SPECULAR] = Quantity_Color (Graphic3d_Vec3 (0.333f, 0.333f, 0.522f)); + Colors[Graphic3d_TOR_EMISSION] = Quantity_Color (Graphic3d_Vec3 (0.0f)); break; case Graphic3d_NOM_PLASTER: - Shininess = 0.01f; - ColorCoef[Graphic3d_TOR_AMBIENT] = 0.26f; - ColorCoef[Graphic3d_TOR_DIFFUSE] = 0.75f; - ColorCoef[Graphic3d_TOR_SPECULAR] = 0.05f; + MaterialType = Graphic3d_MATERIAL_ASPECT; - Colors[Graphic3d_TOR_AMBIENT] = Quantity_Color (Graphic3d_Vec3 (0.192f, 0.192f, 0.192f)); - Colors[Graphic3d_TOR_DIFFUSE] = Quantity_Color (Graphic3d_Vec3 (0.508f, 0.508f, 0.508f)); - Colors[Graphic3d_TOR_SPECULAR] = Quantity_Color (Graphic3d_Vec3 (0.508f, 0.508f, 0.508f)); + Shininess = 0.01f; + Colors[Graphic3d_TOR_AMBIENT] = Quantity_Color (Graphic3d_Vec3 (0.26f)); + Colors[Graphic3d_TOR_DIFFUSE] = Quantity_Color (Graphic3d_Vec3 (0.75f)); + Colors[Graphic3d_TOR_SPECULAR] = Quantity_Color (Graphic3d_Vec3 (0.05f)); + Colors[Graphic3d_TOR_EMISSION] = Quantity_Color (Graphic3d_Vec3 (0.0f)); BSDF.Kd = Graphic3d_Vec3 (0.482353f, 0.482353f, 0.482353f); - break; case Graphic3d_NOM_SILVER: MaterialType = Graphic3d_MATERIAL_PHYSIC; - Shininess = 0.75f; - ColorCoef[Graphic3d_TOR_AMBIENT] = 1.00f; - ColorCoef[Graphic3d_TOR_DIFFUSE] = 1.00f; - ColorCoef[Graphic3d_TOR_SPECULAR] = 1.00f; - BSDF = Graphic3d_BSDF::CreateMetallic (Graphic3d_Vec3 (0.985f, 0.985f, 0.985f), Graphic3d_Fresnel::CreateSchlick (Graphic3d_Vec3 (0.971519f, 0.959915f, 0.915324f)), 0.045f); + Shininess = 0.75f; Colors[Graphic3d_TOR_AMBIENT] = Quantity_Color (Graphic3d_Vec3 (0.275f, 0.275f, 0.250f)); Colors[Graphic3d_TOR_DIFFUSE] = Quantity_Color (Graphic3d_Vec3 (0.630f, 0.630f, 0.630f)); Colors[Graphic3d_TOR_SPECULAR] = Quantity_Color (Graphic3d_Vec3 (0.950f, 0.930f, 0.880f)); + Colors[Graphic3d_TOR_EMISSION] = Quantity_Color (Graphic3d_Vec3 (0.0f)); break; case Graphic3d_NOM_STEEL: MaterialType = Graphic3d_MATERIAL_PHYSIC; - Shininess = 0.90f; - ColorCoef[Graphic3d_TOR_AMBIENT] = 1.00f; - ColorCoef[Graphic3d_TOR_DIFFUSE] = 1.00f; - ColorCoef[Graphic3d_TOR_SPECULAR] = 1.00f; - BSDF = Graphic3d_BSDF::CreateMetallic (Graphic3d_Vec3 (0.985f, 0.985f, 0.985f), Graphic3d_Fresnel::CreateConductor (Graphic3d_Vec3 (2.90f, 2.80f, 2.53f), Graphic3d_Vec3 (3.08f, 2.90f, 2.74f)), 0.045f); + Shininess = 0.90f; Colors[Graphic3d_TOR_AMBIENT] = Quantity_Color (Graphic3d_Vec3 (0.150f, 0.150f, 0.180f)); Colors[Graphic3d_TOR_DIFFUSE] = Quantity_Color (Graphic3d_Vec3 (0.500f, 0.510f, 0.520f)); Colors[Graphic3d_TOR_SPECULAR] = Quantity_Color (Graphic3d_Vec3 (0.560f, 0.570f, 0.580f)); + Colors[Graphic3d_TOR_EMISSION] = Quantity_Color (Graphic3d_Vec3 (0.0f)); break; case Graphic3d_NOM_STONE: MaterialType = Graphic3d_MATERIAL_PHYSIC; - Shininess = 0.17f; - ColorCoef[Graphic3d_TOR_AMBIENT] = 0.19f; - ColorCoef[Graphic3d_TOR_DIFFUSE] = 0.75f; - ColorCoef[Graphic3d_TOR_SPECULAR] = 0.08f; + // special case for SetColor() + AmbientCoef = 0.19f * 0.25f; + DiffuseCoef = 0.75f; - Colors[Graphic3d_TOR_AMBIENT] = Quantity_Color (Graphic3d_Vec3 (1.00f, 0.8f, 0.62f)); - Colors[Graphic3d_TOR_DIFFUSE] = Quantity_Color (Graphic3d_Vec3 (1.00f, 0.8f, 0.62f)); - Colors[Graphic3d_TOR_SPECULAR] = Quantity_Color (Graphic3d_Vec3 (0.98f, 1.0f, 0.60f)); + Shininess = 0.17f; + Colors[Graphic3d_TOR_AMBIENT] = Quantity_Color (Graphic3d_Vec3 (1.00f, 0.8f, 0.62f) * 0.19f); + Colors[Graphic3d_TOR_DIFFUSE] = Quantity_Color (Graphic3d_Vec3 (1.00f, 0.8f, 0.62f) * 0.75f); + Colors[Graphic3d_TOR_SPECULAR] = Quantity_Color (Graphic3d_Vec3 (0.98f, 1.0f, 0.60f) * 0.08f); + Colors[Graphic3d_TOR_EMISSION] = Quantity_Color (Graphic3d_Vec3 (0.0f)); BSDF.Kd = Graphic3d_Vec3 (0.243137f, 0.243137f, 0.243137f); BSDF.Ks = Graphic3d_Vec4 (0.00392157f, 0.00392157f, 0.00392157f, 0.5f); - break; - // Ascending Compatibility of physical materials. Takes the same definition as in the next constructor. New materials case Graphic3d_NOM_CHROME: MaterialType = Graphic3d_MATERIAL_PHYSIC; - Shininess = 0.90f; - ColorCoef[Graphic3d_TOR_AMBIENT] = 1.00f; - ColorCoef[Graphic3d_TOR_DIFFUSE] = 1.00f; - ColorCoef[Graphic3d_TOR_SPECULAR] = 1.00f; - BSDF = Graphic3d_BSDF::CreateMetallic (Graphic3d_Vec3 (0.985f, 0.985f, 0.985f), Graphic3d_Fresnel::CreateSchlick (Graphic3d_Vec3 (0.549585f, 0.556114f, 0.554256f)), 0.045f); + Shininess = 0.90f; Colors[Graphic3d_TOR_AMBIENT] = Quantity_Color (Graphic3d_Vec3 (0.200f, 0.200f, 0.225f)); Colors[Graphic3d_TOR_DIFFUSE] = Quantity_Color (Graphic3d_Vec3 (0.550f, 0.550f, 0.550f)); Colors[Graphic3d_TOR_SPECULAR] = Quantity_Color (Graphic3d_Vec3 (0.975f, 0.975f, 0.975f)); + Colors[Graphic3d_TOR_EMISSION] = Quantity_Color (Graphic3d_Vec3 (0.0f)); break; case Graphic3d_NOM_ALUMINIUM: MaterialType = Graphic3d_MATERIAL_PHYSIC; - Shininess = 0.75f; - ColorCoef[Graphic3d_TOR_AMBIENT] = 1.00f; - ColorCoef[Graphic3d_TOR_DIFFUSE] = 1.00f; - ColorCoef[Graphic3d_TOR_SPECULAR] = 1.00f; - BSDF = Graphic3d_BSDF::CreateMetallic (Graphic3d_Vec3 (0.985f, 0.985f, 0.985f), Graphic3d_Fresnel::CreateSchlick (Graphic3d_Vec3 (0.913183f, 0.921494f, 0.924524f)), 0.045f); + Shininess = 0.75f; Colors[Graphic3d_TOR_AMBIENT] = Quantity_Color (Graphic3d_Vec3 (0.300f, 0.300f, 0.300f)); Colors[Graphic3d_TOR_DIFFUSE] = Quantity_Color (Graphic3d_Vec3 (0.600f, 0.600f, 0.600f)); Colors[Graphic3d_TOR_SPECULAR] = Quantity_Color (Graphic3d_Vec3 (0.910f, 0.920f, 0.920f)); + Colors[Graphic3d_TOR_EMISSION] = Quantity_Color (Graphic3d_Vec3 (0.0f)); break; case Graphic3d_NOM_NEON_PHC: MaterialType = Graphic3d_MATERIAL_PHYSIC; - Shininess = 0.05f; - ColorCoef[Graphic3d_TOR_AMBIENT] = 1.00f; - ColorCoef[Graphic3d_TOR_DIFFUSE] = 1.00f; - ColorCoef[Graphic3d_TOR_SPECULAR] = 0.62f; - ColorCoef[Graphic3d_TOR_EMISSION] = 0.90f; - ReflActivity[Graphic3d_TOR_AMBIENT] = Standard_False; - ReflActivity[Graphic3d_TOR_DIFFUSE] = Standard_False; - ReflActivity[Graphic3d_TOR_EMISSION] = Standard_True; - - Colors[Graphic3d_TOR_AMBIENT] = Quantity_Color (Graphic3d_Vec3 (1.0f, 1.0f, 1.0f)); - Colors[Graphic3d_TOR_DIFFUSE] = Quantity_Color (Graphic3d_Vec3 (1.0f, 1.0f, 1.0f)); - Colors[Graphic3d_TOR_SPECULAR] = Quantity_Color (Graphic3d_Vec3 (1.0f, 1.0f, 1.0f)); - Colors[Graphic3d_TOR_EMISSION] = Quantity_Color (Graphic3d_Vec3 (0.0f, 1.0f, 0.46f)); + Shininess = 0.05f; + Colors[Graphic3d_TOR_AMBIENT] = Quantity_Color (Graphic3d_Vec3 (0.0f)); + Colors[Graphic3d_TOR_DIFFUSE] = Quantity_Color (Graphic3d_Vec3 (0.0f)); + Colors[Graphic3d_TOR_SPECULAR] = Quantity_Color (Graphic3d_Vec3 (0.62f)); + Colors[Graphic3d_TOR_EMISSION] = Quantity_Color (Graphic3d_Vec3 (0.0f, 0.90f, 0.414f)); BSDF.Kd = Graphic3d_Vec3 (0.0f); BSDF.Ks = Graphic3d_Vec4 (0.5f, 0.5f, 0.5f, 0.f); @@ -345,14 +303,11 @@ RawMaterial::RawMaterial (Graphic3d_NameOfMaterial theName, const char* theStrin case Graphic3d_NOM_OBSIDIAN: MaterialType = Graphic3d_MATERIAL_PHYSIC; - Shininess = 0.3f; - ColorCoef[Graphic3d_TOR_AMBIENT] = 1.0f; - ColorCoef[Graphic3d_TOR_DIFFUSE] = 1.0f; - ColorCoef[Graphic3d_TOR_SPECULAR] = 1.0f; - + Shininess = 0.3f; Colors[Graphic3d_TOR_AMBIENT] = Quantity_Color (Graphic3d_Vec3 (0.054f, 0.050f, 0.066f)); Colors[Graphic3d_TOR_DIFFUSE] = Quantity_Color (Graphic3d_Vec3 (0.183f, 0.170f, 0.225f)); Colors[Graphic3d_TOR_SPECULAR] = Quantity_Color (Graphic3d_Vec3 (0.333f, 0.329f, 0.346f)); + Colors[Graphic3d_TOR_EMISSION] = Quantity_Color (Graphic3d_Vec3 (0.0f)); BSDF.Kd = Graphic3d_Vec3 (0.023f, 0.f, 0.023f); BSDF.Ks = Graphic3d_Vec4 (0.0156863f, 0.0156863f, 0.0156863f, 0.1f); @@ -360,14 +315,11 @@ RawMaterial::RawMaterial (Graphic3d_NameOfMaterial theName, const char* theStrin case Graphic3d_NOM_JADE: MaterialType = Graphic3d_MATERIAL_PHYSIC; - Shininess = 0.10f; - ColorCoef[Graphic3d_TOR_AMBIENT] = 1.00f; - ColorCoef[Graphic3d_TOR_DIFFUSE] = 1.00f; - ColorCoef[Graphic3d_TOR_SPECULAR] = 1.00f; - + Shininess = 0.10f; Colors[Graphic3d_TOR_AMBIENT] = Quantity_Color (Graphic3d_Vec3 (0.135f, 0.223f, 0.158f)); Colors[Graphic3d_TOR_DIFFUSE] = Quantity_Color (Graphic3d_Vec3 (0.540f, 0.890f, 0.630f)); Colors[Graphic3d_TOR_SPECULAR] = Quantity_Color (Graphic3d_Vec3 (0.316f, 0.316f, 0.316f)); + Colors[Graphic3d_TOR_EMISSION] = Quantity_Color (Graphic3d_Vec3 (0.0f)); BSDF.FresnelBase = Graphic3d_Fresnel::CreateDielectric (1.5f); BSDF.Kd = Graphic3d_Vec3 (0.208658f, 0.415686f, 0.218401f); @@ -376,14 +328,11 @@ RawMaterial::RawMaterial (Graphic3d_NameOfMaterial theName, const char* theStrin case Graphic3d_NOM_CHARCOAL: MaterialType = Graphic3d_MATERIAL_PHYSIC; - Shininess = 0.01f; - ColorCoef[Graphic3d_TOR_AMBIENT] = 1.00f; - ColorCoef[Graphic3d_TOR_DIFFUSE] = 1.00f; - ColorCoef[Graphic3d_TOR_SPECULAR] = 1.00f; - - Colors[Graphic3d_TOR_AMBIENT] = Quantity_Color (Graphic3d_Vec3 (0.050f, 0.050f, 0.050f)); - Colors[Graphic3d_TOR_DIFFUSE] = Quantity_Color (Graphic3d_Vec3 (0.150f, 0.150f, 0.150f)); - Colors[Graphic3d_TOR_SPECULAR] = Quantity_Color (Graphic3d_Vec3 (0.000f, 0.000f, 0.000f)); + Shininess = 0.01f; + Colors[Graphic3d_TOR_AMBIENT] = Quantity_Color (Graphic3d_Vec3 (0.050f)); + Colors[Graphic3d_TOR_DIFFUSE] = Quantity_Color (Graphic3d_Vec3 (0.150f)); + Colors[Graphic3d_TOR_SPECULAR] = Quantity_Color (Graphic3d_Vec3 (0.0f)); + Colors[Graphic3d_TOR_EMISSION] = Quantity_Color (Graphic3d_Vec3 (0.0f)); BSDF.Kd = Graphic3d_Vec3 (0.02f, 0.02f, 0.02f); BSDF.Ks = Graphic3d_Vec4 (0.1f, 0.1f, 0.1f, 0.3f); @@ -391,10 +340,6 @@ RawMaterial::RawMaterial (Graphic3d_NameOfMaterial theName, const char* theStrin case Graphic3d_NOM_WATER: MaterialType = Graphic3d_MATERIAL_PHYSIC; - Shininess = 0.90f; - ColorCoef[Graphic3d_TOR_AMBIENT] = 1.00f; - ColorCoef[Graphic3d_TOR_DIFFUSE] = 1.00f; - ColorCoef[Graphic3d_TOR_SPECULAR] = 1.00f; RefractionIndex = 1.33f; BSDF = Graphic3d_BSDF::CreateGlass (Graphic3d_Vec3 (1.f), Graphic3d_Vec3 (0.7f, 0.75f, 0.85f), @@ -402,17 +347,15 @@ RawMaterial::RawMaterial (Graphic3d_NameOfMaterial theName, const char* theStrin RefractionIndex); TransparencyCoef = 0.80f; + Shininess = 0.90f; Colors[Graphic3d_TOR_AMBIENT] = Quantity_Color (Graphic3d_Vec3 (0.450f, 0.450f, 0.475f)); Colors[Graphic3d_TOR_DIFFUSE] = Quantity_Color (Graphic3d_Vec3 (0.050f, 0.050f, 0.075f)); Colors[Graphic3d_TOR_SPECULAR] = Quantity_Color (Graphic3d_Vec3 (0.380f, 0.380f, 0.380f)); + Colors[Graphic3d_TOR_EMISSION] = Quantity_Color (Graphic3d_Vec3 (0.0f)); break; case Graphic3d_NOM_GLASS: MaterialType = Graphic3d_MATERIAL_PHYSIC; - Shininess = 0.50f; - ColorCoef[Graphic3d_TOR_AMBIENT] = 1.00f; - ColorCoef[Graphic3d_TOR_DIFFUSE] = 1.00f; - ColorCoef[Graphic3d_TOR_SPECULAR] = 1.00f; RefractionIndex = 1.62f; BSDF = Graphic3d_BSDF::CreateGlass (Graphic3d_Vec3 (1.f), Graphic3d_Vec3 (0.75f, 0.95f, 0.9f), @@ -420,17 +363,15 @@ RawMaterial::RawMaterial (Graphic3d_NameOfMaterial theName, const char* theStrin RefractionIndex); TransparencyCoef = 0.80f; + Shininess = 0.50f; Colors[Graphic3d_TOR_AMBIENT] = Quantity_Color (Graphic3d_Vec3 (0.550f, 0.575f, 0.575f)); Colors[Graphic3d_TOR_DIFFUSE] = Quantity_Color (Graphic3d_Vec3 (0.050f, 0.075f, 0.075f)); Colors[Graphic3d_TOR_SPECULAR] = Quantity_Color (Graphic3d_Vec3 (0.920f, 0.920f, 0.920f)); + Colors[Graphic3d_TOR_EMISSION] = Quantity_Color (Graphic3d_Vec3 (0.0f)); break; case Graphic3d_NOM_DIAMOND: MaterialType = Graphic3d_MATERIAL_PHYSIC; - Shininess = 0.90f; - ColorCoef[Graphic3d_TOR_AMBIENT] = 1.00f; - ColorCoef[Graphic3d_TOR_DIFFUSE] = 1.00f; - ColorCoef[Graphic3d_TOR_SPECULAR] = 1.00f; RefractionIndex = 2.42f; BSDF = Graphic3d_BSDF::CreateGlass (Graphic3d_Vec3 (1.f), Graphic3d_Vec3 (0.95f, 0.95f, 0.95f), @@ -438,18 +379,16 @@ RawMaterial::RawMaterial (Graphic3d_NameOfMaterial theName, const char* theStrin RefractionIndex); TransparencyCoef = 0.80f; - Colors[Graphic3d_TOR_AMBIENT] = Quantity_Color (Graphic3d_Vec3 (0.550f, 0.550f, 0.550f)); - Colors[Graphic3d_TOR_DIFFUSE] = Quantity_Color (Graphic3d_Vec3 (0.100f, 0.100f, 0.100f)); - Colors[Graphic3d_TOR_SPECULAR] = Quantity_Color (Graphic3d_Vec3 (0.970f, 0.970f, 0.970f)); + Shininess = 0.90f; + Colors[Graphic3d_TOR_AMBIENT] = Quantity_Color (Graphic3d_Vec3 (0.550f)); + Colors[Graphic3d_TOR_DIFFUSE] = Quantity_Color (Graphic3d_Vec3 (0.100f)); + Colors[Graphic3d_TOR_SPECULAR] = Quantity_Color (Graphic3d_Vec3 (0.970f)); + Colors[Graphic3d_TOR_EMISSION] = Quantity_Color (Graphic3d_Vec3 (0.0f)); break; case Graphic3d_NOM_TRANSPARENT: MaterialType = Graphic3d_MATERIAL_PHYSIC; - Shininess = 0.90f; - ColorCoef[Graphic3d_TOR_AMBIENT] = 1.00f; - ColorCoef[Graphic3d_TOR_DIFFUSE] = 1.00f; - ColorCoef[Graphic3d_TOR_SPECULAR] = 1.00f; RefractionIndex = 1.0f; BSDF.Kd = Graphic3d_Vec3 (0.1f); @@ -457,22 +396,26 @@ RawMaterial::RawMaterial (Graphic3d_NameOfMaterial theName, const char* theStrin BSDF.FresnelBase = Graphic3d_Fresnel::CreateConstant (0.0f); TransparencyCoef = 0.80f; - Colors[Graphic3d_TOR_AMBIENT] = Quantity_Color (Graphic3d_Vec3 (0.550f, 0.550f, 0.550f)); - Colors[Graphic3d_TOR_DIFFUSE] = Quantity_Color (Graphic3d_Vec3 (0.100f, 0.100f, 0.100f)); - Colors[Graphic3d_TOR_SPECULAR] = Quantity_Color (Graphic3d_Vec3 (0.970f, 0.970f, 0.970f)); + Shininess = 0.90f; + Colors[Graphic3d_TOR_AMBIENT] = Quantity_Color (Graphic3d_Vec3 (0.550f)); + Colors[Graphic3d_TOR_DIFFUSE] = Quantity_Color (Graphic3d_Vec3 (0.100f)); + Colors[Graphic3d_TOR_SPECULAR] = Quantity_Color (Graphic3d_Vec3 (0.970f)); + Colors[Graphic3d_TOR_EMISSION] = Quantity_Color (Graphic3d_Vec3 (0.0f)); break; case Graphic3d_NOM_UserDefined: MaterialType = Graphic3d_MATERIAL_PHYSIC; - ColorCoef[Graphic3d_TOR_AMBIENT] = 1.00f; - ColorCoef[Graphic3d_TOR_DIFFUSE] = 1.00f; - ColorCoef[Graphic3d_TOR_SPECULAR] = 1.00f; - ColorCoef[Graphic3d_TOR_EMISSION] = 1.00f; - Colors[Graphic3d_TOR_AMBIENT] = Quantity_Color (Graphic3d_Vec3 (0.1f, 0.1f, 0.1f)); - Colors[Graphic3d_TOR_DIFFUSE] = Quantity_Color (Graphic3d_Vec3 (0.8f, 0.8f, 0.8f)); - Colors[Graphic3d_TOR_SPECULAR] = Quantity_Color (Graphic3d_Vec3 (0.2f, 0.2f, 0.2f)); - Colors[Graphic3d_TOR_EMISSION] = Quantity_Color (Graphic3d_Vec3 (0.0f, 0.0f, 0.0f)); + Colors[Graphic3d_TOR_AMBIENT] = Quantity_Color (Graphic3d_Vec3 (0.1f)); + Colors[Graphic3d_TOR_DIFFUSE] = Quantity_Color (Graphic3d_Vec3 (0.8f)); + Colors[Graphic3d_TOR_SPECULAR] = Quantity_Color (Graphic3d_Vec3 (0.2f)); + Colors[Graphic3d_TOR_EMISSION] = Quantity_Color (Graphic3d_Vec3 (0.0f)); break; case Graphic3d_NOM_DEFAULT: + MaterialType = Graphic3d_MATERIAL_ASPECT; + + Colors[Graphic3d_TOR_AMBIENT] = Quantity_Color (Graphic3d_Vec3 (0.30f)); + Colors[Graphic3d_TOR_DIFFUSE] = Quantity_Color (Graphic3d_Vec3 (0.65f)); + Colors[Graphic3d_TOR_SPECULAR] = Quantity_Color (Graphic3d_Vec3 (0.0f)); + Colors[Graphic3d_TOR_EMISSION] = Quantity_Color (Graphic3d_Vec3 (0.0f)); break; } } @@ -510,20 +453,12 @@ void Graphic3d_MaterialAspect::init (const Graphic3d_NameOfMaterial theName) myColors[Graphic3d_TOR_DIFFUSE] = aMat.Colors[Graphic3d_TOR_DIFFUSE]; myColors[Graphic3d_TOR_SPECULAR] = aMat.Colors[Graphic3d_TOR_SPECULAR]; myColors[Graphic3d_TOR_EMISSION] = aMat.Colors[Graphic3d_TOR_EMISSION]; - myColorCoef[Graphic3d_TOR_AMBIENT] = aMat.ColorCoef[Graphic3d_TOR_AMBIENT]; - myColorCoef[Graphic3d_TOR_DIFFUSE] = aMat.ColorCoef[Graphic3d_TOR_DIFFUSE]; - myColorCoef[Graphic3d_TOR_SPECULAR] = aMat.ColorCoef[Graphic3d_TOR_SPECULAR]; - myColorCoef[Graphic3d_TOR_EMISSION] = aMat.ColorCoef[Graphic3d_TOR_EMISSION]; myTransparencyCoef = aMat.TransparencyCoef; myRefractionIndex = aMat.RefractionIndex; myShininess = aMat.Shininess; myMaterialType = aMat.MaterialType; myMaterialName = theName; myRequestedMaterialName = theName; - myReflActivity[Graphic3d_TOR_AMBIENT] = aMat.ReflActivity[Graphic3d_TOR_AMBIENT]; - myReflActivity[Graphic3d_TOR_DIFFUSE] = aMat.ReflActivity[Graphic3d_TOR_DIFFUSE]; - myReflActivity[Graphic3d_TOR_SPECULAR] = aMat.ReflActivity[Graphic3d_TOR_SPECULAR]; - myReflActivity[Graphic3d_TOR_EMISSION] = aMat.ReflActivity[Graphic3d_TOR_EMISSION]; } // ======================================================================= @@ -553,42 +488,28 @@ void Graphic3d_MaterialAspect::SetMaterialType (const Graphic3d_TypeOfMaterial t } } -// ======================================================================= -// function : SetAmbient -// purpose : -// ======================================================================= -void Graphic3d_MaterialAspect::SetAmbient (const Standard_ShortReal theValue) -{ - if (theValue < 0.0f - || theValue > 1.0f) - { - throw Graphic3d_MaterialDefinitionError("Bad value for SetAmbient < 0. or > 1.0"); - } - - myColorCoef[Graphic3d_TOR_AMBIENT] = theValue; - if (myReflActivity[Graphic3d_TOR_AMBIENT] - && myMaterialType == Graphic3d_MATERIAL_PHYSIC) - { - setUserMaterial(); - } -} - // ======================================================================= // function : SetColor // purpose : // ======================================================================= void Graphic3d_MaterialAspect::SetColor (const Quantity_Color& theColor) { - const Standard_ShortReal anAmbientCoeff = 0.25f; - myColors[Graphic3d_TOR_AMBIENT].SetValues (theColor.Red() * anAmbientCoeff, - theColor.Green() * anAmbientCoeff, - theColor.Blue() * anAmbientCoeff, Quantity_TOC_RGB); - myColors[Graphic3d_TOR_DIFFUSE] = theColor; - if (myReflActivity[Graphic3d_TOR_AMBIENT] - && myMaterialType == Graphic3d_MATERIAL_PHYSIC) + if (myMaterialType == Graphic3d_MATERIAL_ASPECT) + { + return; + } + + const RawMaterial& aSrcMat = THE_MATERIALS[myRequestedMaterialName]; + const Quantity_Color anAmbient((Graphic3d_Vec3 )theColor * aSrcMat.AmbientCoef); + const Quantity_Color aDiffuse ((Graphic3d_Vec3 )theColor * aSrcMat.DiffuseCoef); + if (myMaterialName != Graphic3d_NOM_UserDefined + && (!myColors[Graphic3d_TOR_AMBIENT].IsEqual (anAmbient) + || !myColors[Graphic3d_TOR_DIFFUSE].IsEqual (aDiffuse))) { setUserMaterial(); } + myColors[Graphic3d_TOR_AMBIENT] = anAmbient; + myColors[Graphic3d_TOR_DIFFUSE] = aDiffuse; } // ======================================================================= @@ -597,12 +518,13 @@ void Graphic3d_MaterialAspect::SetColor (const Quantity_Color& theColor) // ======================================================================= void Graphic3d_MaterialAspect::SetAmbientColor (const Quantity_Color& theColor) { - myColors[Graphic3d_TOR_AMBIENT] = theColor; - if (myReflActivity[Graphic3d_TOR_AMBIENT] - && myMaterialType == Graphic3d_MATERIAL_PHYSIC) + if (myMaterialType == Graphic3d_MATERIAL_PHYSIC + && myMaterialName != Graphic3d_NOM_UserDefined + && !myColors[Graphic3d_TOR_AMBIENT].IsEqual (theColor)) { setUserMaterial(); } + myColors[Graphic3d_TOR_AMBIENT] = theColor; } // ======================================================================= @@ -611,12 +533,13 @@ void Graphic3d_MaterialAspect::SetAmbientColor (const Quantity_Color& theColor) // ======================================================================= void Graphic3d_MaterialAspect::SetDiffuseColor (const Quantity_Color& theColor) { - myColors[Graphic3d_TOR_DIFFUSE] = theColor; - if (myReflActivity[Graphic3d_TOR_DIFFUSE] - && myMaterialType == Graphic3d_MATERIAL_PHYSIC) + if (myMaterialType == Graphic3d_MATERIAL_PHYSIC + && myMaterialName != Graphic3d_NOM_UserDefined + && !myColors[Graphic3d_TOR_DIFFUSE].IsEqual (theColor)) { setUserMaterial(); } + myColors[Graphic3d_TOR_DIFFUSE] = theColor; } // ======================================================================= @@ -625,12 +548,13 @@ void Graphic3d_MaterialAspect::SetDiffuseColor (const Quantity_Color& theColor) // ======================================================================= void Graphic3d_MaterialAspect::SetSpecularColor (const Quantity_Color& theColor) { - myColors[Graphic3d_TOR_SPECULAR] = theColor; - if (myReflActivity[Graphic3d_TOR_SPECULAR] - && myMaterialType == Graphic3d_MATERIAL_PHYSIC) + if (myMaterialType == Graphic3d_MATERIAL_PHYSIC + && myMaterialName != Graphic3d_NOM_UserDefined + && !myColors[Graphic3d_TOR_SPECULAR].IsEqual (theColor)) { setUserMaterial(); } + myColors[Graphic3d_TOR_SPECULAR] = theColor; } // ======================================================================= @@ -639,86 +563,13 @@ void Graphic3d_MaterialAspect::SetSpecularColor (const Quantity_Color& theColor) // ======================================================================= void Graphic3d_MaterialAspect::SetEmissiveColor (const Quantity_Color& theColor) { + if (myMaterialType == Graphic3d_MATERIAL_PHYSIC + && myMaterialName != Graphic3d_NOM_UserDefined + && !myColors[Graphic3d_TOR_EMISSION].IsEqual (theColor)) + { + setUserMaterial(); + } myColors[Graphic3d_TOR_EMISSION] = theColor; - if (myReflActivity[Graphic3d_TOR_EMISSION] - && myMaterialType == Graphic3d_MATERIAL_PHYSIC) - { - setUserMaterial(); - } -} - -// ======================================================================= -// function : SetDiffuse -// purpose : -// ======================================================================= -void Graphic3d_MaterialAspect::SetDiffuse (const Standard_ShortReal theValue) -{ - if (theValue < 0.0f - || theValue > 1.0f) - { - throw Graphic3d_MaterialDefinitionError("Bad value for SetDiffuse < 0. or > 1.0"); - } - - myColorCoef[Graphic3d_TOR_DIFFUSE] = theValue; - if (myReflActivity[Graphic3d_TOR_DIFFUSE] - && myMaterialType == Graphic3d_MATERIAL_PHYSIC) - { - setUserMaterial(); - } -} - -// ======================================================================= -// function : SetEmissive -// purpose : -// ======================================================================= -void Graphic3d_MaterialAspect::SetEmissive (const Standard_ShortReal theValue) -{ - if (theValue < 0.0f - || theValue > 1.0f) - { - throw Graphic3d_MaterialDefinitionError("Bad value for SetEmissive < 0. or > 1.0"); - } - - myColorCoef[Graphic3d_TOR_EMISSION] = theValue; - if (myReflActivity[Graphic3d_TOR_DIFFUSE] - && myMaterialType == Graphic3d_MATERIAL_PHYSIC) - { - setUserMaterial(); - } -} - -// ======================================================================= -// function : SetReflectionMode -// purpose : -// ======================================================================= -void Graphic3d_MaterialAspect::SetReflectionMode (const Graphic3d_TypeOfReflection theType, - const Standard_Boolean theValue) -{ - myReflActivity[theType] = theValue; - if (myMaterialType == Graphic3d_MATERIAL_PHYSIC) - { - setUserMaterial(); - } -} - -// ======================================================================= -// function : SetSpecular -// purpose : -// ======================================================================= -void Graphic3d_MaterialAspect::SetSpecular (const Standard_ShortReal theValue) -{ - if (theValue < 0.0f - || theValue > 1.0f) - { - throw Graphic3d_MaterialDefinitionError("Bad value for SetSpecular < 0. or > 1.0"); - } - - myColorCoef[Graphic3d_TOR_SPECULAR] = theValue; - if (myReflActivity[Graphic3d_TOR_SPECULAR] - && myMaterialType == Graphic3d_MATERIAL_PHYSIC) - { - setUserMaterial(); - } } // ======================================================================= @@ -762,8 +613,11 @@ void Graphic3d_MaterialAspect::SetShininess (const Standard_ShortReal theValue) throw Graphic3d_MaterialDefinitionError("Bad value for Shininess < 0. or > 1.0"); } - myShininess = theValue; - setUserMaterial(); + if (myShininess != theValue) + { + myShininess = theValue; + setUserMaterial(); + } } // ======================================================================= @@ -784,47 +638,55 @@ Standard_CString Graphic3d_MaterialAspect::MaterialName (const Standard_Integer // function : MaterialFromName // purpose : // ======================================================================= -Graphic3d_NameOfMaterial Graphic3d_MaterialAspect::MaterialFromName (const Standard_CString theName) +Standard_Boolean Graphic3d_MaterialAspect::MaterialFromName (const Standard_CString theName, + Graphic3d_NameOfMaterial& theMat) { TCollection_AsciiString aName (theName); aName.LowerCase(); aName.Capitalize(); const Standard_Integer aNbMaterials = Graphic3d_MaterialAspect::NumberOfMaterials(); - for (Standard_Integer aMatIter = 0; aMatIter < aNbMaterials; ++aMatIter) + for (Standard_Integer aMatIter = 0; aMatIter <= aNbMaterials; ++aMatIter) { const RawMaterial& aMat = THE_MATERIALS[aMatIter]; if (aName == aMat.StringName) { - return Graphic3d_NameOfMaterial(aMatIter); + theMat = Graphic3d_NameOfMaterial(aMatIter); + return Standard_True; } } // parse aliases if (aName == "Plastic") // Plastified { - return Graphic3d_NOM_PLASTIC; + theMat = Graphic3d_NOM_PLASTIC; + return Standard_True; } else if (aName == "Shiny_plastic") // Shiny_plastified { - return Graphic3d_NOM_SHINY_PLASTIC; + theMat = Graphic3d_NOM_SHINY_PLASTIC; + return Standard_True; } else if (aName == "Plaster") // Plastered { - return Graphic3d_NOM_PLASTER; + theMat = Graphic3d_NOM_PLASTER; + return Standard_True; } else if (aName == "Satin") // Satined { - return Graphic3d_NOM_SATIN; + theMat = Graphic3d_NOM_SATIN; + return Standard_True; } else if (aName == "Neon_gnc") // Ionized { - return Graphic3d_NOM_NEON_GNC; + theMat = Graphic3d_NOM_NEON_GNC; + return Standard_True; } else if (aName == "Neon_phc") // Neon { - return Graphic3d_NOM_NEON_PHC; + theMat = Graphic3d_NOM_NEON_PHC; + return Standard_True; } - return Graphic3d_NOM_DEFAULT; + return Standard_False; } // ======================================================================= diff --git a/src/Graphic3d/Graphic3d_MaterialAspect.hxx b/src/Graphic3d/Graphic3d_MaterialAspect.hxx index 78b9b1045e..99d25eac7d 100644 --- a/src/Graphic3d/Graphic3d_MaterialAspect.hxx +++ b/src/Graphic3d/Graphic3d_MaterialAspect.hxx @@ -42,8 +42,20 @@ public: //! Returns the type of the predefined material of specified rank within range [1, NumberOfMaterials()]. Standard_EXPORT static Graphic3d_TypeOfMaterial MaterialType (const Standard_Integer theRank); + //! Finds the material for specified name. + //! @param theName [in] name to find + //! @param theMat [out] found material + //! @return FALSE if name was unrecognized + Standard_EXPORT static Standard_Boolean MaterialFromName (const Standard_CString theName, + Graphic3d_NameOfMaterial& theMat); + //! Returns the material for specified name or Graphic3d_NOM_DEFAULT if name is unknown. - Standard_EXPORT static Graphic3d_NameOfMaterial MaterialFromName (const Standard_CString theName); + static Graphic3d_NameOfMaterial MaterialFromName (const Standard_CString theName) + { + Graphic3d_NameOfMaterial aMat = Graphic3d_NOM_DEFAULT; + MaterialFromName (theName, aMat); + return aMat; + } public: @@ -87,9 +99,11 @@ public: } //! Returns the diffuse color of the surface. + //! WARNING! This method does NOT return color for Graphic3d_MATERIAL_ASPECT material (color is defined by Graphic3d_Aspects::InteriorColor()). const Quantity_Color& Color() const { return myColors[Graphic3d_TOR_DIFFUSE]; } //! Modifies the ambient and diffuse color of the surface. + //! WARNING! Has no effect for Graphic3d_MATERIAL_ASPECT material (color should be set to Graphic3d_Aspects::SetInteriorColor()). Standard_EXPORT void SetColor (const Quantity_Color& theColor); //! Returns the transparency coefficient of the surface (1.0 - Alpha); 0.0 means opaque. @@ -132,34 +146,6 @@ public: //! Modifies the emissive color of the surface. Standard_EXPORT void SetEmissiveColor (const Quantity_Color& theColor); - //! Returns the reflection properties of the surface. - Standard_ShortReal Ambient() const { return myColorCoef[Graphic3d_TOR_AMBIENT]; } - - //! Modifies the reflection properties of the surface. - //! Warning: Raises MaterialDefinitionError if given value is a negative value or greater than 1.0. - Standard_EXPORT void SetAmbient (const Standard_ShortReal theValue); - - //! Returns the reflection properties of the surface. - Standard_ShortReal Diffuse() const { return myColorCoef[Graphic3d_TOR_DIFFUSE]; } - - //! Modifies the reflection properties of the surface. - //! Warning: Raises MaterialDefinitionError if given value is a negative value or greater than 1.0. - Standard_EXPORT void SetDiffuse (const Standard_ShortReal theValue); - - //! Returns the reflection properties of the surface. - Standard_ShortReal Specular() const { return myColorCoef[Graphic3d_TOR_SPECULAR]; } - - //! Modifies the reflection properties of the surface. - //! Warning: Raises MaterialDefinitionError if given value is a negative value or greater than 1.0. - Standard_EXPORT void SetSpecular (const Standard_ShortReal theValue); - - //! Returns the emissive coefficient of the surface. - Standard_ShortReal Emissive() const { return myColorCoef[Graphic3d_TOR_EMISSION]; } - - //! Modifies the reflection properties of the surface. - //! Warning: Raises MaterialDefinitionError if given value is a negative value or greater than 1.0. - Standard_EXPORT void SetEmissive (const Standard_ShortReal theValue); - //! Returns the luminosity of the surface. Standard_ShortReal Shininess() const { return myShininess; } @@ -187,27 +173,9 @@ public: //! Returns TRUE if the reflection mode is active, FALSE otherwise. Standard_Boolean ReflectionMode (const Graphic3d_TypeOfReflection theType) const { - return myReflActivity[theType]; + return !myColors[theType].IsEqual (Quantity_NOC_BLACK); } - //! Activates or deactivates the reflective properties of the surface with specified reflection type. - //! - //! Disabling diffuse and specular reflectance is useful for efficient visualization - //! of large amounts of data as definition of normals for graphic primitives is not needed - //! when only "all-directional" reflectance is active. - //! - //! NOTE: Disabling all four reflection modes also turns off the following effects: - //! 1. Lighting. Colors of primitives are not affected by the material properties when lighting is off. - //! 2. Transparency. - Standard_EXPORT void SetReflectionMode (const Graphic3d_TypeOfReflection theType, - const Standard_Boolean theValue); - - //! Activates the reflective properties of the surface with specified reflection type. - void SetReflectionModeOn (const Graphic3d_TypeOfReflection theType) { SetReflectionMode (theType, Standard_True); } - - //! Deactivates the reflective properties of the surface with specified reflection type. - void SetReflectionModeOff (const Graphic3d_TypeOfReflection theType) { SetReflectionMode (theType, Standard_False); } - //! Returns material type. Graphic3d_TypeOfMaterial MaterialType() const { return myMaterialType; } @@ -226,27 +194,39 @@ public: //! Returns TRUE if this material is identical to specified one. Standard_Boolean IsEqual (const Graphic3d_MaterialAspect& theOther) const { - return myColorCoef[Graphic3d_TOR_AMBIENT] == theOther.myColorCoef[Graphic3d_TOR_AMBIENT] - && myColorCoef[Graphic3d_TOR_DIFFUSE] == theOther.myColorCoef[Graphic3d_TOR_DIFFUSE] - && myColorCoef[Graphic3d_TOR_SPECULAR] == theOther.myColorCoef[Graphic3d_TOR_SPECULAR] - && myColorCoef[Graphic3d_TOR_EMISSION] == theOther.myColorCoef[Graphic3d_TOR_EMISSION] - && myTransparencyCoef == theOther.myTransparencyCoef + return myTransparencyCoef == theOther.myTransparencyCoef && myRefractionIndex == theOther.myRefractionIndex && myBSDF == theOther.myBSDF && myShininess == theOther.myShininess - && myColors[Graphic3d_TOR_AMBIENT] == theOther.myColors[Graphic3d_TOR_AMBIENT] - && myColors[Graphic3d_TOR_DIFFUSE] == theOther.myColors[Graphic3d_TOR_DIFFUSE] - && myColors[Graphic3d_TOR_SPECULAR] == theOther.myColors[Graphic3d_TOR_SPECULAR] - && myColors[Graphic3d_TOR_EMISSION] == theOther.myColors[Graphic3d_TOR_EMISSION] - && myReflActivity[Graphic3d_TOR_AMBIENT] == theOther.myReflActivity[Graphic3d_TOR_AMBIENT] - && myReflActivity[Graphic3d_TOR_DIFFUSE] == theOther.myReflActivity[Graphic3d_TOR_DIFFUSE] - && myReflActivity[Graphic3d_TOR_SPECULAR] == theOther.myReflActivity[Graphic3d_TOR_SPECULAR] - && myReflActivity[Graphic3d_TOR_EMISSION] == theOther.myReflActivity[Graphic3d_TOR_EMISSION]; + && myColors[Graphic3d_TOR_AMBIENT] == theOther.myColors[Graphic3d_TOR_AMBIENT] + && myColors[Graphic3d_TOR_DIFFUSE] == theOther.myColors[Graphic3d_TOR_DIFFUSE] + && myColors[Graphic3d_TOR_SPECULAR] == theOther.myColors[Graphic3d_TOR_SPECULAR] + && myColors[Graphic3d_TOR_EMISSION] == theOther.myColors[Graphic3d_TOR_EMISSION]; } //! Returns TRUE if this material is identical to specified one. Standard_Boolean operator== (const Graphic3d_MaterialAspect& theOther) const { return IsEqual (theOther); } +public: + + //! Deactivates the reflective properties of the surface with specified reflection type. + Standard_DEPRECATED("Deprecated method, specific material component should be zerroed instead") + void SetReflectionModeOff (const Graphic3d_TypeOfReflection theType) + { + if (!ReflectionMode (theType)) + { + return; + } + + switch (theType) + { + case Graphic3d_TOR_AMBIENT: SetAmbientColor (Quantity_NOC_BLACK); break; + case Graphic3d_TOR_DIFFUSE: SetDiffuseColor (Quantity_NOC_BLACK); break; + case Graphic3d_TOR_SPECULAR: SetSpecularColor(Quantity_NOC_BLACK); break; + case Graphic3d_TOR_EMISSION: SetEmissiveColor(Quantity_NOC_BLACK); break; + } + } + private: //! Initialize the standard material. @@ -257,16 +237,18 @@ private: { // if a component of a "standard" material change, the // result is no more standard (a blue gold is not a gold) - myMaterialName = Graphic3d_NOM_UserDefined; - myStringName = "UserDefined"; + if (myMaterialName != Graphic3d_NOM_UserDefined) + { + myMaterialName = Graphic3d_NOM_UserDefined; + myStringName = "UserDefined"; + } } private: Graphic3d_BSDF myBSDF; TCollection_AsciiString myStringName; - Quantity_Color myColors [Graphic3d_TypeOfReflection_NB]; - Standard_ShortReal myColorCoef[Graphic3d_TypeOfReflection_NB]; + Quantity_Color myColors[Graphic3d_TypeOfReflection_NB]; Standard_ShortReal myTransparencyCoef; Standard_ShortReal myRefractionIndex; Standard_ShortReal myShininess; @@ -275,8 +257,6 @@ private: Graphic3d_NameOfMaterial myMaterialName; Graphic3d_NameOfMaterial myRequestedMaterialName; - Standard_Boolean myReflActivity[Graphic3d_TypeOfReflection_NB]; - }; #endif // _Graphic3d_MaterialAspect_HeaderFile diff --git a/src/MeshVS/MeshVS_ElementalColorPrsBuilder.cxx b/src/MeshVS/MeshVS_ElementalColorPrsBuilder.cxx index 75880888e4..e267a56afa 100644 --- a/src/MeshVS/MeshVS_ElementalColorPrsBuilder.cxx +++ b/src/MeshVS/MeshVS_ElementalColorPrsBuilder.cxx @@ -215,13 +215,14 @@ void MeshVS_ElementalColorPrsBuilder::Build ( const Handle(Prs3d_Presentation)& PolygonVerticesFor3D, PolygonBoundsFor3D ); } - Graphic3d_MaterialAspect aMaterial[2]; + Graphic3d_MaterialAspect aMaterial[2] = { Graphic3d_NOM_PLASTIC, Graphic3d_NOM_PLASTIC }; for (Standard_Integer i = 0; i < 2; i++) { // OCC20644 "plastic" is most suitable here, as it is "non-physic" // so TelUpdateMaterial() from OpenGl_attri.c uses the interior // color from AspectFillArea3d to calculate all material colors - aMaterial[i] = Graphic3d_MaterialAspect ( Graphic3d_NOM_PLASTIC ); + aMaterial[i].SetSpecularColor (Quantity_NOC_BLACK); + aMaterial[i].SetEmissiveColor (Quantity_NOC_BLACK); // OCC21720 For single-colored elements turning all material components off is a good idea, // as anyhow the normals are not computed and the lighting will be off, @@ -229,10 +230,8 @@ void MeshVS_ElementalColorPrsBuilder::Build ( const Handle(Prs3d_Presentation)& // and there is no need to spend time on updating material properties if ( !IsReflect ) { - aMaterial[i].SetReflectionModeOff(Graphic3d_TOR_AMBIENT); - aMaterial[i].SetReflectionModeOff(Graphic3d_TOR_DIFFUSE); - aMaterial[i].SetReflectionModeOff(Graphic3d_TOR_SPECULAR); - aMaterial[i].SetReflectionModeOff(Graphic3d_TOR_EMISSION); + aMaterial[i].SetAmbientColor (Quantity_NOC_BLACK); + aMaterial[i].SetDiffuseColor (Quantity_NOC_BLACK); } else { @@ -241,10 +240,8 @@ void MeshVS_ElementalColorPrsBuilder::Build ( const Handle(Prs3d_Presentation)& // those in the color scale most exactly (the sum of all reflection // coefficients is equal to 1). See also MeshVS_NodalColorPrsBuilder // class for more explanations. - aMaterial[i].SetAmbient( .5 ); - aMaterial[i].SetDiffuse( .5 ); - aMaterial[i].SetSpecular( 0. ); - aMaterial[i].SetEmissive( 0. ); + aMaterial[i].SetAmbientColor (Quantity_Color (Graphic3d_Vec3 (0.5f))); + aMaterial[i].SetDiffuseColor (Quantity_Color (Graphic3d_Vec3 (0.5f))); } } @@ -481,13 +478,14 @@ void MeshVS_ElementalColorPrsBuilder::Build ( const Handle(Prs3d_Presentation)& CustomBuild(Prs, aCustomElements, IDsToExclude, DisplayMode); } - Graphic3d_MaterialAspect aMaterial2[2]; + Graphic3d_MaterialAspect aMaterial2[2] = { Graphic3d_NOM_PLASTIC, Graphic3d_NOM_PLASTIC }; for (Standard_Integer i = 0; i < 2; i++) { // OCC20644 "plastic" is most suitable here, as it is "non-physic" // so TelUpdateMaterial() from OpenGl_attri.c uses the interior // color from AspectFillArea3d to calculate all material colors - aMaterial2[i] = Graphic3d_MaterialAspect ( Graphic3d_NOM_PLASTIC ); + aMaterial2[i].SetSpecularColor (Quantity_NOC_BLACK); + aMaterial2[i].SetEmissiveColor (Quantity_NOC_BLACK); if ( !IsReflect ) { @@ -496,14 +494,8 @@ void MeshVS_ElementalColorPrsBuilder::Build ( const Handle(Prs3d_Presentation)& // to have different materials for front and back sides! // Instead, trying to make material color "nondirectional" with // only ambient component on. - aMaterial2[i].SetReflectionModeOn ( Graphic3d_TOR_AMBIENT ); - aMaterial2[i].SetReflectionModeOff( Graphic3d_TOR_DIFFUSE ); - aMaterial2[i].SetReflectionModeOff( Graphic3d_TOR_SPECULAR ); - aMaterial2[i].SetReflectionModeOff( Graphic3d_TOR_EMISSION ); - aMaterial2[i].SetAmbient ( 1. ); - aMaterial2[i].SetDiffuse ( 0. ); - aMaterial2[i].SetSpecular( 0. ); - aMaterial2[i].SetEmissive( 0. ); + aMaterial2[i].SetAmbientColor (Quantity_Color (Graphic3d_Vec3 (1.0f))); + aMaterial2[i].SetDiffuseColor (Quantity_NOC_BLACK); } else { @@ -512,10 +504,8 @@ void MeshVS_ElementalColorPrsBuilder::Build ( const Handle(Prs3d_Presentation)& // those in the color scale most exactly (the sum of all reflection // coefficients is equal to 1). See also MeshVS_NodalColorPrsBuilder // class for more explanations. - aMaterial2[i].SetAmbient( .5 ); - aMaterial2[i].SetDiffuse( .5 ); - aMaterial2[i].SetSpecular( 0. ); - aMaterial2[i].SetEmissive( 0. ); + aMaterial2[i].SetAmbientColor (Quantity_Color (Graphic3d_Vec3 (0.5f))); + aMaterial2[i].SetDiffuseColor (Quantity_Color (Graphic3d_Vec3 (0.5f))); } } diff --git a/src/MeshVS/MeshVS_MeshPrsBuilder.cxx b/src/MeshVS/MeshVS_MeshPrsBuilder.cxx index 99cb9c5c82..b627d16d7f 100644 --- a/src/MeshVS/MeshVS_MeshPrsBuilder.cxx +++ b/src/MeshVS/MeshVS_MeshPrsBuilder.cxx @@ -219,10 +219,10 @@ void MeshVS_MeshPrsBuilder::BuildElements( const Handle(Prs3d_Presentation)& Prs aDrawer->GetMaterial ( MeshVS_DA_FrontMaterial, AMat ); if ( !IsReflect ) { - AMat.SetReflectionModeOff(Graphic3d_TOR_AMBIENT); - AMat.SetReflectionModeOff(Graphic3d_TOR_DIFFUSE); - AMat.SetReflectionModeOff(Graphic3d_TOR_SPECULAR); - AMat.SetReflectionModeOff(Graphic3d_TOR_EMISSION); + AMat.SetAmbientColor (Quantity_NOC_BLACK); + AMat.SetDiffuseColor (Quantity_NOC_BLACK); + AMat.SetSpecularColor(Quantity_NOC_BLACK); + AMat.SetEmissiveColor(Quantity_NOC_BLACK); } Handle( Graphic3d_AspectFillArea3d ) aFill = MeshVS_Tool::CreateAspectFillArea3d( GetDrawer(), AMat ); Handle( Graphic3d_AspectLine3d ) aBeam = MeshVS_Tool::CreateAspectLine3d ( GetDrawer() ); @@ -533,10 +533,10 @@ void MeshVS_MeshPrsBuilder::BuildHilightPrs ( const Handle(Prs3d_Presentation)& Graphic3d_MaterialAspect AMat; aDrawer->GetMaterial ( MeshVS_DA_FrontMaterial, AMat ); - AMat.SetReflectionModeOff(Graphic3d_TOR_AMBIENT); - AMat.SetReflectionModeOff(Graphic3d_TOR_DIFFUSE); - AMat.SetReflectionModeOff(Graphic3d_TOR_SPECULAR); - AMat.SetReflectionModeOff(Graphic3d_TOR_EMISSION); + AMat.SetAmbientColor (Quantity_NOC_BLACK); + AMat.SetDiffuseColor (Quantity_NOC_BLACK); + AMat.SetSpecularColor(Quantity_NOC_BLACK); + AMat.SetEmissiveColor(Quantity_NOC_BLACK); Handle( Graphic3d_AspectFillArea3d ) aFill = MeshVS_Tool::CreateAspectFillArea3d( GetDrawer(), AMat ); Handle( Graphic3d_AspectLine3d ) aBeam = MeshVS_Tool::CreateAspectLine3d( GetDrawer() ); diff --git a/src/MeshVS/MeshVS_NodalColorPrsBuilder.cxx b/src/MeshVS/MeshVS_NodalColorPrsBuilder.cxx index fb74051c91..1d90c3fc79 100644 --- a/src/MeshVS/MeshVS_NodalColorPrsBuilder.cxx +++ b/src/MeshVS/MeshVS_NodalColorPrsBuilder.cxx @@ -189,20 +189,16 @@ void MeshVS_NodalColorPrsBuilder::Build ( const Handle(Prs3d_Presentation)& Prs, } // Draw faces with nodal color - // OCC20644 Use "plastic" material as it is "non-physic" and so it is easier - // to get the required colors (see TelUpdateMaterial() function in OpenGl_attri.c) - Graphic3d_MaterialAspect aMaterial[ 2 ]; - aMaterial[ 0 ] = Graphic3d_MaterialAspect( Graphic3d_NOM_PLASTIC ); - aMaterial[ 1 ] = Graphic3d_MaterialAspect( Graphic3d_NOM_PLASTIC ); - Standard_Integer i; - for ( i = 0; i < 2; i++ ) + // OCC20644 Use "plastic" material as it is "non-physic" and so it is easier to get the required colors + Graphic3d_MaterialAspect aMaterial[2] = { Graphic3d_NOM_PLASTIC, Graphic3d_NOM_PLASTIC }; + for (Standard_Integer i = 0; i < 2; ++i) { + aMaterial[i].SetSpecularColor (Quantity_NOC_BLACK); + aMaterial[i].SetEmissiveColor (Quantity_NOC_BLACK); if ( !IsReflect ) { - aMaterial[ i ].SetReflectionModeOff( Graphic3d_TOR_SPECULAR ); - aMaterial[ i ].SetReflectionModeOff( Graphic3d_TOR_AMBIENT ); - aMaterial[ i ].SetReflectionModeOff( Graphic3d_TOR_DIFFUSE ); - aMaterial[ i ].SetReflectionModeOff( Graphic3d_TOR_EMISSION ); + aMaterial[i].SetAmbientColor (Quantity_NOC_BLACK); + aMaterial[i].SetDiffuseColor (Quantity_NOC_BLACK); } else{ // OCC20644 Using the material with reflection properties same as in @@ -215,14 +211,10 @@ void MeshVS_NodalColorPrsBuilder::Build ( const Handle(Prs3d_Presentation)& Prs, // is done by TelUpdateMaterial(). // 0.5 is used to have the colors in 3D maximally similar to those in the color scale. // This is possible when the sum of all coefficient is equal to 1. - aMaterial[i].SetAmbient( .5 ); - aMaterial[i].SetDiffuse( .5 ); - aMaterial[i].SetSpecular( 0. ); - aMaterial[i].SetEmissive( 0. ); + aMaterial[i].SetAmbientColor (Quantity_Color (Graphic3d_Vec3 (0.5f))); + aMaterial[i].SetDiffuseColor (Quantity_Color (Graphic3d_Vec3 (0.5f))); } - - } - + } // Create array of polygons for interior presentation of faces and volumes Handle(Graphic3d_ArrayOfPolygons) aCPolyArr = new Graphic3d_ArrayOfPolygons @@ -283,7 +275,7 @@ void MeshVS_NodalColorPrsBuilder::Build ( const Handle(Prs3d_Presentation)& Prs, gp_Dir aDefNorm( 0., 0., 1. ); // Prepare for scaling the incoming colors - Standard_Real anColorRatio = aMaterial[0].Ambient(); + const Standard_Real anColorRatio = !IsReflect ? 0.44f : 0.5f; for (it.Reset(); it.More(); it.Next()) { diff --git a/src/OpenGl/OpenGl_Aspects.cxx b/src/OpenGl/OpenGl_Aspects.cxx index 13cf990279..6eae505d74 100644 --- a/src/OpenGl/OpenGl_Aspects.cxx +++ b/src/OpenGl/OpenGl_Aspects.cxx @@ -25,14 +25,10 @@ namespace { Graphic3d_MaterialAspect aMat; aMat.SetMaterialType (Graphic3d_MATERIAL_ASPECT); - aMat.SetAmbient (0.2f); - aMat.SetDiffuse (0.8f); - aMat.SetSpecular (0.1f); - aMat.SetEmissive (0.0f); - aMat.SetAmbientColor (Quantity_NOC_WHITE); - aMat.SetDiffuseColor (Quantity_NOC_WHITE); - aMat.SetEmissiveColor(Quantity_NOC_WHITE); - aMat.SetSpecularColor(Quantity_NOC_WHITE); + aMat.SetAmbientColor (Quantity_Color (Graphic3d_Vec3 (0.2f))); + aMat.SetDiffuseColor (Quantity_Color (Graphic3d_Vec3 (0.8f))); + aMat.SetEmissiveColor(Quantity_Color (Graphic3d_Vec3 (0.1f))); + aMat.SetSpecularColor(Quantity_NOC_BLACK); aMat.SetShininess (10.0f / 128.0f); aMat.SetRefractionIndex (1.0f); return aMat; diff --git a/src/OpenGl/OpenGl_Material.hxx b/src/OpenGl/OpenGl_Material.hxx index f2225a4d78..70695a707c 100644 --- a/src/OpenGl/OpenGl_Material.hxx +++ b/src/OpenGl/OpenGl_Material.hxx @@ -43,6 +43,14 @@ struct OpenGl_Material Diffuse.SetValues (theColor.rgb(), Diffuse.a()); } + //! Empty constructor. + OpenGl_Material() + : Ambient (1.0f), + Diffuse (1.0f), + Specular(1.0f), + Emission(1.0f), + Params (1.0f, 0.0f, 0.0f, 0.0f) {} + //! Initialize material void Init (const Graphic3d_MaterialAspect& theProp, const Quantity_Color& theInteriorColor); diff --git a/src/OpenGl/OpenGl_SceneGeometry.cxx b/src/OpenGl/OpenGl_SceneGeometry.cxx index 530bf57048..b13e16727c 100644 --- a/src/OpenGl/OpenGl_SceneGeometry.cxx +++ b/src/OpenGl/OpenGl_SceneGeometry.cxx @@ -47,66 +47,6 @@ OpenGl_RaytraceMaterial::OpenGl_RaytraceMaterial() Transparency (ZERO_VEC_4F) { } -// ======================================================================= -// function : OpenGl_RaytraceMaterial -// purpose : Creates new material with specified properties -// ======================================================================= -OpenGl_RaytraceMaterial::OpenGl_RaytraceMaterial (const BVH_Vec4f& theAmbient, - const BVH_Vec4f& theDiffuse, - const BVH_Vec4f& theSpecular) -: Ambient (theAmbient), - Diffuse (theDiffuse), - Specular (theSpecular), - Emission (ZERO_VEC_4F), - Reflection (ZERO_VEC_4F), - Refraction (ZERO_VEC_4F), - Transparency (ZERO_VEC_4F) -{ - // -} - -// ======================================================================= -// function : OpenGl_RaytraceMaterial -// purpose : Creates new material with specified properties -// ======================================================================= -OpenGl_RaytraceMaterial::OpenGl_RaytraceMaterial (const BVH_Vec4f& theAmbient, - const BVH_Vec4f& theDiffuse, - const BVH_Vec4f& theSpecular, - const BVH_Vec4f& theEmission, - const BVH_Vec4f& theTranspar) -: Ambient (theAmbient), - Diffuse (theDiffuse), - Specular (theSpecular), - Emission (theEmission), - Reflection (ZERO_VEC_4F), - Refraction (ZERO_VEC_4F), - Transparency (theTranspar) -{ - // -} - -// ======================================================================= -// function : OpenGl_RaytraceMaterial -// purpose : Creates new material with specified properties -// ======================================================================= -OpenGl_RaytraceMaterial::OpenGl_RaytraceMaterial (const BVH_Vec4f& theAmbient, - const BVH_Vec4f& theDiffuse, - const BVH_Vec4f& theSpecular, - const BVH_Vec4f& theEmission, - const BVH_Vec4f& theTranspar, - const BVH_Vec4f& theReflection, - const BVH_Vec4f& theRefraction) -: Ambient (theAmbient), - Diffuse (theDiffuse), - Specular (theSpecular), - Emission (theEmission), - Reflection (theReflection), - Refraction (theRefraction), - Transparency (theTranspar) -{ - // -} - // ======================================================================= // function : OpenGl_RaytraceLight // purpose : Creates new light source diff --git a/src/OpenGl/OpenGl_SceneGeometry.hxx b/src/OpenGl/OpenGl_SceneGeometry.hxx index 8fa64e2959..f48de97092 100644 --- a/src/OpenGl/OpenGl_SceneGeometry.hxx +++ b/src/OpenGl/OpenGl_SceneGeometry.hxx @@ -43,89 +43,35 @@ namespace OpenGl_Raytrace } //! Stores properties of surface material. -class OpenGl_RaytraceMaterial +struct OpenGl_RaytraceMaterial { -public: - - //! Ambient reflection coefficient. - BVH_Vec4f Ambient; - - //! Diffuse reflection coefficient. - BVH_Vec4f Diffuse; - - //! Glossy reflection coefficient. - BVH_Vec4f Specular; - - //! Material emission. - BVH_Vec4f Emission; - - //! Specular reflection coefficient. - BVH_Vec4f Reflection; - - //! Specular refraction coefficient. - BVH_Vec4f Refraction; - - //! Material transparency. - BVH_Vec4f Transparency; - - //! Texture transformation matrix. - BVH_Mat4f TextureTransform; + BVH_Vec4f Ambient; //!< Ambient reflection coefficient + BVH_Vec4f Diffuse; //!< Diffuse reflection coefficient + BVH_Vec4f Specular; //!< Glossy reflection coefficient + BVH_Vec4f Emission; //!< Material emission + BVH_Vec4f Reflection; //!< Specular reflection coefficient + BVH_Vec4f Refraction; //!< Specular refraction coefficient + BVH_Vec4f Transparency; //!< Material transparency + BVH_Mat4f TextureTransform; //!< Texture transformation matrix //! Physically-based material properties (used in path tracing engine). struct Physical { - //! Weight of coat specular/glossy BRDF. - BVH_Vec4f Kc; - - //! Weight of base diffuse BRDF. - BVH_Vec4f Kd; - - //! Weight of base specular/glossy BRDF. - BVH_Vec4f Ks; - - //! Weight of base specular/glossy BTDF. - BVH_Vec4f Kt; - - //! Radiance emitted by the surface. - BVH_Vec4f Le; - - //! Fresnel coefficients of coat layer. - BVH_Vec4f FresnelCoat; - - //! Fresnel coefficients of base layer. - BVH_Vec4f FresnelBase; - - //! Absorption color/intensity. - BVH_Vec4f Absorption; - + BVH_Vec4f Kc; //!< Weight of coat specular/glossy BRDF + BVH_Vec4f Kd; //!< Weight of base diffuse BRDF + BVH_Vec4f Ks; //!< Weight of base specular/glossy BRDF + BVH_Vec4f Kt; //!< Weight of base specular/glossy BTDF + BVH_Vec4f Le; //!< Radiance emitted by the surface + BVH_Vec4f FresnelCoat; //!< Fresnel coefficients of coat layer + BVH_Vec4f FresnelBase; //!< Fresnel coefficients of base layer + BVH_Vec4f Absorption; //!< Absorption color/intensity } BSDF; public: - //! Creates new default material. + //! Empty constructor. OpenGl_RaytraceMaterial(); - //! Creates new material with specified properties. - OpenGl_RaytraceMaterial (const BVH_Vec4f& theAmbient, - const BVH_Vec4f& theDiffuse, - const BVH_Vec4f& theSpecular); - - //! Creates new material with specified properties. - OpenGl_RaytraceMaterial (const BVH_Vec4f& theAmbient, - const BVH_Vec4f& theDiffuse, - const BVH_Vec4f& theSpecular, - const BVH_Vec4f& theEmission, - const BVH_Vec4f& theTranspar); - - //! Creates new material with specified properties. - OpenGl_RaytraceMaterial (const BVH_Vec4f& theAmbient, - const BVH_Vec4f& theDiffuse, - const BVH_Vec4f& theSpecular, - const BVH_Vec4f& theEmission, - const BVH_Vec4f& theTranspar, - const BVH_Vec4f& theReflection, - const BVH_Vec4f& theRefraction); - //! Returns packed (serialized) representation of material. const Standard_ShortReal* Packed() { @@ -134,15 +80,11 @@ public: }; //! Stores properties of OpenGL light source. -class OpenGl_RaytraceLight +struct OpenGl_RaytraceLight { -public: - //! Diffuse intensity (in terms of OpenGL). - BVH_Vec4f Emission; - - //! Position of light source (in terms of OpenGL). - BVH_Vec4f Position; + BVH_Vec4f Emission; //!< Diffuse intensity (in terms of OpenGL) + BVH_Vec4f Position; //!< Position of light source (in terms of OpenGL) public: diff --git a/src/OpenGl/OpenGl_View.hxx b/src/OpenGl/OpenGl_View.hxx index 1b05ee7200..87e6605ce8 100644 --- a/src/OpenGl/OpenGl_View.hxx +++ b/src/OpenGl/OpenGl_View.hxx @@ -58,7 +58,6 @@ struct OpenGl_Matrix; class Graphic3d_StructureManager; class OpenGl_GraphicDriver; class OpenGl_StateCounter; -class OpenGl_RaytraceMaterial; class OpenGl_TriangleSet; class OpenGl_Workspace; class OpenGl_View; diff --git a/src/OpenGl/OpenGl_View_Raytrace.cxx b/src/OpenGl/OpenGl_View_Raytrace.cxx index 33dec76c21..e64e55906b 100644 --- a/src/OpenGl/OpenGl_View_Raytrace.cxx +++ b/src/OpenGl/OpenGl_View_Raytrace.cxx @@ -350,90 +350,67 @@ void buildTextureTransform (const Handle(Graphic3d_TextureParams)& theParams, BV OpenGl_RaytraceMaterial OpenGl_View::convertMaterial (const OpenGl_Aspects* theAspect, const Handle(OpenGl_Context)& theGlContext) { - OpenGl_RaytraceMaterial theMaterial; + OpenGl_RaytraceMaterial aResMat; const Graphic3d_MaterialAspect& aSrcMat = theAspect->Aspect()->FrontMaterial(); const OpenGl_Vec3& aMatCol = theAspect->Aspect()->InteriorColor(); - const bool isPhysic = aSrcMat.MaterialType (Graphic3d_MATERIAL_PHYSIC); const float aShine = 128.0f * float(aSrcMat.Shininess()); - // ambient component - if (aSrcMat.ReflectionMode (Graphic3d_TOR_AMBIENT)) + const OpenGl_Vec3& aSrcAmb = aSrcMat.AmbientColor(); + const OpenGl_Vec3& aSrcDif = aSrcMat.DiffuseColor(); + const OpenGl_Vec3& aSrcSpe = aSrcMat.SpecularColor(); + const OpenGl_Vec3& aSrcEms = aSrcMat.EmissiveColor(); + switch (aSrcMat.MaterialType()) { - const OpenGl_Vec3& aSrcAmb = isPhysic ? aSrcMat.AmbientColor() : aMatCol; - theMaterial.Ambient = BVH_Vec4f (aSrcAmb * (float )aSrcMat.Ambient(), 1.0f); - } - else - { - theMaterial.Ambient = THE_BLACK_COLOR; + case Graphic3d_MATERIAL_ASPECT: + { + aResMat.Ambient .SetValues (aSrcAmb * aMatCol, 1.0f); + aResMat.Diffuse .SetValues (aSrcDif * aMatCol, -1.0f); // -1 is no texture + aResMat.Emission.SetValues (aSrcEms * aMatCol, 1.0f); + break; + } + case Graphic3d_MATERIAL_PHYSIC: + { + aResMat.Ambient .SetValues (aSrcAmb, 1.0f); + aResMat.Diffuse .SetValues (aSrcDif, -1.0f); // -1 is no texture + aResMat.Emission.SetValues (aSrcEms, 1.0f); + break; + } } - // diffusion component - if (aSrcMat.ReflectionMode (Graphic3d_TOR_DIFFUSE)) { - const OpenGl_Vec3& aSrcDif = isPhysic ? aSrcMat.DiffuseColor() : aMatCol; - theMaterial.Diffuse = BVH_Vec4f (aSrcDif * (float )aSrcMat.Diffuse(), -1.0f); // -1 is no texture - } - else - { - theMaterial.Diffuse = BVH_Vec4f (THE_BLACK_COLOR.rgb(), -1.0f); - } - - // specular component - if (aSrcMat.ReflectionMode (Graphic3d_TOR_SPECULAR)) - { - const OpenGl_Vec3& aSrcSpe = aSrcMat.SpecularColor(); - const OpenGl_Vec3& aSrcSpe2 = isPhysic ? aSrcSpe : THE_WHITE_COLOR.rgb(); - theMaterial.Specular = BVH_Vec4f (aSrcSpe2 * (float )aSrcMat.Specular(), aShine); - - const Standard_ShortReal aMaxRefl = Max (theMaterial.Diffuse.x() + theMaterial.Specular.x(), - Max (theMaterial.Diffuse.y() + theMaterial.Specular.y(), - theMaterial.Diffuse.z() + theMaterial.Specular.z())); - + // interior color is always ignored for Specular + aResMat.Specular.SetValues (aSrcSpe, aShine); + const Standard_ShortReal aMaxRefl = Max (aResMat.Diffuse.x() + aResMat.Specular.x(), + Max (aResMat.Diffuse.y() + aResMat.Specular.y(), + aResMat.Diffuse.z() + aResMat.Specular.z())); const Standard_ShortReal aReflectionScale = 0.75f / aMaxRefl; - - // ignore isPhysic here - theMaterial.Reflection = BVH_Vec4f (aSrcSpe * (float )aSrcMat.Specular() * aReflectionScale, 0.0f); - } - else - { - theMaterial.Specular = BVH_Vec4f (THE_BLACK_COLOR.rgb(), aShine); - } - - // emission component - if (aSrcMat.ReflectionMode (Graphic3d_TOR_EMISSION)) - { - const OpenGl_Vec3& aSrcEms = isPhysic ? aSrcMat.EmissiveColor() : aMatCol; - theMaterial.Emission = BVH_Vec4f (aSrcEms * (float )aSrcMat.Emissive(), 1.0f); - } - else - { - theMaterial.Emission = THE_BLACK_COLOR; + aResMat.Reflection.SetValues (aSrcSpe * aReflectionScale, 0.0f); } const float anIndex = (float )aSrcMat.RefractionIndex(); - theMaterial.Transparency = BVH_Vec4f (aSrcMat.Alpha(), aSrcMat.Transparency(), - anIndex == 0 ? 1.0f : anIndex, - anIndex == 0 ? 1.0f : 1.0f / anIndex); + aResMat.Transparency = BVH_Vec4f (aSrcMat.Alpha(), aSrcMat.Transparency(), + anIndex == 0 ? 1.0f : anIndex, + anIndex == 0 ? 1.0f : 1.0f / anIndex); // Serialize physically-based material properties const Graphic3d_BSDF& aBSDF = aSrcMat.BSDF(); - theMaterial.BSDF.Kc = aBSDF.Kc; - theMaterial.BSDF.Ks = aBSDF.Ks; - theMaterial.BSDF.Kd = BVH_Vec4f (aBSDF.Kd, -1.f); // no texture - theMaterial.BSDF.Kt = BVH_Vec4f (aBSDF.Kt, 0.f); - theMaterial.BSDF.Le = BVH_Vec4f (aBSDF.Le, 0.f); + aResMat.BSDF.Kc = aBSDF.Kc; + aResMat.BSDF.Ks = aBSDF.Ks; + aResMat.BSDF.Kd = BVH_Vec4f (aBSDF.Kd, -1.f); // no texture + aResMat.BSDF.Kt = BVH_Vec4f (aBSDF.Kt, 0.f); + aResMat.BSDF.Le = BVH_Vec4f (aBSDF.Le, 0.f); - theMaterial.BSDF.Absorption = aBSDF.Absorption; + aResMat.BSDF.Absorption = aBSDF.Absorption; - theMaterial.BSDF.FresnelCoat = aBSDF.FresnelCoat.Serialize (); - theMaterial.BSDF.FresnelBase = aBSDF.FresnelBase.Serialize (); + aResMat.BSDF.FresnelCoat = aBSDF.FresnelCoat.Serialize (); + aResMat.BSDF.FresnelBase = aBSDF.FresnelBase.Serialize (); // Handle material textures if (!theAspect->Aspect()->ToMapTexture()) { - return theMaterial; + return aResMat; } const Handle(OpenGl_TextureSet)& aTextureSet = theAspect->TextureSet (theGlContext); @@ -441,30 +418,26 @@ OpenGl_RaytraceMaterial OpenGl_View::convertMaterial (const OpenGl_Aspects* theA || aTextureSet->IsEmpty() || aTextureSet->First().IsNull()) { - return theMaterial; + return aResMat; } if (theGlContext->HasRayTracingTextures()) { const Handle(OpenGl_Texture)& aTexture = aTextureSet->First(); - buildTextureTransform (aTexture->Sampler()->Parameters(), theMaterial.TextureTransform); + buildTextureTransform (aTexture->Sampler()->Parameters(), aResMat.TextureTransform); // write texture ID to diffuse w-component - theMaterial.Diffuse.w() = theMaterial.BSDF.Kd.w() = static_cast (myRaytraceGeometry.AddTexture (aTexture)); + aResMat.Diffuse.w() = aResMat.BSDF.Kd.w() = static_cast (myRaytraceGeometry.AddTexture (aTexture)); } else if (!myIsRaytraceWarnTextures) { - const TCollection_ExtendedString aWarnMessage = - "Warning: texturing in Ray-Trace requires GL_ARB_bindless_texture extension which is missing. " - "Please try to update graphics card driver. At the moment textures will be ignored."; - - theGlContext->PushMessage (GL_DEBUG_SOURCE_APPLICATION, - GL_DEBUG_TYPE_PORTABILITY, 0, GL_DEBUG_SEVERITY_HIGH, aWarnMessage); - + theGlContext->PushMessage (GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_PORTABILITY, 0, GL_DEBUG_SEVERITY_HIGH, + "Warning: texturing in Ray-Trace requires GL_ARB_bindless_texture extension which is missing. " + "Please try to update graphics card driver. At the moment textures will be ignored."); myIsRaytraceWarnTextures = Standard_True; } - return theMaterial; + return aResMat; } // ======================================================================= diff --git a/src/OpenGl/OpenGl_Workspace.cxx b/src/OpenGl/OpenGl_Workspace.cxx index c13bcb3cca..71f074b585 100644 --- a/src/OpenGl/OpenGl_Workspace.cxx +++ b/src/OpenGl/OpenGl_Workspace.cxx @@ -57,52 +57,30 @@ namespace void OpenGl_Material::Init (const Graphic3d_MaterialAspect& theMat, const Quantity_Color& theInteriorColor) { - const bool isPhysic = theMat.MaterialType (Graphic3d_MATERIAL_PHYSIC); ChangeShine() = 128.0f * theMat.Shininess(); ChangeTransparency() = theMat.Alpha(); - // ambient component - if (theMat.ReflectionMode (Graphic3d_TOR_AMBIENT)) + const OpenGl_Vec3& aSrcAmb = theMat.AmbientColor(); + const OpenGl_Vec3& aSrcDif = theMat.DiffuseColor(); + const OpenGl_Vec3& aSrcSpe = theMat.SpecularColor(); + const OpenGl_Vec3& aSrcEms = theMat.EmissiveColor(); + Specular.SetValues (aSrcSpe, 1.0f); // interior color is ignored for Specular + switch (theMat.MaterialType()) { - const OpenGl_Vec3& aSrcAmb = isPhysic ? theMat.AmbientColor() : theInteriorColor; - Ambient = OpenGl_Vec4 (aSrcAmb * theMat.Ambient(), 1.0f); - } - else - { - Ambient = THE_BLACK_COLOR; - } - - // diffusion component - if (theMat.ReflectionMode (Graphic3d_TOR_DIFFUSE)) - { - const OpenGl_Vec3& aSrcDif = isPhysic ? theMat.DiffuseColor() : theInteriorColor; - Diffuse = OpenGl_Vec4 (aSrcDif * theMat.Diffuse(), 1.0f); - } - else - { - Diffuse = THE_BLACK_COLOR; - } - - // specular component - if (theMat.ReflectionMode (Graphic3d_TOR_SPECULAR)) - { - const OpenGl_Vec3& aSrcSpe = isPhysic ? (const OpenGl_Vec3& )theMat.SpecularColor() : THE_WHITE_COLOR.rgb(); - Specular = OpenGl_Vec4 (aSrcSpe * theMat.Specular(), 1.0f); - } - else - { - Specular = THE_BLACK_COLOR; - } - - // emission component - if (theMat.ReflectionMode (Graphic3d_TOR_EMISSION)) - { - const OpenGl_Vec3& aSrcEms = isPhysic ? theMat.EmissiveColor() : theInteriorColor; - Emission = OpenGl_Vec4 (aSrcEms * theMat.Emissive(), 1.0f); - } - else - { - Emission = THE_BLACK_COLOR; + case Graphic3d_MATERIAL_ASPECT: + { + Ambient .SetValues (aSrcAmb * theInteriorColor, 1.0f); + Diffuse .SetValues (aSrcDif * theInteriorColor, 1.0f); + Emission.SetValues (aSrcEms * theInteriorColor, 1.0f); + break; + } + case Graphic3d_MATERIAL_PHYSIC: + { + Ambient .SetValues (aSrcAmb, 1.0f); + Diffuse .SetValues (aSrcDif, 1.0f); + Emission.SetValues (aSrcEms, 1.0f); + break; + } } } diff --git a/src/Prs3d/Prs3d_ShadingAspect.cxx b/src/Prs3d/Prs3d_ShadingAspect.cxx index 102deb416a..3e2ea06d8e 100644 --- a/src/Prs3d/Prs3d_ShadingAspect.cxx +++ b/src/Prs3d/Prs3d_ShadingAspect.cxx @@ -76,9 +76,13 @@ const Quantity_Color& Prs3d_ShadingAspect::Color (const Aspect_TypeOfFacingModel default: case Aspect_TOFM_BOTH_SIDE: case Aspect_TOFM_FRONT_SIDE: - return myAspect->FrontMaterial().Color(); + return myAspect->FrontMaterial().MaterialType() == Graphic3d_MATERIAL_ASPECT + ? myAspect->InteriorColor() + : myAspect->FrontMaterial().Color(); case Aspect_TOFM_BACK_SIDE: - return myAspect->BackMaterial().Color(); + return myAspect->BackMaterial().MaterialType() == Graphic3d_MATERIAL_ASPECT + ? myAspect->BackInteriorColor() + : myAspect->BackMaterial().Color(); } } diff --git a/src/QABugs/QABugs_17.cxx b/src/QABugs/QABugs_17.cxx index 6638171e0b..87457bda7e 100644 --- a/src/QABugs/QABugs_17.cxx +++ b/src/QABugs/QABugs_17.cxx @@ -1113,7 +1113,7 @@ static Standard_Integer OCC1174_1 (Draw_Interpretor& di, Standard_Integer argc, aFront.SetAmbientColor(aColF); aFront.SetDiffuseColor(aColF); aFront.SetSpecularColor(aColF); - aFront.SetEmissiveColor(aColF); + aFront.SetEmissiveColor(Quantity_NOC_BLACK); aFront.SetTransparency(0.0); aShadingAspect->SetMaterial(aFront,Aspect_TOFM_FRONT_SIDE); @@ -1121,7 +1121,7 @@ static Standard_Integer OCC1174_1 (Draw_Interpretor& di, Standard_Integer argc, aBack.SetAmbientColor(aColB); aBack.SetDiffuseColor(aColB); aBack.SetSpecularColor(aColB); - aBack.SetEmissiveColor(aColB); + aBack.SetEmissiveColor(Quantity_NOC_BLACK); aBack.SetTransparency(0.0); aShadingAspect->SetMaterial(aBack,Aspect_TOFM_BACK_SIDE); @@ -1171,7 +1171,7 @@ static Standard_Integer OCC1174_2 (Draw_Interpretor& di, Standard_Integer argc, front.SetAmbientColor(colf); front.SetDiffuseColor(colf); front.SetSpecularColor(colf); - front.SetEmissiveColor(colf); + front.SetEmissiveColor(Quantity_NOC_BLACK); front.SetTransparency (0.4f); sa->SetMaterial(front,Aspect_TOFM_FRONT_SIDE); @@ -1179,7 +1179,7 @@ static Standard_Integer OCC1174_2 (Draw_Interpretor& di, Standard_Integer argc, back.SetAmbientColor(colb); back.SetDiffuseColor(colb); back.SetSpecularColor(colb); - back.SetEmissiveColor(colb); + back.SetEmissiveColor(Quantity_NOC_BLACK); back.SetTransparency (0.2f); sa->SetMaterial(back,Aspect_TOFM_BACK_SIDE); diff --git a/src/QABugs/QABugs_PresentableObject.cxx b/src/QABugs/QABugs_PresentableObject.cxx index 6dff125d49..87ee177f5d 100644 --- a/src/QABugs/QABugs_PresentableObject.cxx +++ b/src/QABugs/QABugs_PresentableObject.cxx @@ -42,10 +42,10 @@ void QABugs_PresentableObject::Compute(const Handle(PrsMgr_PresentationManager3d Handle(Graphic3d_Group) aGroup = aStructure->NewGroup(); Handle(Prs3d_ShadingAspect) anAspect = myDrawer->ShadingAspect(); Graphic3d_MaterialAspect aMat = anAspect->Aspect()->FrontMaterial(); - aMat.SetReflectionModeOff (Graphic3d_TOR_AMBIENT); - aMat.SetReflectionModeOff (Graphic3d_TOR_DIFFUSE); - aMat.SetReflectionModeOff (Graphic3d_TOR_SPECULAR); - aMat.SetReflectionModeOff (Graphic3d_TOR_EMISSION); + aMat.SetAmbientColor (Quantity_NOC_BLACK); + aMat.SetDiffuseColor (Quantity_NOC_BLACK); + aMat.SetSpecularColor(Quantity_NOC_BLACK); + aMat.SetEmissiveColor(Quantity_NOC_BLACK); anAspect->SetMaterial (aMat); aGroup->SetPrimitivesAspect (anAspect->Aspect()); diff --git a/src/V3d/V3d_Trihedron.cxx b/src/V3d/V3d_Trihedron.cxx index e02db0e4ce..20bb0671c2 100644 --- a/src/V3d/V3d_Trihedron.cxx +++ b/src/V3d/V3d_Trihedron.cxx @@ -91,7 +91,7 @@ V3d_Trihedron::V3d_Trihedron() // Set material. Graphic3d_MaterialAspect aShadingMaterial; - aShadingMaterial.SetReflectionModeOff (Graphic3d_TOR_SPECULAR); + aShadingMaterial.SetSpecularColor(Quantity_NOC_BLACK); aShadingMaterial.SetMaterialType (Graphic3d_MATERIAL_ASPECT); for (Standard_Integer anIt = 0; anIt < 3; ++anIt) diff --git a/src/ViewerTest/ViewerTest.cxx b/src/ViewerTest/ViewerTest.cxx index d008ef9a01..8805ea57ef 100644 --- a/src/ViewerTest/ViewerTest.cxx +++ b/src/ViewerTest/ViewerTest.cxx @@ -1964,12 +1964,6 @@ struct ViewerTest_AspectsChangeSet std::cout << "Error: alpha cutoff value should be within (0; 1) range (specified " << AlphaCutoff << ")\n"; isOk = Standard_False; } - if (ToSetMaterial == 1 - && Material == Graphic3d_NOM_DEFAULT) - { - std::cout << "Error: unknown material " << MatName << ".\n"; - isOk = Standard_False; - } if (FreeBoundaryWidth <= 0.0 || FreeBoundaryWidth > 10.0) { @@ -2421,9 +2415,13 @@ static Standard_Integer VAspects (Draw_Interpretor& /*theDI*/, return 1; } aChangeSet->ToSetMaterial = 1; - aChangeSet->MatName = aNames.Last(); - aChangeSet->Material = Graphic3d_MaterialAspect::MaterialFromName (aChangeSet->MatName.ToCString()); + aChangeSet->MatName = aNames.Last(); aNames.Remove (aNames.Length()); + if (!Graphic3d_MaterialAspect::MaterialFromName (aChangeSet->MatName.ToCString(), aChangeSet->Material)) + { + std::cout << "Syntax error: unknown material '" << aChangeSet->MatName << "'.\n"; + return 1; + } } else if (aCmdName == "vunsetmaterial") { @@ -2861,8 +2859,12 @@ static Standard_Integer VAspects (Draw_Interpretor& /*theDI*/, return 1; } aChangeSet->ToSetMaterial = 1; - aChangeSet->MatName = theArgVec[anArgIter]; - aChangeSet->Material = Graphic3d_MaterialAspect::MaterialFromName (aChangeSet->MatName.ToCString()); + aChangeSet->MatName = theArgVec[anArgIter]; + if (!Graphic3d_MaterialAspect::MaterialFromName (aChangeSet->MatName.ToCString(), aChangeSet->Material)) + { + std::cout << "Syntax error: unknown material '" << aChangeSet->MatName << "'.\n"; + return 1; + } } else if (anArg == "-unsetmat" || anArg == "-unsetmaterial") diff --git a/src/ViewerTest/ViewerTest_ObjectCommands.cxx b/src/ViewerTest/ViewerTest_ObjectCommands.cxx index 02f63eb9cc..653acdbef5 100644 --- a/src/ViewerTest/ViewerTest_ObjectCommands.cxx +++ b/src/ViewerTest/ViewerTest_ObjectCommands.cxx @@ -3048,8 +3048,8 @@ static int VDrawSphere (Draw_Interpretor& /*di*/, Standard_Integer argc, const c // Setting material properties, very important for desirable visual result! Graphic3d_MaterialAspect aMat (Graphic3d_NOM_PLASTIC); - aMat.SetAmbient (0.2f); - aMat.SetSpecular (0.5f); + aMat.SetAmbientColor (Quantity_Color (Graphic3d_Vec3 (0.04f))); + aMat.SetSpecularColor(Quantity_Color (Graphic3d_Vec3 (0.50f))); Handle(Graphic3d_AspectFillArea3d) anAspect = new Graphic3d_AspectFillArea3d (Aspect_IS_SOLID, Quantity_NOC_RED, diff --git a/src/ViewerTest/ViewerTest_OpenGlCommands.cxx b/src/ViewerTest/ViewerTest_OpenGlCommands.cxx index b6d41ec969..d140eb1726 100644 --- a/src/ViewerTest/ViewerTest_OpenGlCommands.cxx +++ b/src/ViewerTest/ViewerTest_OpenGlCommands.cxx @@ -1082,18 +1082,10 @@ static Standard_Integer VListMaterials (Draw_Interpretor& theDI, { Graphic3d_MaterialAspect aMat (aMatIter.Value()); const TCollection_AsciiString aMatName = aMat.StringName(); - const Graphic3d_Vec3 anAmbient = aMat.ReflectionMode (Graphic3d_TOR_AMBIENT) - ? (Graphic3d_Vec3 )aMat.AmbientColor() * aMat.Ambient() - : Graphic3d_Vec3 (0.0f); - const Graphic3d_Vec3 aDiffuse = aMat.ReflectionMode (Graphic3d_TOR_DIFFUSE) - ? (Graphic3d_Vec3 )aMat.DiffuseColor() * aMat.Diffuse() - : Graphic3d_Vec3 (0.0f); - const Graphic3d_Vec3 aSpecular = aMat.ReflectionMode (Graphic3d_TOR_SPECULAR) - ? (Graphic3d_Vec3 )aMat.SpecularColor() * aMat.Specular() - : Graphic3d_Vec3 (0.0f); - const Graphic3d_Vec3 anEmission = aMat.ReflectionMode (Graphic3d_TOR_EMISSION) - ? (Graphic3d_Vec3 )aMat.EmissiveColor() * aMat.Emissive() - : Graphic3d_Vec3 (0.0f); + const Graphic3d_Vec3 anAmbient = (Graphic3d_Vec3 )aMat.AmbientColor(); + const Graphic3d_Vec3 aDiffuse = (Graphic3d_Vec3 )aMat.DiffuseColor(); + const Graphic3d_Vec3 aSpecular = (Graphic3d_Vec3 )aMat.SpecularColor(); + const Graphic3d_Vec3 anEmission = (Graphic3d_Vec3 )aMat.EmissiveColor(); const Standard_Real aShiness = aMat.Shininess() * 1000.0; if (aMatFile.is_open()) { diff --git a/src/ViewerTest/ViewerTest_ViewerCommands.cxx b/src/ViewerTest/ViewerTest_ViewerCommands.cxx index 833ac10d93..90c890d905 100644 --- a/src/ViewerTest/ViewerTest_ViewerCommands.cxx +++ b/src/ViewerTest/ViewerTest_ViewerCommands.cxx @@ -7203,18 +7203,10 @@ public: const Handle(Graphic3d_AspectFillArea3d)& aFillAspect = myDrawer->ShadingAspect()->Aspect(); Graphic3d_MaterialAspect aMat; aMat.SetMaterialType (Graphic3d_MATERIAL_PHYSIC); - aMat.SetAmbient (1.0); - aMat.SetDiffuse (1.0); - aMat.SetSpecular (1.0); - aMat.SetEmissive (1.0); - aMat.SetReflectionModeOn (Graphic3d_TOR_AMBIENT); - aMat.SetReflectionModeOn (Graphic3d_TOR_DIFFUSE); - aMat.SetReflectionModeOn (Graphic3d_TOR_SPECULAR); - aMat.SetReflectionModeOn (Graphic3d_TOR_EMISSION); - aMat.SetAmbientColor (Quantity_Color (0.0, 0.0, 0.0, Quantity_TOC_RGB)); - aMat.SetDiffuseColor (Quantity_Color (1.0, 1.0, 1.0, Quantity_TOC_RGB)); - aMat.SetSpecularColor (Quantity_Color (0.0, 0.0, 0.0, Quantity_TOC_RGB)); - aMat.SetEmissiveColor (Quantity_Color (0.0, 0.0, 0.0, Quantity_TOC_RGB)); + aMat.SetAmbientColor (Quantity_NOC_BLACK); + aMat.SetDiffuseColor (Quantity_NOC_WHITE); + aMat.SetSpecularColor (Quantity_NOC_BLACK); + aMat.SetEmissiveColor (Quantity_NOC_BLACK); aFillAspect->SetFrontMaterial (aMat); aFillAspect->SetTextureMap (new Graphic3d_Texture2Dmanual (theImage)); aFillAspect->SetTextureMapOn(); @@ -9594,13 +9586,22 @@ static int VClipPlane (Draw_Interpretor& theDi, Standard_Integer theArgsNb, cons std::cout << "Syntax error: need more arguments.\n"; return 1; } - - Graphic3d_MaterialAspect aMat = aClipPlane->CappingMaterial(); - aMat.SetAmbientColor (aColor); - aMat.SetDiffuseColor (aColor); - aClipPlane->SetCappingMaterial (aMat); + aClipPlane->SetCappingColor (aColor); anArgIter += aNbParsed; } + else if (aNbChangeArgs >= 1 + && (aChangeArg == "-material" + || aChangeArg == "material")) + { + ++anArgIter; + Graphic3d_NameOfMaterial aMatName; + if (!Graphic3d_MaterialAspect::MaterialFromName (aChangeArgs[1], aMatName)) + { + std::cout << "Syntax error: unknown material '" << aChangeArgs[1] << "'.\n"; + return 1; + } + aClipPlane->SetCappingMaterial (aMatName); + } else if ((aChangeArg == "-transparency" || aChangeArg == "-transp") && aNbChangeArgs >= 2)