Skip to content

Instantly share code, notes, and snippets.

@VehpuS
Created March 10, 2022 17:13
Show Gist options
  • Save VehpuS/416ba299a41f0dafe1000ce8ae966e2c to your computer and use it in GitHub Desktop.
Save VehpuS/416ba299a41f0dafe1000ce8ae966e2c to your computer and use it in GitHub Desktop.
Calculating modulo with other arithmetic functions (thanks to https://stackoverflow.com/questions/35155598/unable-to-use-in-glsl for the idea)
// neither recursion nor looping is necessary to compute a mod b. That's easily done by a - (b * floor(a/b)).
const mod = (a, b) => a - (b * floor(a/b))
// Simple, but powerful when running on platforms that lack the function but have the floor function (i.e. GLSL for deck.gl)
// Thanks to https://stackoverflow.com/questions/35155598/unable-to-use-in-glsl for the idea
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment