Skip to content

Commit

Permalink
NextWeek: fix bad code in Perlin noise() function
Browse files Browse the repository at this point in the history
The original code for the first version of the Perlin noise() function
in _The Next Week_ was incorrect. This returns the code to the original
behavior, but using static_cast instead of the original C-style cast.

Resolves #396
  • Loading branch information
hollasch committed Mar 16, 2020
1 parent 00d0ab0 commit 5cb9a2c
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions books/RayTracingTheNextWeek.html
Original file line number Diff line number Diff line change
Expand Up @@ -1093,9 +1093,11 @@
auto u = p.x() - floor(p.x());
auto v = p.y() - floor(p.y());
auto w = p.z() - floor(p.z());
auto i = static_cast<int>(floor(p.x()));
auto j = static_cast<int>(floor(p.y()));
auto k = static_cast<int>(floor(p.z()));

auto i = static_cast<int>(4*p.x()) & 255;
auto j = static_cast<int>(4*p.y()) & 255;
auto k = static_cast<int>(4*p.z()) & 255;

return ranfloat[perm_x[i] ^ perm_y[j] ^ perm_z[k]];
}

Expand Down

0 comments on commit 5cb9a2c

Please sign in to comment.