Nori  24
mirror.cpp
1 /*
2  This file is part of Nori, a simple educational ray tracer
3 
4  Copyright (c) 2015 by Wenzel Jakob
5 
6  Nori is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License Version 3
8  as published by the Free Software Foundation.
9 
10  Nori is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18 
19 #include <nori/bsdf.h>
20 #include <nori/frame.h>
21 
22 NORI_NAMESPACE_BEGIN
23 
25 class Mirror : public BSDF {
26 public:
27  Mirror(const PropertyList &) { }
28 
29  virtual Color3f eval(const BSDFQueryRecord &) const override {
30  /* Discrete BRDFs always evaluate to zero in Nori */
31  return Color3f(0.0f);
32  }
33 
34  virtual float pdf(const BSDFQueryRecord &) const override {
35  /* Discrete BRDFs always evaluate to zero in Nori */
36  return 0.0f;
37  }
38 
39  virtual Color3f sample(BSDFQueryRecord &bRec, const Point2f &) const override {
40  if (Frame::cosTheta(bRec.wi) <= 0)
41  return Color3f(0.0f);
42 
43  // Reflection in local coordinates
44  bRec.wo = Vector3f(
45  -bRec.wi.x(),
46  -bRec.wi.y(),
47  bRec.wi.z()
48  );
49  bRec.measure = EDiscrete;
50 
51  /* Relative index of refraction: no change */
52  bRec.eta = 1.0f;
53 
54  return Color3f(1.0f);
55  }
56 
57  virtual std::string toString() const override {
58  return "Mirror[]";
59  }
60 };
61 
62 NORI_REGISTER_CLASS(Mirror, "mirror");
63 NORI_NAMESPACE_END
Superclass of all bidirectional scattering distribution functions.
Definition: bsdf.h:60
Ideal mirror BRDF.
Definition: mirror.cpp:25
virtual Color3f eval(const BSDFQueryRecord &) const override
Evaluate the BSDF for a pair of directions and measure specified in code bRec.
Definition: mirror.cpp:29
virtual float pdf(const BSDFQueryRecord &) const override
Compute the probability of sampling bRec.wo (conditioned on bRec.wi).
Definition: mirror.cpp:34
virtual std::string toString() const override
Return a brief string summary of the instance (for debugging purposes)
Definition: mirror.cpp:57
virtual Color3f sample(BSDFQueryRecord &bRec, const Point2f &) const override
Sample the BSDF and return the importance weight (i.e. the value of the BSDF * cos(theta_o) divided b...
Definition: mirror.cpp:39
This is an associative container used to supply the constructors of NoriObject subclasses with parame...
Definition: proplist.h:32
Convenience data structure used to pass multiple parameters to the evaluation and sampling routines i...
Definition: bsdf.h:30
Vector3f wo
Outgoing direction (in the local frame)
Definition: bsdf.h:35
Vector3f wi
Incident direction (in the local frame)
Definition: bsdf.h:32
EMeasure measure
Measure associated with the sample.
Definition: bsdf.h:41
float eta
Relative refractive index in the sampled direction.
Definition: bsdf.h:38
Represents a linear RGB color value.
Definition: color.h:29
static float cosTheta(const Vector3f &v)
Assuming that the given direction is in the local coordinate system, return the cosine of the angle b...
Definition: frame.h:67