Skip to content

Commit 4083db8

Browse files
committed
Groom listing 2.37 and update smooth Perlin image
1 parent 1dcd491 commit 4083db8

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

books/RayTracingTheNextWeek.html

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2042,9 +2042,14 @@
20422042
<div class='together'>
20432043
Now if we create an actual texture that takes these floats between 0 and 1 and creates grey colors:
20442044

2045+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
2046+
#include "rtweekend.h"
2047+
2048+
20452049
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
20462050
#include "perlin.h"
20472051
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
2052+
#include "rtw_stb_image.h"
20482053

20492054
...
20502055

@@ -2129,6 +2134,7 @@
21292134
class perlin {
21302135
public:
21312136
...
2137+
21322138
double noise(const point3& p) const {
21332139
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
21342140
auto u = p.x() - floor(p.x());
@@ -2152,19 +2158,27 @@
21522158
return trilinear_interp(c, u, v, w);
21532159
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
21542160
}
2161+
21552162
...
21562163

21572164
private:
21582165
...
2166+
2167+
static void permute(int* p, int n) {
2168+
...
2169+
}
2170+
2171+
21592172
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
21602173
static double trilinear_interp(double c[2][2][2], double u, double v, double w) {
21612174
auto accum = 0.0;
21622175
for (int i=0; i < 2; i++)
21632176
for (int j=0; j < 2; j++)
21642177
for (int k=0; k < 2; k++)
2165-
accum += (i*u + (1-i)*(1-u))*
2166-
(j*v + (1-j)*(1-v))*
2167-
(k*w + (1-k)*(1-w))*c[i][j][k];
2178+
accum += (i*u + (1-i)*(1-u))
2179+
* (j*v + (1-j)*(1-v))
2180+
* (k*w + (1-k)*(1-w))
2181+
* c[i][j][k];
21682182

21692183
return accum;
21702184
}

images/img-2.10-perlin-trilerp.png

-17.7 KB
Loading

0 commit comments

Comments
 (0)