‹ BackHN Continuity

Thread

When the fractional part of a float fixes your shader

111 points · 19 comments · vinhnx

  1. Sharlin · · focus · HN ↗
    Should be noted that `fract(x)` is importantly only equivalent to `x - floor(x)` when x >= 0. Which it was in this case, but often negative values are also possible/expected and the latter should be used instead. This is an easy mistake to make.
    1. SomeonesAccount · · focus · HN ↗
      *former

      Good catch. OP should probably update the article

      1. Sharlin · · focus · HN ↗
        No, the latter. To make a lattice, we usually want to decompose x to floor(x) and whatever's left over, which is x - floor(x) and always nonnegative. fract(x) gives the leftover of trunc(x) instead and is negative when x is negative, and it's usually a logic error for a lerp variable to be outside [0, 1]. In this case, it creates artifacts along the coordinate axes.
        1. [deleted] · · focus · HN ↗

          [deleted]

Open on Hacker News to reply ↗

Unofficial Hacker News client; not affiliated with Y Combinator.