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 //! Type of the Fresnel model.
23 enum Graphic3d_FresnelModel
25 Graphic3d_FM_SCHLICK = 0,
26 Graphic3d_FM_CONSTANT = 1,
27 Graphic3d_FM_CONDUCTOR = 2,
28 Graphic3d_FM_DIELECTRIC = 3
31 //! Describes Fresnel reflectance parameters.
32 class Graphic3d_Fresnel
36 //! Creates uninitialized Fresnel factor.
38 : myFresnelType (Graphic3d_FM_CONSTANT)
40 // ideal specular reflector
41 myFresnelData = Graphic3d_Vec3 (0.f, 1.f, 0.f);
44 //! Creates Schlick's approximation of Fresnel factor.
45 static Graphic3d_Fresnel CreateSchlick (const Graphic3d_Vec3& theSpecularColor)
47 return Graphic3d_Fresnel (Graphic3d_FM_SCHLICK, theSpecularColor);
50 //! Creates Fresnel factor for constant reflection.
51 static Graphic3d_Fresnel CreateConstant (const Standard_ShortReal theReflection)
53 return Graphic3d_Fresnel (Graphic3d_FM_CONSTANT, Graphic3d_Vec3 (0.f, 1.f, theReflection));
56 //! Creates Fresnel factor for physical-based dielectric model.
57 static Graphic3d_Fresnel CreateDielectric (Standard_ShortReal theRefractionIndex)
59 return Graphic3d_Fresnel (Graphic3d_FM_DIELECTRIC, Graphic3d_Vec3 (0.f, theRefractionIndex, 0.f));
62 //! Creates Fresnel factor for physical-based conductor model.
63 static Graphic3d_Fresnel CreateConductor (Standard_ShortReal theRefractionIndex,
64 Standard_ShortReal theAbsorptionIndex)
66 return Graphic3d_Fresnel (Graphic3d_FM_CONDUCTOR, Graphic3d_Vec3 (0.f, theRefractionIndex, theAbsorptionIndex));
69 //! Creates Fresnel factor for physical-based conductor model (spectral version).
70 Standard_EXPORT static Graphic3d_Fresnel CreateConductor (const Graphic3d_Vec3& theRefractionIndex,
71 const Graphic3d_Vec3& theAbsorptionIndex);
75 //! Returns serialized representation of Fresnel factor.
76 Standard_EXPORT Graphic3d_Vec4 Serialize() const;
78 //! Performs comparison of two objects describing Fresnel factor.
79 bool operator== (const Graphic3d_Fresnel& theOther) const
81 return myFresnelType == theOther.myFresnelType
82 && myFresnelData == theOther.myFresnelData;
85 //! Returns type of Fresnel.
86 Graphic3d_FresnelModel FresnelType() const
93 //! Creates new Fresnel reflectance factor.
94 Graphic3d_Fresnel (Graphic3d_FresnelModel theType, const Graphic3d_Vec3& theData)
95 : myFresnelType (theType),
96 myFresnelData (theData)
103 //! Type of Fresnel approximation.
104 Graphic3d_FresnelModel myFresnelType;
106 //! Serialized parameters of specific approximation.
107 Graphic3d_Vec3 myFresnelData;
110 //! Describes material's BSDF (Bidirectional Scattering Distribution Function) used
111 //! for physically-based rendering (in path tracing engine). BSDF is represented as
112 //! weighted mixture of basic BRDFs/BTDFs (Bidirectional Reflectance (Transmittance)
113 //! Distribution Functions).
118 //! Weight of the Lambertian BRDF.
121 //! Weight of the reflection BRDF.
124 //! Weight of the transmission BTDF.
127 //! Weight of the Blinn's glossy BRDF.
130 //! Self-emitted radiance.
133 //! Parameters of Fresnel reflectance.
134 Graphic3d_Fresnel Fresnel;
136 //! Roughness (exponent) of Blinn's BRDF.
137 Standard_ShortReal Roughness;
139 //! Absorption color of transparent media.
140 Graphic3d_Vec3 AbsorptionColor;
142 //! Absorption intensity of transparent media.
143 Standard_ShortReal AbsorptionCoeff;
147 //! Creates BSDF describing diffuse (Lambertian) surface.
148 static Standard_EXPORT Graphic3d_BSDF CreateDiffuse (const Graphic3d_Vec3& theWeight);
150 //! Creates BSDF describing polished metallic-like surface.
151 static Standard_EXPORT Graphic3d_BSDF CreateMetallic (const Graphic3d_Vec3& theWeight,
152 const Graphic3d_Fresnel& theFresnel,
153 const Standard_ShortReal theRoughness);
155 //! Creates BSDF describing transparent object.
156 //! Transparent BSDF models simple transparency without
157 //! refraction (the ray passes straight through the surface).
158 static Standard_EXPORT Graphic3d_BSDF CreateTransparent (const Graphic3d_Vec3& theWeight,
159 const Graphic3d_Vec3& theAbsorptionColor,
160 const Standard_ShortReal theAbsorptionCoeff);
162 //! Creates BSDF describing glass-like object.
163 //! Glass-like BSDF mixes refraction and reflection effects at
164 //! grazing angles using physically-based Fresnel dielectric model.
165 static Standard_EXPORT Graphic3d_BSDF CreateGlass (const Graphic3d_Vec3& theWeight,
166 const Graphic3d_Vec3& theAbsorptionColor,
167 const Standard_ShortReal theAbsorptionCoeff,
168 const Standard_ShortReal theRefractionIndex);
172 //! Creates uninitialized BSDF.
173 Graphic3d_BSDF() : Roughness (1.f), AbsorptionCoeff (0.f)
175 Fresnel = Graphic3d_Fresnel::CreateConstant (1.f);
178 //! Normalizes BSDF components.
179 Standard_EXPORT void Normalize();
181 //! Performs mixing of two BSDFs.
182 Graphic3d_BSDF& operator+ (const Graphic3d_BSDF& theOther)
193 //! Performs comparison of two BSDFs.
194 bool operator== (const Graphic3d_BSDF& theOther) const
196 return Kd == theOther.Kd
201 && Fresnel == theOther.Fresnel
202 && Roughness == theOther.Roughness
203 && AbsorptionCoeff == theOther.AbsorptionCoeff
204 && AbsorptionColor == theOther.AbsorptionColor;
209 #endif // _Graphic3d_BSDF_HeaderFile