forked from RayTracing/TheNextWeek
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtexture.h
54 lines (43 loc) · 1.34 KB
/
texture.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#ifndef TEXTUREH
#define TEXTUREH
#include "perlin.h"
class texture {
public:
virtual vec3 value(float u, float v, const vec3& p) const = 0;
};
class constant_texture : public texture {
public:
constant_texture() { }
constant_texture(vec3 c) : color(c) { }
virtual vec3 value(float u, float v, const vec3& p) const {
return color;
}
vec3 color;
};
class checker_texture : public texture {
public:
checker_texture() { }
checker_texture(texture *t0, texture *t1): even(t0), odd(t1) { }
virtual vec3 value(float u, float v, const vec3& p) const {
float sines = sin(10*p.x())*sin(10*p.y())*sin(10*p.z());
if (sines < 0)
return odd->value(u, v, p);
else
return even->value(u, v, p);
}
texture *odd;
texture *even;
};
class noise_texture : public texture {
public:
noise_texture() {}
noise_texture(float sc) : scale(sc) {}
virtual vec3 value(float u, float v, const vec3& p) const {
// return vec3(1,1,1)*0.5*(1 + noise.turb(scale * p));
// return vec3(1,1,1)*noise.turb(scale * p);
return vec3(1,1,1)*0.5*(1 + sin(scale*p.x() + 5*noise.turb(scale*p))) ;
}
perlin noise;
float scale;
};
#endif