Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-10-24 09:14:00

0001 // Created on: 2015-01-15
0002 // Created by: Danila ULYANOV
0003 // Copyright (c) 2014 OPEN CASCADE SAS
0004 //
0005 // This file is part of Open CASCADE Technology software library.
0006 //
0007 // This library is free software; you can redistribute it and/or modify it under
0008 // the terms of the GNU Lesser General Public License version 2.1 as published
0009 // by the Free Software Foundation, with special exception defined in the file
0010 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0011 // distribution for complete text of the license and disclaimer of any warranty.
0012 //
0013 // Alternatively, this file may be used under the terms of Open CASCADE
0014 // commercial license or contractual agreement.
0015 
0016 #ifndef _Graphic3d_BSDF_HeaderFile
0017 #define _Graphic3d_BSDF_HeaderFile
0018 
0019 #include <NCollection_Vec3.hxx>
0020 #include <Standard_TypeDef.hxx>
0021 #include <NCollection_Vec4.hxx>
0022 
0023 class Graphic3d_PBRMaterial;
0024 
0025 //! Type of the Fresnel model.
0026 enum Graphic3d_FresnelModel
0027 {
0028   Graphic3d_FM_SCHLICK    = 0,
0029   Graphic3d_FM_CONSTANT   = 1,
0030   Graphic3d_FM_CONDUCTOR  = 2,
0031   Graphic3d_FM_DIELECTRIC = 3
0032 };
0033 
0034 //! Describes Fresnel reflectance parameters.
0035 class Graphic3d_Fresnel
0036 {
0037 public:
0038   //! Creates uninitialized Fresnel factor.
0039   Graphic3d_Fresnel()
0040       : myFresnelType(Graphic3d_FM_CONSTANT)
0041   {
0042     // ideal specular reflector
0043     myFresnelData = NCollection_Vec3<float>(0.f, 1.f, 0.f);
0044   }
0045 
0046   //! Creates Schlick's approximation of Fresnel factor.
0047   static Graphic3d_Fresnel CreateSchlick(const NCollection_Vec3<float>& theSpecularColor)
0048   {
0049     return Graphic3d_Fresnel(Graphic3d_FM_SCHLICK, theSpecularColor);
0050   }
0051 
0052   //! Creates Fresnel factor for constant reflection.
0053   static Graphic3d_Fresnel CreateConstant(const float theReflection)
0054   {
0055     return Graphic3d_Fresnel(Graphic3d_FM_CONSTANT,
0056                              NCollection_Vec3<float>(0.f, 1.f, theReflection));
0057   }
0058 
0059   //! Creates Fresnel factor for physical-based dielectric model.
0060   static Graphic3d_Fresnel CreateDielectric(float theRefractionIndex)
0061   {
0062     return Graphic3d_Fresnel(Graphic3d_FM_DIELECTRIC,
0063                              NCollection_Vec3<float>(0.f, theRefractionIndex, 0.f));
0064   }
0065 
0066   //! Creates Fresnel factor for physical-based conductor model.
0067   static Graphic3d_Fresnel CreateConductor(float theRefractionIndex, float theAbsorptionIndex)
0068   {
0069     return Graphic3d_Fresnel(Graphic3d_FM_CONDUCTOR,
0070                              NCollection_Vec3<float>(0.f, theRefractionIndex, theAbsorptionIndex));
0071   }
0072 
0073   //! Creates Fresnel factor for physical-based conductor model (spectral version).
0074   Standard_EXPORT static Graphic3d_Fresnel CreateConductor(
0075     const NCollection_Vec3<float>& theRefractionIndex,
0076     const NCollection_Vec3<float>& theAbsorptionIndex);
0077 
0078 public:
0079   //! Returns serialized representation of Fresnel factor.
0080   Standard_EXPORT NCollection_Vec4<float> Serialize() const;
0081 
0082   //! Performs comparison of two objects describing Fresnel factor.
0083   bool operator==(const Graphic3d_Fresnel& theOther) const
0084   {
0085     return myFresnelType == theOther.myFresnelType && myFresnelData == theOther.myFresnelData;
0086   }
0087 
0088   //! Returns type of Fresnel.
0089   Graphic3d_FresnelModel FresnelType() const { return myFresnelType; }
0090 
0091   //! Dumps the content of me into the stream
0092   Standard_EXPORT void DumpJson(Standard_OStream& theOStream, int theDepth = -1) const;
0093 
0094 protected:
0095   //! Creates new Fresnel reflectance factor.
0096   Graphic3d_Fresnel(Graphic3d_FresnelModel theType, const NCollection_Vec3<float>& theData)
0097       : myFresnelType(theType),
0098         myFresnelData(theData)
0099   {
0100     //
0101   }
0102 
0103 private:
0104   //! Type of Fresnel approximation.
0105   Graphic3d_FresnelModel myFresnelType;
0106 
0107   //! Serialized parameters of specific approximation.
0108   NCollection_Vec3<float> myFresnelData;
0109 };
0110 
0111 //! Describes material's BSDF (Bidirectional Scattering Distribution Function) used
0112 //! for physically-based rendering (in path tracing engine). BSDF is represented as
0113 //! weighted mixture of basic BRDFs/BTDFs (Bidirectional Reflectance (Transmittance)
0114 //! Distribution Functions).
0115 //!
0116 //! NOTE: OCCT uses two-layer material model. We have base diffuse, glossy, or transmissive
0117 //! layer, covered by one glossy/specular coat. In the current model, the layers themselves
0118 //! have no thickness; they can simply reflect light or transmits it to the layer under it.
0119 //! We use actual BRDF model only for direct reflection by the coat layer. For transmission
0120 //! through this layer, we approximate it as a flat specular surface.
0121 class Graphic3d_BSDF
0122 {
0123 public:
0124   //! Weight of coat specular/glossy BRDF.
0125   NCollection_Vec4<float> Kc;
0126 
0127   //! Weight of base diffuse BRDF.
0128   NCollection_Vec3<float> Kd;
0129 
0130   //! Weight of base specular/glossy BRDF.
0131   NCollection_Vec4<float> Ks;
0132 
0133   //! Weight of base specular/glossy BTDF.
0134   NCollection_Vec3<float> Kt;
0135 
0136   //! Radiance emitted by the surface.
0137   NCollection_Vec3<float> Le;
0138 
0139   //! Volume scattering color/density.
0140   NCollection_Vec4<float> Absorption;
0141 
0142   //! Parameters of Fresnel reflectance of coat layer.
0143   Graphic3d_Fresnel FresnelCoat;
0144 
0145   //! Parameters of Fresnel reflectance of base layer.
0146   Graphic3d_Fresnel FresnelBase;
0147 
0148 public:
0149   //! Creates BSDF describing diffuse (Lambertian) surface.
0150   static Standard_EXPORT Graphic3d_BSDF CreateDiffuse(const NCollection_Vec3<float>& theWeight);
0151 
0152   //! Creates BSDF describing polished metallic-like surface.
0153   static Standard_EXPORT Graphic3d_BSDF CreateMetallic(const NCollection_Vec3<float>& theWeight,
0154                                                        const Graphic3d_Fresnel&       theFresnel,
0155                                                        const float                    theRoughness);
0156 
0157   //! Creates BSDF describing transparent object.
0158   //! Transparent BSDF models simple transparency without
0159   //! refraction (the ray passes straight through the surface).
0160   static Standard_EXPORT Graphic3d_BSDF
0161     CreateTransparent(const NCollection_Vec3<float>& theWeight,
0162                       const NCollection_Vec3<float>& theAbsorptionColor,
0163                       const float                    theAbsorptionCoeff);
0164 
0165   //! Creates BSDF describing glass-like object.
0166   //! Glass-like BSDF mixes refraction and reflection effects at
0167   //! grazing angles using physically-based Fresnel dielectric model.
0168   static Standard_EXPORT Graphic3d_BSDF
0169     CreateGlass(const NCollection_Vec3<float>& theWeight,
0170                 const NCollection_Vec3<float>& theAbsorptionColor,
0171                 const float                    theAbsorptionCoeff,
0172                 const float                    theRefractionIndex);
0173 
0174   //! Creates BSDF from PBR metallic-roughness material.
0175   static Standard_EXPORT Graphic3d_BSDF
0176     CreateMetallicRoughness(const Graphic3d_PBRMaterial& thePbr);
0177 
0178 public:
0179   //! Creates uninitialized BSDF.
0180   Standard_EXPORT Graphic3d_BSDF();
0181 
0182   //! Normalizes BSDF components.
0183   Standard_EXPORT void Normalize();
0184 
0185   //! Performs comparison of two BSDFs.
0186   Standard_EXPORT bool operator==(const Graphic3d_BSDF& theOther) const;
0187 
0188   //! Dumps the content of me into the stream
0189   Standard_EXPORT void DumpJson(Standard_OStream& theOStream, int theDepth = -1) const;
0190 };
0191 
0192 #endif // _Graphic3d_BSDF_HeaderFile