1 // Created on: 2015-01-15
2 // Created by: Danila ULYANOV
3 // Copyright (c) 2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #ifndef _Graphic3d_BSDF_HeaderFile
17 #define _Graphic3d_BSDF_HeaderFile
19 #include <Graphic3d_Vec3.hxx>
20 #include <Graphic3d_Vec4.hxx>
22 class Graphic3d_PBRMaterial;
24 //! Type of the Fresnel model.
25 enum Graphic3d_FresnelModel
27 Graphic3d_FM_SCHLICK = 0,
28 Graphic3d_FM_CONSTANT = 1,
29 Graphic3d_FM_CONDUCTOR = 2,
30 Graphic3d_FM_DIELECTRIC = 3
33 //! Describes Fresnel reflectance parameters.
34 class Graphic3d_Fresnel
38 //! Creates uninitialized Fresnel factor.
39 Graphic3d_Fresnel() : myFresnelType (Graphic3d_FM_CONSTANT)
41 // ideal specular reflector
42 myFresnelData = Graphic3d_Vec3 (0.f, 1.f, 0.f);
45 //! Creates Schlick's approximation of Fresnel factor.
46 static Graphic3d_Fresnel CreateSchlick (const Graphic3d_Vec3& theSpecularColor)
48 return Graphic3d_Fresnel (Graphic3d_FM_SCHLICK, theSpecularColor);
51 //! Creates Fresnel factor for constant reflection.
52 static Graphic3d_Fresnel CreateConstant (const Standard_ShortReal theReflection)
54 return Graphic3d_Fresnel (Graphic3d_FM_CONSTANT, Graphic3d_Vec3 (0.f, 1.f, theReflection));
57 //! Creates Fresnel factor for physical-based dielectric model.
58 static Graphic3d_Fresnel CreateDielectric (Standard_ShortReal theRefractionIndex)
60 return Graphic3d_Fresnel (Graphic3d_FM_DIELECTRIC, Graphic3d_Vec3 (0.f, theRefractionIndex, 0.f));
63 //! Creates Fresnel factor for physical-based conductor model.
64 static Graphic3d_Fresnel CreateConductor (Standard_ShortReal theRefractionIndex,
65 Standard_ShortReal theAbsorptionIndex)
67 return Graphic3d_Fresnel (Graphic3d_FM_CONDUCTOR, Graphic3d_Vec3 (0.f, theRefractionIndex, theAbsorptionIndex));
70 //! Creates Fresnel factor for physical-based conductor model (spectral version).
71 Standard_EXPORT static Graphic3d_Fresnel CreateConductor (const Graphic3d_Vec3& theRefractionIndex,
72 const Graphic3d_Vec3& theAbsorptionIndex);
76 //! Returns serialized representation of Fresnel factor.
77 Standard_EXPORT Graphic3d_Vec4 Serialize() const;
79 //! Performs comparison of two objects describing Fresnel factor.
80 bool operator== (const Graphic3d_Fresnel& theOther) const
82 return myFresnelType == theOther.myFresnelType
83 && myFresnelData == theOther.myFresnelData;
86 //! Returns type of Fresnel.
87 Graphic3d_FresnelModel FresnelType() const
92 //! Dumps the content of me into the stream
93 Standard_EXPORT void DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth = -1) const;
97 //! Creates new Fresnel reflectance factor.
98 Graphic3d_Fresnel (Graphic3d_FresnelModel theType, const Graphic3d_Vec3& theData)
99 : myFresnelType (theType),
100 myFresnelData (theData)
107 //! Type of Fresnel approximation.
108 Graphic3d_FresnelModel myFresnelType;
110 //! Serialized parameters of specific approximation.
111 Graphic3d_Vec3 myFresnelData;
114 //! Describes material's BSDF (Bidirectional Scattering Distribution Function) used
115 //! for physically-based rendering (in path tracing engine). BSDF is represented as
116 //! weighted mixture of basic BRDFs/BTDFs (Bidirectional Reflectance (Transmittance)
117 //! Distribution Functions).
119 //! NOTE: OCCT uses two-layer material model. We have base diffuse, glossy, or transmissive
120 //! layer, covered by one glossy/specular coat. In the current model, the layers themselves
121 //! have no thickness; they can simply reflect light or transmits it to the layer under it.
122 //! We use actual BRDF model only for direct reflection by the coat layer. For transmission
123 //! through this layer, we approximate it as a flat specular surface.
128 //! Weight of coat specular/glossy BRDF.
131 //! Weight of base diffuse BRDF.
134 //! Weight of base specular/glossy BRDF.
137 //! Weight of base specular/glossy BTDF.
140 //! Radiance emitted by the surface.
143 //! Volume scattering color/density.
144 Graphic3d_Vec4 Absorption;
146 //! Parameters of Fresnel reflectance of coat layer.
147 Graphic3d_Fresnel FresnelCoat;
149 //! Parameters of Fresnel reflectance of base layer.
150 Graphic3d_Fresnel FresnelBase;
154 //! Creates BSDF describing diffuse (Lambertian) surface.
155 static Standard_EXPORT Graphic3d_BSDF CreateDiffuse (const Graphic3d_Vec3& theWeight);
157 //! Creates BSDF describing polished metallic-like surface.
158 static Standard_EXPORT Graphic3d_BSDF CreateMetallic (const Graphic3d_Vec3& theWeight,
159 const Graphic3d_Fresnel& theFresnel,
160 const Standard_ShortReal theRoughness);
162 //! Creates BSDF describing transparent object.
163 //! Transparent BSDF models simple transparency without
164 //! refraction (the ray passes straight through the surface).
165 static Standard_EXPORT Graphic3d_BSDF CreateTransparent (const Graphic3d_Vec3& theWeight,
166 const Graphic3d_Vec3& theAbsorptionColor,
167 const Standard_ShortReal theAbsorptionCoeff);
169 //! Creates BSDF describing glass-like object.
170 //! Glass-like BSDF mixes refraction and reflection effects at
171 //! grazing angles using physically-based Fresnel dielectric model.
172 static Standard_EXPORT Graphic3d_BSDF CreateGlass (const Graphic3d_Vec3& theWeight,
173 const Graphic3d_Vec3& theAbsorptionColor,
174 const Standard_ShortReal theAbsorptionCoeff,
175 const Standard_ShortReal theRefractionIndex);
177 //! Creates BSDF from PBR metallic-roughness material.
178 static Standard_EXPORT Graphic3d_BSDF CreateMetallicRoughness (const Graphic3d_PBRMaterial& thePbr);
182 //! Creates uninitialized BSDF.
183 Standard_EXPORT Graphic3d_BSDF();
185 //! Normalizes BSDF components.
186 Standard_EXPORT void Normalize();
188 //! Performs comparison of two BSDFs.
189 Standard_EXPORT bool operator== (const Graphic3d_BSDF& theOther) const;
191 //! Dumps the content of me into the stream
192 Standard_EXPORT void DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth = -1) const;
196 #endif // _Graphic3d_BSDF_HeaderFile