Is there a good GLSL hash function?

2019-06-26 07:13发布

问题:

So I am still getting upvotes for my ancient comment on this question: What's the origin of this GLSL rand() one-liner?

And it got me thinking, what would a good GLSL hash function look like? There are obvious use cases for it like Perlin noise. There are some properties that I would look for in a good implementation.

  • Stable under different precisions (mediump,highp). This could be configurable.
  • Should be usable in ES2, so it can not use integer support
  • ALU only, no textures
  • Not looking for cryptographic qualities, but for large periods and "perceptual" randomness
  • Should ideally produce the same results on a bare minimum spec ES2 implementation

Practically I think most people just mix x,y inputs by multiplying them with some prime numbers, adding them, multiplying them again, and looking the result coordinate up in a tiling texture of random numbers with nearest sampling.

So this question is less about looking for "the answer" but curiosity if there is a good way to do this. I would also like to know arguments about why it is not possible.