3 #include <color/spectrum.hpp>
5 #include <texture/perlin.hpp>
6 #include <camera/ray.hpp>
7 #include <math3d/vec3.hpp>
8 using namespace ptracey;
12 virtual color value(Real u, Real v,
const vec3 &p,
13 const WaveLength &w)
const = 0;
23 color value(Real u, Real v,
const vec3 &p,
24 const WaveLength &w)
const override {
25 return color_value.evaluate(w);
36 shared_ptr<texture> _even)
37 : odd(_odd), even(_even) {}
40 : odd(make_shared<solid_color>(c1)),
41 even(make_shared<solid_color>(c2)) {}
43 color value(Real u, Real v,
const vec3 &p,
44 const WaveLength &w)
const override {
46 sin(10 * p.x()) * sin(10 * p.y()) * sin(10 * p.z());
48 return odd->value(u, v, p, w);
50 return even->value(u, v, p, w);
54 shared_ptr<texture> odd;
55 shared_ptr<texture> even;
61 : scale(sc), spec(sp) {}
63 color value(Real u, Real v,
const vec3 &p,
64 const WaveLength &w)
const override {
66 0.5 * (1 + sin(scale * p.z() + 10 * noise.turb(p)));
67 color eval = spec.evaluate(w);
79 const static int bytes_per_pixel = 3;
81 : data(
nullptr), width(0), height(0),
82 bytes_per_scanline(0) {}
84 auto components_per_pixel = bytes_per_pixel;
86 data = stbi_load(filename, &width, &height,
87 &components_per_pixel,
88 components_per_pixel);
92 <<
"ERROR: Could not load texture image file '"
93 << filename <<
"'.\n";
97 bytes_per_scanline = bytes_per_pixel * width;
100 color value(Real u, Real v,
const vec3 &p,
101 const WaveLength &wl)
const override {
104 if (data ==
nullptr) {
105 return spectrum(0, 1, 1).evaluate(wl);
109 u = clamp(u, 0.0, 1.0);
113 auto i =
static_cast<int>(u * width);
114 auto j =
static_cast<int>(v * height);
123 const auto color_scale = 1.0 / 255.0;
125 data + j * bytes_per_scanline + i * bytes_per_pixel;
127 spectrum pix_rgb(color_scale * pixel[0],
128 color_scale * pixel[1],
129 color_scale * pixel[2]);
130 return pix_rgb.evaluate(wl);
136 int bytes_per_scanline;
143 : spect(make_shared<solid_color>(s)) {}
146 const path &path_to_csv,
147 const std::string &wave_col_name,
148 const std::string &power_col_name,
149 const char &sep =
',',
150 const unsigned int stride = SPD_STRIDE,
151 SpectrumType stype = SpectrumType::Reflectance) {
153 spectrum(CSV_PARENT / path_to_csv, wave_col_name,
154 power_col_name, sep, stride, stype);
155 spect = make_shared<solid_color>(spd_material);
158 color value(Real u, Real v,
const vec3 &p,
159 const WaveLength &w)
const {
160 return spect->value(u, v, p, w);
164 shared_ptr<texture> spect;