tag:blogger.com,1999:blog-8258684804699119480.post566563210613903994..comments2020-08-15T23:19:02.028-07:00Comments on A Mind Forever Programming: Random Floats in GLSL 330Lee Chttp://www.blogger.com/profile/06442139982211951254noreply@blogger.comBlogger2125tag:blogger.com,1999:blog-8258684804699119480.post-54274445437949912192017-10-03T13:54:19.398-07:002017-10-03T13:54:19.398-07:00Hello! The idea is sound, but your 2D, 3D and 4D h...Hello! The idea is sound, but your 2D, 3D and 4D hash functions are very expensive... and the 1D hash is prone to visible artifacts.<br /><br />Note that the hash functions only need to care about the lowest 23 bits, with a focus on good avalanche behavior in the higher bits of that range.<br /><br />Here's what I use:<br /><br />uint hashInt1D( uint x )<br />{<br /> x += x >> 11;<br /> x ^= x << 7;<br /> x += x >> 15;<br /> x ^= x << 5;<br /> x += x >> 12;<br /> x ^= x << 9;<br /> return x;<br />}<br /><br />uint hashInt2D( uint x, uint y )<br />{<br /> x += x >> 11;<br /> x ^= x << 7;<br /> x += y;<br /> x ^= x << 6;<br /> x += x >> 15;<br /> x ^= x << 5;<br /> x += x >> 12;<br /> x ^= x << 9;<br /> return x;<br />}<br /><br />uint hashInt3D( uint x, uint y, uint z )<br />{<br /> x += x >> 11;<br /> x ^= x << 7;<br /> x += y;<br /> x ^= x << 3;<br /> x += z ^ ( x >> 14 );<br /> x ^= x << 6;<br /> x += x >> 15;<br /> x ^= x << 5;<br /> x += x >> 12;<br /> x ^= x << 9;<br /> return x;<br />}<br />Alexis Naveroshttps://www.blogger.com/profile/09598439800275763091noreply@blogger.comtag:blogger.com,1999:blog-8258684804699119480.post-32465930131401849172016-12-15T00:37:30.177-08:002016-12-15T00:37:30.177-08:00Thanks, works perfectly in Metal too. Very nice lo...Thanks, works perfectly in Metal too. Very nice looking noise also... :)Anonymoushttps://www.blogger.com/profile/16041039901440504964noreply@blogger.com