Fastest way to generate this kind of noise

3 posts

Flag Post

Hey,

I want to achieve some kind of random slight color change in every single pixel every frame, and also based on how far from the center every pixel is.

What’s the fastest way to generate noise every frame? I know Math.random() is slow so I should not use that. Eventually, is the perlinNoise function able to output a bitmapdata where every pixel is randomized (both in R, G and B)?
I could then blend it using a premade alpha bitmap.
Though I don’t thing perlin noise is fast at all either.
Thanks!

 
Flag Post

The first thing to do is try BitmapData.noise() and see if that’s fast enough.

If it turns out not to be, you can try these pseudorandom number generators instead: 1 2 3.

 
Flag Post

noise() would have been my first guess as well. If it’s too slow, you could generate a large BitmapData of noise (say 4000×4000 so you don’t exceed the FP10 BitmapData size limits and needlessly crash legacy players) at game start, apply whatever effects you want that do not depend on position, and then copyPixels() a random portion of it every frame on which you apply your radial effects.

Another option is to generate a Perlin noise bitmapdata at game startup and change the offsets of the various harmonics to random stuff at each frame. That would shift the various components, making it look like the noise is different. It’s been used to animate cloud effects, so I know this one’s fast enough to use in a frame renderer.