0027816: Visualization - provide an API for overriding clipping planes list
[occt.git] / src / Graphic3d / Graphic3d_BSDF.hxx
CommitLineData
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
22//! Type of the Fresnel model.
23enum Graphic3d_FresnelModel
24{
25 Graphic3d_FM_SCHLICK = 0,
26 Graphic3d_FM_CONSTANT = 1,
27 Graphic3d_FM_CONDUCTOR = 2,
28 Graphic3d_FM_DIELECTRIC = 3
29};
30
31//! Describes Fresnel reflectance parameters.
32class Graphic3d_Fresnel
33{
34public:
35
36 //! Creates uninitialized Fresnel factor.
37 Graphic3d_Fresnel()
38 : myFresnelType (Graphic3d_FM_CONSTANT)
39 {
40 // ideal specular reflector
41 myFresnelData = Graphic3d_Vec3 (0.f, 1.f, 0.f);
42 }
43
44 //! Creates Schlick's approximation of Fresnel factor.
45 static Graphic3d_Fresnel CreateSchlick (const Graphic3d_Vec3& theSpecularColor)
46 {
47 return Graphic3d_Fresnel (Graphic3d_FM_SCHLICK, theSpecularColor);
48 }
49
50 //! Creates Fresnel factor for constant reflection.
51 static Graphic3d_Fresnel CreateConstant (const Standard_ShortReal theReflection)
52 {
53 return Graphic3d_Fresnel (Graphic3d_FM_CONSTANT, Graphic3d_Vec3 (0.f, 1.f, theReflection));
54 }
55
56 //! Creates Fresnel factor for physical-based dielectric model.
57 static Graphic3d_Fresnel CreateDielectric (Standard_ShortReal theRefractionIndex)
58 {
59 return Graphic3d_Fresnel (Graphic3d_FM_DIELECTRIC, Graphic3d_Vec3 (0.f, theRefractionIndex, 0.f));
60 }
61
62 //! Creates Fresnel factor for physical-based conductor model.
63 static Graphic3d_Fresnel CreateConductor (Standard_ShortReal theRefractionIndex,
64 Standard_ShortReal theAbsorptionIndex)
65 {
66 return Graphic3d_Fresnel (Graphic3d_FM_CONDUCTOR, Graphic3d_Vec3 (0.f, theRefractionIndex, theAbsorptionIndex));
67 }
68
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);
72
73public:
74
75 //! Returns serialized representation of Fresnel factor.
76 Standard_EXPORT Graphic3d_Vec4 Serialize() const;
77
78 //! Performs comparison of two objects describing Fresnel factor.
79 bool operator== (const Graphic3d_Fresnel& theOther) const
80 {
81 return myFresnelType == theOther.myFresnelType
82 && myFresnelData == theOther.myFresnelData;
83 }
84
85protected:
86
87 //! Creates new Fresnel reflectance factor.
88 Graphic3d_Fresnel (Graphic3d_FresnelModel theType, const Graphic3d_Vec3& theData)
89 : myFresnelType (theType),
90 myFresnelData (theData)
91 {
92 //
93 }
94
95private:
96
97 //! Type of Fresnel approximation.
98 Graphic3d_FresnelModel myFresnelType;
99
100 //! Serialized parameters of specific approximation.
101 Graphic3d_Vec3 myFresnelData;
102};
103
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).
108class Graphic3d_BSDF
109{
110public:
111
112 //! Weight of the Lambertian BRDF.
113 Graphic3d_Vec3 Kd;
114
115 //! Weight of the reflection BRDF.
116 Graphic3d_Vec3 Kr;
117
118 //! Weight of the transmission BTDF.
119 Graphic3d_Vec3 Kt;
120
121 //! Weight of the Blinn's glossy BRDF.
122 Graphic3d_Vec3 Ks;
123
124 //! Self-emitted radiance.
125 Graphic3d_Vec3 Le;
126
127 //! Parameters of Fresnel reflectance.
128 Graphic3d_Fresnel Fresnel;
129
130 //! Roughness (exponent) of Blinn's BRDF.
131 Standard_ShortReal Roughness;
132
133 //! Absorption color of transparent media.
134 Graphic3d_Vec3 AbsorptionColor;
135
136 //! Absorption intensity of transparent media.
137 Standard_ShortReal AbsorptionCoeff;
138
139public:
140
141 //! Creates BSDF describing diffuse (Lambertian) surface.
142 static Standard_EXPORT Graphic3d_BSDF CreateDiffuse (const Graphic3d_Vec3& theWeight);
143
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);
148
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);
155
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);
163
164public:
165
166 //! Creates uninitialized BSDF.
167 Graphic3d_BSDF()
168 {
169 Roughness = AbsorptionCoeff = 0.f;
170 }
171
172 //! Normalizes BSDF components.
173 Standard_EXPORT void Normalize();
174
175 //! Performs mixing of two BSDFs.
176 Graphic3d_BSDF& operator+ (const Graphic3d_BSDF& theOther)
177 {
178 Kd += theOther.Kd;
179 Kr += theOther.Kr;
180 Kt += theOther.Kt;
181 Ks += theOther.Ks;
182 Le += theOther.Le;
183
184 return *this;
185 }
186
187 //! Performs comparison of two BSDFs.
188 bool operator== (const Graphic3d_BSDF& theOther) const
189 {
190 return Kd == theOther.Kd
191 && Kr == theOther.Kr
192 && Kt == theOther.Kt
193 && Ks == theOther.Ks
194 && Le == theOther.Le
195 && Fresnel == theOther.Fresnel
196 && Roughness == theOther.Roughness
197 && AbsorptionCoeff == theOther.AbsorptionCoeff
198 && AbsorptionColor == theOther.AbsorptionColor;
199 }
200
201};
202
203#endif // _Graphic3d_BSDF_HeaderFile