public static class VfxRandomRandom numbers a compute shader can reproduce exactly.
No guide page documents this yet — the page shows what the code says about itself.
Remarks
Stateless, not a stream. A generator with state has to be carried per particle and advanced in the order the particles are visited, which on the GPU is no order at all. So there is no state: a value is a pure function of what it is for — the particle's own identifier, the effect's seed, and a per-use salt — and any thread can compute any particle's value at any time without having computed anybody else's first. That is what makes the CPU and GPU paths comparable rather than merely similar.
Integer operations only, and that is a hard rule. Every step here is a 32-bit multiply, xor or shift, all of which are exact and identical on every processor that runs them. The moment a hash reaches for a float multiply, a sine or a table it becomes a thing that agrees to within a tolerance, and a tolerance is not what a golden-image test or a replay wants. The single conversion to float happens at the very end, from a 24-bit mantissa's worth of bits, which is exact in both directions.
The mixing function is the one from Chris Wellons' lowbias32, chosen because it is three multiplies and three xor-shifts, has no anomalies in the avalanche tests, and is short enough to inline into a shader without a second thought.
Fields and properties (1)
public const uint FirstSaltSalt for the first random value an operation asks for.
Methods (6)
public static uint Hash(uint value)Mixes a value into a well-distributed 32-bit hash.
public static uint Hash(uint particle, uint seed, uint salt)The hash for one particle's one use of randomness.
public static float Value(uint particle, uint seed, uint salt)A uniform value in [0, 1).
public static float Range(uint particle, uint seed, uint salt, float minimum, float maximum)A uniform value in [, ).
public static Vector3 Value3(uint particle, uint seed, uint salt)Three uniform values in [0, 1), from three consecutive salts.
public static Vector3 Direction(uint particle, uint seed, uint salt)A direction uniformly distributed over the unit sphere.
Used by (3)
- VfxNoiseVixen.Vfx
- VfxRandomTestsVixen.Vfx.Tests
- VfxSimulationVixen.Vfx