Jump to content
IGNORED

Random Numbers, Blue Noise vs White Noise


Recommended Posts

 

Often random numbers are referred to as "noise", and sometimes we attach colors to refer to the different characteristics of that noise

 

I recently watched a very good video that covered the usefulness of blue noise in modern game dev. One of the relevant bits for us was that blue noise is a source of aesthetically pleasing random numbers. Most random noise sources, including our better LFSRs, have white noise characteristics. Humans tend to perceive white noise distribution as "clumpy", meaning that sometimes you get a run of neighbouring random values. This likely isn't desirable if you're using random numbers for enemy positions, loot drops, etc.

 

The traditional algorithms for generating blue noise from white noise involve generating a bunch of random values, and massaging the number distribution. That's approach isn't suitable for our small machines, so I came up with an alternative method of bluing white noise that's super-cheap and surprisingly effective. The comparison spectral analysis charts in that article were produced using the  bB/7800basic 16-bit LFSR as the random source.

 

Hopefully someone finds all of this interesting, if not useful. :P

  • Like 11
Link to comment
Share on other sites

This is pretty cool! I need a bit of help understanding your pseudocode, though:

 

	A=RAND ; any masking or range-reduction needs to be done here, or else
	B=RAND ; it will reintroduce clumpiness into the value distribution
	if ABS(B-C) > ABS(A-C) then A=B
	C=(C+A)/2 ; exponentially decaying running average
	; "A" is holding your next bluish noise value

Would "RAND" here be our call to the LFSR or whatever random generator so that A and B hold different randomly-generated values? If so, it doesn't appear that there's any saved state in the function for it to keep track of prior random values?

Link to comment
Share on other sites

53 minutes ago, Karl G said:

This is pretty cool! I need a bit of help understanding your pseudocode, though:

The assignments were meant to black box the random function, since the algorithm works with LFSR, Standard C library random calls, or any other white noise source. I'll change the pseudocode to a function call looking thing to make that point clearer. (A=GetRandom(),  B=GetRandom() )

 

[edit - done]

  • Thanks 1
Link to comment
Share on other sites

That's what I figured, but I somehow missed that C would end up keeping its state. So it sounds like only one new persistent byte would be needed to blue the randomization, in addition to what is needed for the random function itself. Pretty cool! 

Link to comment
Share on other sites

Just for fun, I made a bin to demonstrate the difference between the two algorithms with random audio output. Press fire to switch which random number generator that is in use, with the background color matching (regular rand having a white background, and "blue rand" having a blue background). My ear can't really hear the difference; probably the sounds change too quickly to notice any patterns. If nothing else, it shows a 7800basic implementation of this algorithm, however.

 

I may try to maybe a visual demo that may make the differences more obvious.

 

bluewhite.78b

 

  • Like 1
Link to comment
Share on other sites

Yeah, it's a bit hard to tell. I want to say the blue is slightly less squiggly, but I don't know if that's just because I expect it to be so. The power of suggestion is pretty strong.

 

The algorithm definitely produces bluish sounding noise when directly played as sample data, with characteristic boosted highs, compared to white. I just think there are some areas where people aren't great at detecting those clumps or runs of numbers.

  • Like 1
Link to comment
Share on other sites

I made a visual version with two side-by-side 16x16 grids with fading squares. It's still difficult for me to get a sense of the difference in random distribution, but if nothing else, it looks cool, and could make for a good screensaver.  :D

 

Screenshotfrom2024-05-2513-35-37.thumb.png.76d5e3fc3e3701e0e7233eb29986d573.png

 

bluewhite2.zip

  • Like 3
Link to comment
Share on other sites

  • 4 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...