Skip to content

Commit 9423527

Browse files
authored
Merge pull request #397 from RayTracing/fix-396
NextWeek: fix bad code in Perlin noise() function
2 parents 00d0ab0 + 5cb9a2c commit 9423527

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

books/RayTracingTheNextWeek.html

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1093,9 +1093,11 @@
10931093
auto u = p.x() - floor(p.x());
10941094
auto v = p.y() - floor(p.y());
10951095
auto w = p.z() - floor(p.z());
1096-
auto i = static_cast<int>(floor(p.x()));
1097-
auto j = static_cast<int>(floor(p.y()));
1098-
auto k = static_cast<int>(floor(p.z()));
1096+
1097+
auto i = static_cast<int>(4*p.x()) & 255;
1098+
auto j = static_cast<int>(4*p.y()) & 255;
1099+
auto k = static_cast<int>(4*p.z()) & 255;
1100+
10991101
return ranfloat[perm_x[i] ^ perm_y[j] ^ perm_z[k]];
11001102
}
11011103

0 commit comments

Comments
 (0)