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;
87 //! Creates new Fresnel reflectance factor.
88 Graphic3d_Fresnel (Graphic3d_FresnelModel theType, const Graphic3d_Vec3& theData)
89 : myFresnelType (theType),
90 myFresnelData (theData)
97 //! Type of Fresnel approximation.
98 Graphic3d_FresnelModel myFresnelType;
100 //! Serialized parameters of specific approximation.
101 Graphic3d_Vec3 myFresnelData;
104 //! Describes material's BSDF (Bidirectional Scattering Distribution Function) used
105 //! for physically-based rendering (in path tracing engine). BSDF is represented as
106 //! weighted mixture of basic BRDFs/BTDFs (Bidirectional Reflectance (Transmittance)
107 //! Distribution Functions).
112 //! Weight of the Lambertian BRDF.
115 //! Weight of the reflection BRDF.
118 //! Weight of the transmission BTDF.
121 //! Weight of the Blinn's glossy BRDF.
124 //! Self-emitted radiance.
127 //! Parameters of Fresnel reflectance.
128 Graphic3d_Fresnel Fresnel;
130 //! Roughness (exponent) of Blinn's BRDF.
131 Standard_ShortReal Roughness;
133 //! Absorption color of transparent media.
134 Graphic3d_Vec3 AbsorptionColor;
136 //! Absorption intensity of transparent media.
137 Standard_ShortReal AbsorptionCoeff;
141 //! Creates BSDF describing diffuse (Lambertian) surface.
142 static Standard_EXPORT Graphic3d_BSDF CreateDiffuse (const Graphic3d_Vec3& theWeight);
144 //! Creates BSDF describing polished metallic-like surface.
145 static Standard_EXPORT Graphic3d_BSDF CreateMetallic (const Graphic3d_Vec3& theWeight,
146 const Graphic3d_Fresnel& theFresnel,
147 const Standard_ShortReal theRoughness);
149 //! Creates BSDF describing transparent object.
150 //! Transparent BSDF models simple transparency without
151 //! refraction (the ray passes straight through the surface).
152 static Standard_EXPORT Graphic3d_BSDF CreateTransparent (const Graphic3d_Vec3& theWeight,
153 const Graphic3d_Vec3& theAbsorptionColor,
154 const Standard_ShortReal theAbsorptionCoeff);
156 //! Creates BSDF describing glass-like object.
157 //! Glass-like BSDF mixes refraction and reflection effects at
158 //! grazing angles using physically-based Fresnel dielectric model.
159 static Standard_EXPORT Graphic3d_BSDF CreateGlass (const Graphic3d_Vec3& theWeight,
160 const Graphic3d_Vec3& theAbsorptionColor,
161 const Standard_ShortReal theAbsorptionCoeff,
162 const Standard_ShortReal theRefractionIndex);
166 //! Creates uninitialized BSDF.
169 Roughness = AbsorptionCoeff = 0.f;
172 //! Normalizes BSDF components.
173 Standard_EXPORT void Normalize();
175 //! Performs mixing of two BSDFs.
176 Graphic3d_BSDF& operator+ (const Graphic3d_BSDF& theOther)
187 //! Performs comparison of two BSDFs.
188 bool operator== (const Graphic3d_BSDF& theOther) const
190 return Kd == theOther.Kd
195 && Fresnel == theOther.Fresnel
196 && Roughness == theOther.Roughness
197 && AbsorptionCoeff == theOther.AbsorptionCoeff
198 && AbsorptionColor == theOther.AbsorptionColor;
203 #endif // _Graphic3d_BSDF_HeaderFile