Skip to content

Instantly share code, notes, and snippets.

@randompast
Created December 28, 2020 14:20
Show Gist options
  • Save randompast/72ea1f00b1a2b0b4495032456313db9c to your computer and use it in GitHub Desktop.
Save randompast/72ea1f00b1a2b0b4495032456313db9c to your computer and use it in GitHub Desktop.
GDC noise function by Squirrel Eiserloh
// Credit to Squirrel Eiserloh https://twitter.com/SquirrelTweets
// https://www.gdcvault.com/play/1024365/Math-for-Game-Programmers-Noise
// https://youtu.be/LWFzPP8ZbdU?t=2831
// http://www.mathforgameprogrammers.com/
// python version: https://github.com/sublee/squirrel3-python/blob/master/squirrel3.py
unit32_t Squirrel( int p, uint32_t seed ){
constexpr unsigned int BIT_NOISE1 = 0xB5297A4D;
constexpr unsigned int BIT_NOISE2 = 0x68E31DA4;
constexpr unsigned int BIT_NOISE3 = 0x1B56C4E9;
unsigned int m = p; //mangled = position
m *= BIT_NOISE1;
m += seed;
m ^= (m >> 8)
m *= BIT_NOISE2;
m ^= (m << 8)
m *= BIT_NOISE3;
m ^= (m >> 8)
return m
}
// the position could be dotted with the PRIMES vector to get higher orders
// SIMD
// https://youtu.be/BpwvXkoFcp8?t=686
// v = [x,y,z, ...], primes = [1, 198491317, 6542989, ...]
// GetNoise( dot(v, primes), seed )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment