HaltonSeq.cs 866 B

123456789101112131415161718192021222324252627282930
  1. namespace UnityEngine.Rendering.PostProcessing
  2. {
  3. /// <summary>
  4. /// Halton sequence utility.
  5. /// </summary>
  6. public static class HaltonSeq
  7. {
  8. /// <summary>
  9. /// Gets a value from the Halton sequence for a given index and radix.
  10. /// </summary>
  11. /// <param name="index">The sequence index</param>
  12. /// <param name="radix">The sequence base</param>
  13. /// <returns>A number from the Halton sequence between 0 and 1.</returns>
  14. public static float Get(int index, int radix)
  15. {
  16. float result = 0f;
  17. float fraction = 1f / (float)radix;
  18. while (index > 0)
  19. {
  20. result += (float)(index % radix) * fraction;
  21. index /= radix;
  22. fraction /= (float)radix;
  23. }
  24. return result;
  25. }
  26. }
  27. }