189f85a3 |
1 | // Created on: 2015-01-15 |
2 | // Created by: Danila ULYANOV |
3 | // Copyright (c) 2014 OPEN CASCADE SAS |
4 | // |
5 | // This file is part of Open CASCADE Technology software library. |
6 | // |
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. |
12 | // |
13 | // Alternatively, this file may be used under the terms of Open CASCADE |
14 | // commercial license or contractual agreement. |
15 | |
16 | #ifndef _Graphic3d_BSDF_HeaderFile |
17 | #define _Graphic3d_BSDF_HeaderFile |
18 | |
19 | #include <Graphic3d_Vec3.hxx> |
20 | #include <Graphic3d_Vec4.hxx> |
21 | |
67312b79 |
22 | class Graphic3d_PBRMaterial; |
23 | |
189f85a3 |
24 | //! Type of the Fresnel model. |
25 | enum Graphic3d_FresnelModel |
26 | { |
27 | Graphic3d_FM_SCHLICK = 0, |
28 | Graphic3d_FM_CONSTANT = 1, |
29 | Graphic3d_FM_CONDUCTOR = 2, |
30 | Graphic3d_FM_DIELECTRIC = 3 |
31 | }; |
32 | |
33 | //! Describes Fresnel reflectance parameters. |
34 | class Graphic3d_Fresnel |
35 | { |
36 | public: |
37 | |
38 | //! Creates uninitialized Fresnel factor. |
05aa616d |
39 | Graphic3d_Fresnel() : myFresnelType (Graphic3d_FM_CONSTANT) |
189f85a3 |
40 | { |
41 | // ideal specular reflector |
42 | myFresnelData = Graphic3d_Vec3 (0.f, 1.f, 0.f); |
43 | } |
44 | |
45 | //! Creates Schlick's approximation of Fresnel factor. |
46 | static Graphic3d_Fresnel CreateSchlick (const Graphic3d_Vec3& theSpecularColor) |
47 | { |
48 | return Graphic3d_Fresnel (Graphic3d_FM_SCHLICK, theSpecularColor); |
49 | } |
50 | |
51 | //! Creates Fresnel factor for constant reflection. |
52 | static Graphic3d_Fresnel CreateConstant (const Standard_ShortReal theReflection) |
53 | { |
54 | return Graphic3d_Fresnel (Graphic3d_FM_CONSTANT, Graphic3d_Vec3 (0.f, 1.f, theReflection)); |
55 | } |
56 | |
57 | //! Creates Fresnel factor for physical-based dielectric model. |
58 | static Graphic3d_Fresnel CreateDielectric (Standard_ShortReal theRefractionIndex) |
59 | { |
60 | return Graphic3d_Fresnel (Graphic3d_FM_DIELECTRIC, Graphic3d_Vec3 (0.f, theRefractionIndex, 0.f)); |
61 | } |
62 | |
63 | //! Creates Fresnel factor for physical-based conductor model. |
64 | static Graphic3d_Fresnel CreateConductor (Standard_ShortReal theRefractionIndex, |
65 | Standard_ShortReal theAbsorptionIndex) |
66 | { |
67 | return Graphic3d_Fresnel (Graphic3d_FM_CONDUCTOR, Graphic3d_Vec3 (0.f, theRefractionIndex, theAbsorptionIndex)); |
68 | } |
69 | |
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); |
73 | |
74 | public: |
75 | |
76 | //! Returns serialized representation of Fresnel factor. |
77 | Standard_EXPORT Graphic3d_Vec4 Serialize() const; |
78 | |
79 | //! Performs comparison of two objects describing Fresnel factor. |
80 | bool operator== (const Graphic3d_Fresnel& theOther) const |
81 | { |
82 | return myFresnelType == theOther.myFresnelType |
83 | && myFresnelData == theOther.myFresnelData; |
84 | } |
85 | |
6e728f3b |
86 | //! Returns type of Fresnel. |
87 | Graphic3d_FresnelModel FresnelType() const |
88 | { |
89 | return myFresnelType; |
90 | } |
91 | |
189f85a3 |
92 | protected: |
93 | |
94 | //! Creates new Fresnel reflectance factor. |
95 | Graphic3d_Fresnel (Graphic3d_FresnelModel theType, const Graphic3d_Vec3& theData) |
96 | : myFresnelType (theType), |
97 | myFresnelData (theData) |
98 | { |
99 | // |
100 | } |
101 | |
102 | private: |
103 | |
104 | //! Type of Fresnel approximation. |
105 | Graphic3d_FresnelModel myFresnelType; |
106 | |
107 | //! Serialized parameters of specific approximation. |
108 | Graphic3d_Vec3 myFresnelData; |
109 | }; |
110 | |
111 | //! Describes material's BSDF (Bidirectional Scattering Distribution Function) used |
112 | //! for physically-based rendering (in path tracing engine). BSDF is represented as |
113 | //! weighted mixture of basic BRDFs/BTDFs (Bidirectional Reflectance (Transmittance) |
114 | //! Distribution Functions). |
05aa616d |
115 | //! |
116 | //! NOTE: OCCT uses two-layer material model. We have base diffuse, glossy, or transmissive |
117 | //! layer, covered by one glossy/specular coat. In the current model, the layers themselves |
118 | //! have no thickness; they can simply reflect light or transmits it to the layer under it. |
119 | //! We use actual BRDF model only for direct reflection by the coat layer. For transmission |
120 | //! through this layer, we approximate it as a flat specular surface. |
189f85a3 |
121 | class Graphic3d_BSDF |
122 | { |
123 | public: |
124 | |
05aa616d |
125 | //! Weight of coat specular/glossy BRDF. |
126 | Graphic3d_Vec4 Kc; |
127 | |
128 | //! Weight of base diffuse BRDF. |
189f85a3 |
129 | Graphic3d_Vec3 Kd; |
130 | |
05aa616d |
131 | //! Weight of base specular/glossy BRDF. |
132 | Graphic3d_Vec4 Ks; |
189f85a3 |
133 | |
05aa616d |
134 | //! Weight of base specular/glossy BTDF. |
189f85a3 |
135 | Graphic3d_Vec3 Kt; |
136 | |
05aa616d |
137 | //! Radiance emitted by the surface. |
189f85a3 |
138 | Graphic3d_Vec3 Le; |
139 | |
05aa616d |
140 | //! Volume scattering color/density. |
141 | Graphic3d_Vec4 Absorption; |
189f85a3 |
142 | |
05aa616d |
143 | //! Parameters of Fresnel reflectance of coat layer. |
144 | Graphic3d_Fresnel FresnelCoat; |
189f85a3 |
145 | |
05aa616d |
146 | //! Parameters of Fresnel reflectance of base layer. |
147 | Graphic3d_Fresnel FresnelBase; |
189f85a3 |
148 | |
149 | public: |
150 | |
151 | //! Creates BSDF describing diffuse (Lambertian) surface. |
152 | static Standard_EXPORT Graphic3d_BSDF CreateDiffuse (const Graphic3d_Vec3& theWeight); |
153 | |
154 | //! Creates BSDF describing polished metallic-like surface. |
155 | static Standard_EXPORT Graphic3d_BSDF CreateMetallic (const Graphic3d_Vec3& theWeight, |
156 | const Graphic3d_Fresnel& theFresnel, |
157 | const Standard_ShortReal theRoughness); |
158 | |
159 | //! Creates BSDF describing transparent object. |
160 | //! Transparent BSDF models simple transparency without |
161 | //! refraction (the ray passes straight through the surface). |
162 | static Standard_EXPORT Graphic3d_BSDF CreateTransparent (const Graphic3d_Vec3& theWeight, |
163 | const Graphic3d_Vec3& theAbsorptionColor, |
164 | const Standard_ShortReal theAbsorptionCoeff); |
165 | |
166 | //! Creates BSDF describing glass-like object. |
167 | //! Glass-like BSDF mixes refraction and reflection effects at |
168 | //! grazing angles using physically-based Fresnel dielectric model. |
169 | static Standard_EXPORT Graphic3d_BSDF CreateGlass (const Graphic3d_Vec3& theWeight, |
170 | const Graphic3d_Vec3& theAbsorptionColor, |
171 | const Standard_ShortReal theAbsorptionCoeff, |
172 | const Standard_ShortReal theRefractionIndex); |
173 | |
67312b79 |
174 | //! Creates BSDF from PBR metallic-roughness material. |
175 | static Standard_EXPORT Graphic3d_BSDF CreateMetallicRoughness (const Graphic3d_PBRMaterial& thePbr); |
176 | |
189f85a3 |
177 | public: |
178 | |
179 | //! Creates uninitialized BSDF. |
05aa616d |
180 | Standard_EXPORT Graphic3d_BSDF(); |
189f85a3 |
181 | |
182 | //! Normalizes BSDF components. |
183 | Standard_EXPORT void Normalize(); |
184 | |
189f85a3 |
185 | //! Performs comparison of two BSDFs. |
05aa616d |
186 | Standard_EXPORT bool operator== (const Graphic3d_BSDF& theOther) const; |
189f85a3 |
187 | |
188 | }; |
189 | |
190 | #endif // _Graphic3d_BSDF_HeaderFile |