Lightmetrica  0.0.1.50dbee3 (yosakoi)
 All Classes Functions Variables Typedefs Enumerations Enumerator
bsdf.h
1 /*
2  Lightmetrica : A research-oriented renderer
3 
4  Copyright (c) 2014 Hisanari Otsu
5 
6  This program is free software: you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 #pragma once
21 #ifndef LIB_LIGHTMETRICA_BSDF_H
22 #define LIB_LIGHTMETRICA_BSDF_H
23 
24 #include "generalizedbsdf.h"
25 #include "surfacegeometry.h"
26 
27 LM_NAMESPACE_BEGIN
28 
33 class BSDF : public GeneralizedBSDF
34 {
35 public:
36 
37  LM_ASSET_INTERFACE_DEF("bsdf", "bsdfs");
38  LM_ASSET_DEPENDENCIES("texture");
39 
40 public:
41 
42  BSDF() {}
43  virtual ~BSDF() {}
44 
45 protected:
46 
57  LM_FORCE_INLINE static Math::Float ShadingNormalCorrectionFactor(
58  const TransportDirection& transportDir, const SurfaceGeometry& geom,
59  const Math::Vec3& localWi, const Math::Vec3& localWo, const Math::Vec3& worldWi, const Math::Vec3& worldWo)
60  {
61  // Prevent light leak
62  // In some cases wi and wo are same side according to the shading normal
63  // but opposite side according to the geometry normal.
64  auto wiDotNg = Math::Dot(worldWi, geom.gn);
65  auto woDotNg = Math::Dot(worldWo, geom.gn);
66  auto wiDotNs = Math::CosThetaZUp(localWi);
67  auto woDotNs = Math::CosThetaZUp(localWo);
68  if (wiDotNg * wiDotNs <= 0 || woDotNg * woDotNs <= 0)
69  {
70  return Math::Float(0);
71  }
72 
73  // Special handling for adjoint case
74  // Be careful of the difference of the notation between Veach's thesis;
75  // in the framework, wo is always the propagating direction.
76  if (transportDir == TransportDirection::LE)
77  {
78  // |w_i, N_s| * |w_o, N_g| / |w_i, N_g| / |w_o, N_s|
79  return wiDotNs * woDotNg / (woDotNs * wiDotNg);
80  }
81 
82  return Math::Float(1);
83  }
84 
85 };
86 
87 LM_NAMESPACE_END
88 
89 #endif // LIB_LIGHTMETRICA_BSDF_H
static LM_FORCE_INLINE Math::Float ShadingNormalCorrectionFactor(const TransportDirection &transportDir, const SurfaceGeometry &geom, const Math::Vec3 &localWi, const Math::Vec3 &localWo, const Math::Vec3 &worldWi, const Math::Vec3 &worldWo)
Definition: bsdf.h:57
Definition: generalizedbsdf.h:168
Definition: bsdf.h:33
Math::Vec3 gn
Geometry normal.
Definition: surfacegeometry.h:42
Definition: surfacegeometry.h:36