|
||||
File indexing completed on 2025-01-18 10:03:49
0001 // Author: Ilya Khramov 0002 // Copyright (c) 2019 OPEN CASCADE SAS 0003 // 0004 // This file is part of Open CASCADE Technology software library. 0005 // 0006 // This library is free software; you can redistribute it and/or modify it under 0007 // the terms of the GNU Lesser General Public License version 2.1 as published 0008 // by the Free Software Foundation, with special exception defined in the file 0009 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT 0010 // distribution for complete text of the license and disclaimer of any warranty. 0011 // 0012 // Alternatively, this file may be used under the terms of Open CASCADE 0013 // commercial license or contractual agreement. 0014 0015 #ifndef _Graphic3d_PBRMaterial_HeaderFile 0016 #define _Graphic3d_PBRMaterial_HeaderFile 0017 0018 #include <Image_PixMap.hxx> 0019 #include <Graphic3d_BSDF.hxx> 0020 #include <Graphic3d_Vec2.hxx> 0021 #include <Graphic3d_Vec3.hxx> 0022 #include <Quantity_Color.hxx> 0023 0024 //! Class implementing Metallic-Roughness physically based material definition 0025 class Graphic3d_PBRMaterial 0026 { 0027 public: 0028 0029 //! Creates new physically based material in Metallic-Roughness system. 0030 //! 'metallic' parameter is 0 by default. 0031 //! 'roughness' parameter is 1 by default. 0032 //! 'color' parameter is (0, 0, 0) by default. 0033 //! 'alpha' parameter is 1 by default. 0034 //! 'IOR' parameter is 1.5 by default. 0035 //! 'emission' parameter is (0, 0, 0) by default. 0036 Standard_EXPORT Graphic3d_PBRMaterial(); 0037 0038 //! Creates new physically based material in Metallic-Roughness system from Graphic3d_BSDF. 0039 Standard_EXPORT Graphic3d_PBRMaterial (const Graphic3d_BSDF& theBSDF); 0040 0041 //! Returns material's metallic coefficient in [0, 1] range. 0042 //! 1 for metals and 0 for dielectrics. 0043 //! It is preferable to be exactly 0 or 1. Average values are needed for textures mixing in shader. 0044 Standard_ShortReal Metallic() const { return myMetallic; } 0045 0046 //! Modifies metallic coefficient of material in [0, 1] range. 0047 Standard_EXPORT void SetMetallic (Standard_ShortReal theMetallic); 0048 0049 //! Maps roughness from [0, 1] to [MinRoughness, 1] for calculations. 0050 Standard_EXPORT static Standard_ShortReal Roughness(Standard_ShortReal theNormalizedRoughness); 0051 0052 //! Returns real value of roughness in [MinRoughness, 1] range for calculations. 0053 Standard_ShortReal Roughness() const { return Roughness(myRoughness); } 0054 0055 //! Returns roughness mapping parameter in [0, 1] range. 0056 //! Roughness is defined in [0, 1] for handful material settings 0057 //! and is mapped to [MinRoughness, 1] for calculations. 0058 Standard_ShortReal NormalizedRoughness() const { return myRoughness; } 0059 0060 //! Modifies roughness coefficient of material in [0, 1] range. 0061 Standard_EXPORT void SetRoughness (Standard_ShortReal theRoughness); 0062 0063 //! Returns index of refraction in [1, 3] range. 0064 Standard_ShortReal IOR() const { return myIOR; } 0065 0066 //! Modifies index of refraction in [1, 3] range. 0067 //! In practice affects only on non-metal materials reflection possibilities. 0068 Standard_EXPORT void SetIOR (Standard_ShortReal theIOR); 0069 0070 //! Returns albedo color with alpha component of material. 0071 const Quantity_ColorRGBA& Color() const { return myColor; } 0072 0073 //! Modifies albedo color with alpha component. 0074 Standard_EXPORT void SetColor (const Quantity_ColorRGBA& theColor); 0075 0076 //! Modifies only albedo color. 0077 Standard_EXPORT void SetColor (const Quantity_Color& theColor); 0078 0079 //! Returns alpha component in range [0, 1]. 0080 Standard_ShortReal Alpha() const { return myColor.Alpha(); }; 0081 0082 //! Modifies alpha component. 0083 Standard_EXPORT void SetAlpha (Standard_ShortReal theAlpha); 0084 0085 //! Returns light intensity emitted by material. 0086 //! Values are greater or equal 0. 0087 Graphic3d_Vec3 Emission() const { return myEmission; } 0088 0089 //! Modifies light intensity emitted by material. 0090 Standard_EXPORT void SetEmission (const Graphic3d_Vec3& theEmission); 0091 0092 //! Generates material in Metallic-Roughness system from Graphic3d_BSDF. 0093 Standard_EXPORT void SetBSDF (const Graphic3d_BSDF& theBSDF); 0094 0095 public: 0096 0097 //! PBR materials comparison operator. 0098 Standard_Boolean operator== (const Graphic3d_PBRMaterial& theOther) const 0099 { 0100 return (myMetallic == theOther.myMetallic) 0101 && (myRoughness == theOther.myRoughness) 0102 && (myIOR == theOther.myIOR) 0103 && (myColor == theOther.myColor) 0104 && (myEmission == theOther.myEmission); 0105 } 0106 0107 public: 0108 0109 //! Generates 2D look up table of scale and bias for fresnell zero coefficient. 0110 //! It is needed for calculation reflectance part of environment lighting. 0111 //! @param [out] theLUT table storage (must be Image_Format_RGF). 0112 //! @param [in] theNbIntegralSamples number of importance samples in hemisphere integral calculation for every table item. 0113 Standard_EXPORT static void GenerateEnvLUT (const Handle(Image_PixMap)& theLUT, 0114 unsigned int theNbIntegralSamples = 1024); 0115 0116 //! Compute material roughness from common material (specular color + shininess). 0117 //! @param theSpecular [in] specular color 0118 //! @param theShiness [in] normalized shininess coefficient within [0..1] range 0119 //! @return roughness within [0..1] range 0120 Standard_EXPORT static Standard_ShortReal RoughnessFromSpecular (const Quantity_Color& theSpecular, 0121 const Standard_Real theShiness); 0122 0123 //! Compute material metallicity from common material (specular color). 0124 //! @param theSpecular [in] specular color 0125 //! @return metallicity within [0..1] range 0126 static Standard_ShortReal MetallicFromSpecular (const Quantity_Color& theSpecular) 0127 { 0128 return ((Graphic3d_Vec3 )theSpecular).maxComp(); 0129 } 0130 0131 public: 0132 0133 //! Roughness cannot be 0 in real calculations, so it returns minimal achievable level of roughness in practice 0134 static Standard_ShortReal MinRoughness() { return 0.01f; } 0135 0136 public: 0137 0138 //! Shows how much times less samples can be used in certain roughness value specular IBL map generation 0139 //! in compare with samples number for map with roughness of 1. 0140 //! Specular IBL maps with less roughness values have higher resolution but require less samples for the same quality of baking. 0141 //! So that reducing samples number is good strategy to improve performance of baking. 0142 //! The samples number for specular IBL map with roughness of 1 (the maximum possible samples number) is expected to be defined as baking parameter. 0143 //! Samples number for other roughness values can be calculated by multiplication origin samples number by this factor. 0144 //! @param theProbability value from 0 to 1 controlling strength of samples reducing. 0145 //! Bigger values result in slower reduction to provide better quality but worse performance. 0146 //! Value of 1 doesn't affect at all so that 1 will be returned (it can be used to disable reduction strategy). 0147 //! @param theRoughness roughness value of current generated specular IBL map (from 0 to 1). 0148 //! @return factor to calculate number of samples for current specular IBL map baking. 0149 //! Be aware! It has no obligation to return 1 in case of roughness of 1. 0150 //! Be aware! It produces poor quality with small number of origin samples. In that case it is recommended to be disabled. 0151 Standard_EXPORT static Standard_ShortReal SpecIBLMapSamplesFactor (Standard_ShortReal theProbability, 0152 Standard_ShortReal theRoughness); 0153 0154 //! Dumps the content of me into the stream 0155 Standard_EXPORT void DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth = -1) const; 0156 0157 private: 0158 0159 //! Calculates geometry factor of Cook-Torrance BRDF using Smith formula. 0160 static Standard_ShortReal lutGenGeometryFactor (Standard_ShortReal theCosL, 0161 Standard_ShortReal theCosV, 0162 Standard_ShortReal theRoughness); 0163 0164 //! Generates quasi-random point from Hammersley set. 0165 //! @param theNumber number of point 0166 //! @param theCount size of Hammersley set 0167 static Graphic3d_Vec2 lutGenHammersley (unsigned int theNumber, unsigned int theCount); 0168 0169 //! Generates only cosine theta of direction in spherical coordinates system 0170 //! according to micro facet distribution function from Cook-Torrance BRDF. 0171 static Standard_ShortReal lutGenImportanceSampleCosTheta (Standard_ShortReal theHammerslayPointComponent, 0172 Standard_ShortReal theRoughness); 0173 0174 //! Generates direction using point from Hammersley set 0175 //! according to micro facet distribution function from Cook-Torrance BRDF. 0176 static Graphic3d_Vec3 lutGenImportanceSample (const Graphic3d_Vec2 &theHammerslayPoint, 0177 Standard_ShortReal theRoughness); 0178 0179 //! Generates vector using cosine of angle between up vector (normal in hemisphere) 0180 //! and desired vector. 0181 //! x component for resulting vector will be zero. 0182 static Graphic3d_Vec3 lutGenView (Standard_ShortReal theCosV); 0183 0184 //! Returns reflected vector according axis. 0185 //! @param theVector vector is needed to be reflected. 0186 //! @param theAxis axis of reflection. 0187 static Graphic3d_Vec3 lutGenReflect (const Graphic3d_Vec3 &theVector, 0188 const Graphic3d_Vec3 &theAxis); 0189 0190 private: 0191 0192 Quantity_ColorRGBA myColor; //!< albedo color with alpha component [0, 1] 0193 Standard_ShortReal myMetallic; //!< metallic coefficient of material [0, 1] 0194 Standard_ShortReal myRoughness; //!< roughness coefficient of material [0, 1] 0195 Graphic3d_Vec3 myEmission; //!< light intensity emitted by material [>= 0] 0196 Standard_ShortReal myIOR; //!< index of refraction [1, 3] 0197 0198 }; 0199 0200 #endif // _Graphic3d_PBRMaterial_HeaderFile
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |