3 ms·
random typically works by storing/modifying some state, so every call with the same argument results in different numbers. In shaders, the same code is execute
by hyperman1 6y ago
random typically works by storing/modifying some state, so every call with the same argument results in different numbers.
In shaders, the same code is executed in parallel for potentially every pixel. Storing state would mean pixels could only be calculated serially, slowing things down.
Hence you need a random-ish function that depends only on its input. Very low RNG quality is not a blocker, as long as things look good.
So in shaders you see a lot of random generators which simply take the pixel coordinate or something else that distinguishes 2 pixels and do some nonsense operations on them.