1 // Created on: 2015-01-19
2 // Created by: Denis BOGOLEPOV
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 #include <Graphic3d_BSDF.hxx>
20 // =======================================================================
21 // function : Serialize
23 // =======================================================================
24 Graphic3d_Vec4 Graphic3d_Fresnel::Serialize() const
26 Graphic3d_Vec4 aData = Graphic3d_Vec4 (myFresnelData, 0.f);
28 if (myFresnelType != Graphic3d_FM_SCHLICK)
30 aData.x() = -static_cast<Standard_ShortReal> (myFresnelType);
36 // =======================================================================
37 // function : fresnelNormal
39 // =======================================================================
40 inline Standard_ShortReal fresnelNormal (Standard_ShortReal theN,
41 Standard_ShortReal theK)
43 return ((theN - 1.f) * (theN - 1.f) + theK * theK) /
44 ((theN + 1.f) * (theN + 1.f) + theK * theK);
47 // =======================================================================
48 // function : CreateConductor
50 // =======================================================================
51 Graphic3d_Fresnel Graphic3d_Fresnel::CreateConductor (const Graphic3d_Vec3& theRefractionIndex,
52 const Graphic3d_Vec3& theAbsorptionIndex)
54 return Graphic3d_Fresnel (Graphic3d_FM_SCHLICK,
55 Graphic3d_Vec3 (fresnelNormal (theRefractionIndex.x(), theAbsorptionIndex.x()),
56 fresnelNormal (theRefractionIndex.y(), theAbsorptionIndex.y()),
57 fresnelNormal (theRefractionIndex.z(), theAbsorptionIndex.z())));
60 // =======================================================================
61 // function : Normalize
63 // =======================================================================
64 void Graphic3d_BSDF::Normalize()
66 Standard_ShortReal aMax = std::max (Kd.x() + Ks.x() + Kr.x() + Kt.x(),
67 std::max (Kd.y() + Ks.y() + Kr.y() + Kt.y(),
68 Kd.z() + Ks.z() + Kr.z() + Kt.z()));
79 // =======================================================================
80 // function : CreateDiffuse
82 // =======================================================================
83 Graphic3d_BSDF Graphic3d_BSDF::CreateDiffuse (const Graphic3d_Vec3& theWeight)
92 // =======================================================================
93 // function : CreateMetallic
95 // =======================================================================
96 Graphic3d_BSDF Graphic3d_BSDF::CreateMetallic (const Graphic3d_Vec3& theWeight,
97 const Graphic3d_Fresnel& theFresnel,
98 const Standard_ShortReal theRoughness)
100 Graphic3d_BSDF aBSDF;
102 aBSDF.Roughness = theRoughness;
104 // Selecting between specular and glossy
105 // BRDF depending on the given roughness
106 if (aBSDF.Roughness > 0.f)
108 aBSDF.Ks = theWeight;
112 aBSDF.Kr = theWeight;
115 aBSDF.Fresnel = theFresnel;
120 // =======================================================================
121 // function : CreateTransparent
123 // =======================================================================
124 Graphic3d_BSDF Graphic3d_BSDF::CreateTransparent (const Graphic3d_Vec3& theWeight,
125 const Graphic3d_Vec3& theAbsorptionColor,
126 const Standard_ShortReal theAbsorptionCoeff)
128 Graphic3d_BSDF aBSDF;
130 aBSDF.Kt = theWeight;
132 aBSDF.AbsorptionColor = theAbsorptionColor;
133 aBSDF.AbsorptionCoeff = theAbsorptionCoeff;
135 aBSDF.Fresnel = Graphic3d_Fresnel::CreateConstant (0.f);
140 // =======================================================================
141 // function : CreateGlass
143 // =======================================================================
144 Graphic3d_BSDF Graphic3d_BSDF::CreateGlass (const Graphic3d_Vec3& theWeight,
145 const Graphic3d_Vec3& theAbsorptionColor,
146 const Standard_ShortReal theAbsorptionCoeff,
147 const Standard_ShortReal theRefractionIndex)
149 Graphic3d_BSDF aBSDF;
151 aBSDF.Kt = theWeight;
153 aBSDF.AbsorptionColor = theAbsorptionColor;
154 aBSDF.AbsorptionCoeff = theAbsorptionCoeff;
156 aBSDF.Fresnel = Graphic3d_Fresnel::CreateDielectric (theRefractionIndex);