Nori  24
uvtexture.cpp
1 /*
2  This file is part of Nori, a simple educational ray tracer
3 
4  Copyright (c) 2024 by CGL, ETH Zurich
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/texture.h>
20 
21 NORI_NAMESPACE_BEGIN
22 
23 template <typename T>
24 class UVTexture : public Texture<T> {
25 public:
26  UVTexture(const PropertyList& props) { }
27 
28  virtual T eval(const Point2f & uv) override {
29  const float C = 8 * 2 * M_PI;
30  float u = uv.x();
31  float v = uv.y();
32 
33  float r = abs(fmod(u, 1.f));
34  float g = abs(fmod(v, 1.f));
35  float b = 0.5;
36 
37  // Adding cyclic pattern
38  r *= (1.f - 0.2 * std::sin(C * u) * std::sin(C * v));
39  g *= (1.f - 0.2 * std::cos(C * u) * std::sin(C * v));
40 
41  return Color3f(r, g, b);
42  }
43 
44  virtual std::string toString() const override {
45  return "UVTexture[]";
46  }
47 };
48 
49 NORI_REGISTER_TEMPLATED_CLASS(UVTexture, Color3f, "uvtexture")
50 
51 NORI_NAMESPACE_END
This is an associative container used to supply the constructors of NoriObject subclasses with parame...
Definition: proplist.h:32
Superclass of all texture.
Definition: texture.h:30
virtual std::string toString() const override
Return a brief string summary of the instance (for debugging purposes)
Definition: uvtexture.cpp:44
Represents a linear RGB color value.
Definition: color.h:29