The permutation maps are usually the numbers from 0 to 255 arranged in a random order. If I were to use a cryptographic hash function to convert a string, and then use the result's individual integers (e.g. 22, 53, 77...) in the permutation map, what effects would this give?
-
2\$\begingroup\$ What meaning do you put into the word "inappropriate"? \$\endgroup\$Kromster– Kromster2024-09-11 08:11:25 +00:00Commented Sep 11, 2024 at 8:11
-
2\$\begingroup\$ We'd need to know more about the intended application to be able to judge how appropriate this approach is for achieving your goals, and whether it poses any problems that detract from those goals. If you want to learn about the use of hash functions in procedural generation in general, Squirrel Eiserloh gave a great overview of how to use them as a pseudo-random source in games at GDC2017. We'd usually use non-cryptographic hash functions for evaluation speed - what makes you reach for a cryptographic one in this case? \$\endgroup\$DMGregory– DMGregory ♦2024-09-11 10:55:26 +00:00Commented Sep 11, 2024 at 10:55
-
\$\begingroup\$ As long as you're not intending to use the output for cryptographic purposes, it doesn't really matter either way. \$\endgroup\$Basic– Basic2024-09-11 15:21:08 +00:00Commented Sep 11, 2024 at 15:21
2 Answers
A cryptographically secure PRNG (CSPRNG) is usually slower than an ordinary PRNG, but otherwise there's no difference for your purposes.
Using the raw values as a permutation map will often make it contain the same number several times, which means it's technically not a permutation map any more. This would make those values appear more often than they should in your Perlin noise. I don't know if this would produce any obvious effect - some wavelets would be going in the same direction, so there might be more regular patterns?
In any case, you can fix this by doing some post-processing to remove duplicate values from the permutation map and replace them with other random values. Or you can try it and see if it affects the quality of your output, which is the important thing.
-
1\$\begingroup\$ It's inaccurate to state that there's no difference in the randomness produced by a regular PRNG and a CSPRNG. The output of CSPRNG has to satisfy statistical randomness tests. Regular PRNGs aren't so obligated & often don't. \$\endgroup\$Pikalek– Pikalek2024-09-11 14:01:26 +00:00Commented Sep 11, 2024 at 14:01
-
\$\begingroup\$ True, but irrelevant - I've edited to try to remove the confusion. Since the state-of-the-art for OP is a hardcoded permutation array of 256 elements, and that worked perfectly fine, clearly we don't need perfect statistical randomness. And it would be overkill to try. \$\endgroup\$Toph– Toph2024-09-11 14:11:48 +00:00Commented Sep 11, 2024 at 14:11
in the permutation map, what effects would this give?
The question is: the repetition of some numbers and elimination of the same number of numbers has what effect?
If we view the noise as an infinite cloud rendering: There would be an increase in density to > 100% in some areas, and an equivalent area < 0 % in others.
To achieve true effect balance the size in each dimension and the number of dimensions must be quite large.
So in effect, depending on the seed value, you will, saturate(1), zero or alternate both, for large portions of the output space.
I would not suggest using hash as a direct replacement for reordering 0 - 255.
If you want to use a hash, then swap each array location with it's hash offset location. Mod 256 if needed.
The noise generator (perlin/simplex), no matter the original seed values, becomes a dimensionally correlated pseudo random number generator function by definition.