Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:03:47

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