HaltonSequence.cs 910 B

12345678910111213141516171819202122232425262728293031
  1. namespace UnityEngine.Rendering
  2. {
  3. /// <summary>
  4. /// An utility class to compute samples on the Halton sequence.
  5. /// https://en.wikipedia.org/wiki/Halton_sequence
  6. /// </summary>
  7. public static class HaltonSequence
  8. {
  9. /// <summary>
  10. /// Gets a deterministic sample in the Halton sequence.
  11. /// </summary>
  12. /// <param name="index">The index in the sequence.</param>
  13. /// <param name="radix">The radix of the sequence.</param>
  14. /// <returns>A sample from the Halton sequence.</returns>
  15. public static float Get(int index, int radix)
  16. {
  17. float result = 0f;
  18. float fraction = 1f / radix;
  19. while (index > 0)
  20. {
  21. result += (index % radix) * fraction;
  22. index /= radix;
  23. fraction /= radix;
  24. }
  25. return result;
  26. }
  27. }
  28. }