-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrtcrisscrosstexture.cpp
136 lines (103 loc) · 3.26 KB
/
rtcrisscrosstexture.cpp
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#include "rtcrisscrosstexture.h"
#include <cmath>
RTColor RTCrissCrossTexture::getColorCC1() const
{
return colorCC1;
}
void RTCrissCrossTexture::setColorCC1(const RTColor &value)
{
colorCC1 = value;
}
RTColor RTCrissCrossTexture::getColorCC2() const
{
return colorCC2;
}
void RTCrissCrossTexture::setColorCC2(const RTColor &value)
{
colorCC2 = value;
}
RTColor RTCrissCrossTexture::getColorCC3() const
{
return colorCC3;
}
void RTCrissCrossTexture::setColorCC3(const RTColor &value)
{
colorCC3 = value;
}
double RTCrissCrossTexture::getScale() const
{
return scale;
}
void RTCrissCrossTexture::setScale(double value)
{
scale = value;
}
RTLatticeNoise RTCrissCrossTexture::getPerlimNoise() const
{
return perlimNoise;
}
void RTCrissCrossTexture::setPerlimNoise(const RTLatticeNoise &value)
{
perlimNoise = value;
}
RTCrissCrossTexture::RTCrissCrossTexture():perlimNoise()
{
}
RTCrissCrossTexture::RTCrissCrossTexture(double ka, double kd, double ks, double kr, int n, int surfaceType, int material,
RTColor colorCC1, RTColor colorCC2,RTColor colorCC3, double scale):
RTBRDF(ka,kd,ks,kr,n,surfaceType,material),perlimNoise()
{
this->colorCC1=colorCC1;
this->colorCC2=colorCC2;
this->colorCC3=colorCC3;
this->scale=scale;
}
RTCrissCrossTexture::RTCrissCrossTexture(RTCrissCrossTexture &cpy):RTBRDF(ka,kd,ks,kr,n,surfaceType,material)
{
this->ka=cpy.getKa();
this->kd = cpy.getKd();
this->ks = cpy.getKs();
this->ka = cpy.getKa();
this->kr = cpy.getKr();
this->n= cpy.getN();
this->surfaceType=cpy.getSurfaceType();
RTVector v;
this->color = cpy.getColor(v);
this->refracIndex=cpy.getRefracIndex();
this->material=cpy.getMaterial();
this->colorCC1=cpy.getColorCC1();
this->colorCC2=cpy.getColorCC2();
this->colorCC3=cpy.getColorCC3();
this->scale=cpy.getScale();
this->perlimNoise=cpy.getPerlimNoise();
}
RTColor RTCrissCrossTexture::getColor(RTVector hitPoint) const
{
double x = hitPoint.getX() * scale * 0.5;
double y = hitPoint.getY() * scale * 0.5;
double z = hitPoint.getZ() * scale * 0.5;
double noiseCoefA = 0;
double noiseCoefB = 0;
double noiseCoefC = 0;
for (int level = 1; level < 10; level++) {
RTVector v1( level * 0.35 * x,level * 0.05 * y,level * z);
noiseCoefA += (1.0f / level) * fabsf(perlimNoise.linearNoise(v1));
RTVector v2( level* x,level * 0.35 * y,level*0.05 * z);
noiseCoefB += (1.0f / level) * fabsf(perlimNoise.linearNoise(v2));
RTVector v3( level*0.05* x,level * y,level*0.35 * z);
noiseCoefC += (1.0f / level) * fabsf(perlimNoise.linearNoise(v3));
}
noiseCoefA = 0.5f * sinf((x + z) * 0.05f + noiseCoefA) + 0.5f;
noiseCoefB = 0.5f * sinf((y + x) * 0.05f + noiseCoefB) + 0.5f;
noiseCoefC = 0.5f * sinf((z + y) * 0.05f + noiseCoefC) + 0.5f;
RTColor c1= colorCC1;
RTColor c2=colorCC2;
RTColor c3=colorCC3;
return (c1 * noiseCoefA + c2 * (1.0f - noiseCoefA)) * 0.25 +
(c2 * noiseCoefB + c3 * (1.0f - noiseCoefB)) * 0.25 +
(c3 * noiseCoefC + c1 * (1.0f - noiseCoefC)) * 0.25;
}
double RTCrissCrossTexture::getRefracIndex() const
{
return 0;
}