pouët.net

Go to bottom

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).

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.
added on the 2016-05-15 23:03:11 by metric metric
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.
added on the 2016-05-16 00:02:51 by Gargaj Gargaj
Well, but of course, 57 is not your usual number. It is so called IQ's prime ;)
added on the 2016-05-16 01:39:24 by tomkh tomkh
7
added on the 2016-05-16 07:05:17 by v3nom v3nom
I vaguely recall hearing that he chose 5 because it was his lucky number, and 7 because it was his wife's lucky number.
added on the 2016-05-16 07:26:19 by yesso yesso
isn't that the name of a tool song? ;)
added on the 2016-05-16 07:51:00 by xeron xeron
From the context I expected them to be primes, but neither is. Funny.
added on the 2016-05-16 08:48:58 by sol_hsa sol_hsa
It's his IQ when drunk or sober.
added on the 2016-05-16 10:00:23 by psonice psonice
Ahh yes... "57 and 133"... off their amazing "Clean your Butt" album...
added on the 2016-05-16 10:18:48 by bloodnok bloodnok
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 :).
added on the 2016-05-16 10:32:38 by metric metric
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.
added on the 2016-05-16 10:39:24 by Preacher Preacher
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.
added on the 2016-05-16 15:22:37 by tomkh tomkh
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.
added on the 2016-05-16 15:37:52 by tomkh tomkh
and with their powers combined you can create 5711 and 1337, both with deep etymological meaning within the demoscene
added on the 2016-05-16 17:12:50 by psenough psenough
it must be the secret shader conspiracy
added on the 2016-05-16 19:25:29 by wysiwtf wysiwtf
7447
added on the 2016-05-16 21:45:32 by sol_hsa sol_hsa
In the year 2525

login

Go to top