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