57 and 133 ?
category: code [glöplog]
Hi,
I've spotted the constants 57 and/or 133 in many of (not only) iq's demos when computing noise or hash. For example in this shader (see below for convenience).
On the line 7 (in the above excerpt) he's essentially computing dot product dot(vec2(1, 57), p). In different shaders number 133 is used instead of 57. I don't see exactly why.
My wild guess is that 57 = 180/pi = 1 radian in degrees (approximately) and that 133 is roughly 2 radians in degrees. And since the hash() function is using sin(), I guess that the constants are somehow linked to the periodicity of trig function.
Anyway, what's so special about 57 and 133 in this context? Thanks.
I've spotted the constants 57 and/or 133 in many of (not only) iq's demos when computing noise or hash. For example in this shader (see below for convenience).
Code:
float hash( float n ) { return fract(sin(n)*43758.5453); }
float noise( in vec2 x )
{
vec2 p = floor(x);
vec2 f = fract(x);
f = f*f*(3.0-2.0*f);
float n = p.x + p.y*57.0;
return mix(mix( hash(n+ 0.0), hash(n+ 1.0),f.x),
mix( hash(n+ 57.0), hash(n+ 58.0),f.x),f.y);
}
On the line 7 (in the above excerpt) he's essentially computing dot product dot(vec2(1, 57), p). In different shaders number 133 is used instead of 57. I don't see exactly why.
My wild guess is that 57 = 180/pi = 1 radian in degrees (approximately) and that 133 is roughly 2 radians in degrees. And since the hash() function is using sin(), I guess that the constants are somehow linked to the periodicity of trig function.
Anyway, what's so special about 57 and 133 in this context? Thanks.
I don't think they have a specific reason, they're just a random enough number that causes the sine offset for the noise to look noisy enough.
Well, but of course, 57 is not your usual number. It is so called IQ's prime ;)
7
I vaguely recall hearing that he chose 5 because it was his lucky number, and 7 because it was his wife's lucky number.
isn't that the name of a tool song? ;)
From the context I expected them to be primes, but neither is. Funny.
It's his IQ when drunk or sober.
Ahh yes... "57 and 133"... off their amazing "Clean your Butt" album...
Quote:
I vaguely recall hearing that he chose 5 because it was his lucky number, and 7 because it was his wife's lucky number.
That's interesting, thanks. It's funny that I thought there's some deeper meaning in those numbers :).
I'd go as far as to say that picking your and your wife's lucky number has a lot more deeper meaning than simply picking something that's mathematically convenient.
Not every number will do.
You have to avoid numbers that are close to 0 modulo "pi" (or 2*pi), for example with this number you will see significant artifacts:
355%pi = 0.00003
Although usually small correlations are canceled out by multiplying it by some big random number like 43758.5453 before taking fraction, so say 66 doesn't look so bad.
And since we perform modulo with irrational number (in theory) there is no point choosing prime for mulitplier. Even in simple LCG, where field size is usually power of two - field size and multiplier just has to be relatively prime (among few other conditions) to maximize the period.
Very small numbers won't work, because we just shifting the domain. Also not every number looks good due to precision/rounding errors and some "hidden" correlations.
At the end it's all very hard to calculate/predict and I guess everyone is just doing a bit trial&error until it looks satisfying.
You have to avoid numbers that are close to 0 modulo "pi" (or 2*pi), for example with this number you will see significant artifacts:
355%pi = 0.00003
Although usually small correlations are canceled out by multiplying it by some big random number like 43758.5453 before taking fraction, so say 66 doesn't look so bad.
And since we perform modulo with irrational number (in theory) there is no point choosing prime for mulitplier. Even in simple LCG, where field size is usually power of two - field size and multiplier just has to be relatively prime (among few other conditions) to maximize the period.
Very small numbers won't work, because we just shifting the domain. Also not every number looks good due to precision/rounding errors and some "hidden" correlations.
At the end it's all very hard to calculate/predict and I guess everyone is just doing a bit trial&error until it looks satisfying.
Errata: in LCG, offset and field size (aka modulus) has to be relatively prime, multiplier not even, but it has not much use here anyway. It's just to show that prime numbers for multipliers are usually just a naive choice that has nothing to do with theory behind.
and with their powers combined you can create 5711 and 1337, both with deep etymological meaning within the demoscene
it must be the secret shader conspiracy
7447
In the year 2525