every gamedev knows and loves the ‘5 cent filter’ aka easy easing: if you have a (persistent) value x, perhaps its the position of something eg a ui element, instead of setting it to a new value, say N, nudge it 1% of the way there each frame: x+=(N-x)*0.01; /
most gamedevs have this one liner deeply etched. the 0.01 controls the smoothness - 1 snaps, 0 never moves, small values go slow, etc; this is exactly what an audio person would call a 1-pole low pass filter, & that number (call it g) that controls smoothness is cutoff frequency
now you can stack two of these in a row to get a steeper cutoff. if youre trying to smooth noisy input (eg a flaky joystick reading), that can be helpful. dont forget the extra step needs to be persistent state, call it y. so you have:
y+=(N-y)*g; x+=(y-x)*g; so its just the same thing as before but stacked twice: we smooth once to get y, then smooth THAT to get x. voila, 2 pole filter. but now for a fun extension: with low g, you get rid of nasty small noise in the input, but it can feel soggy. what to do?
well, the difference between x and y is actually a band pass filter! intuitively its a measure of ‘how much change is going on’ around the critical smoothing frequency. if you boost g up (more responsive) dynamically based on, say, 0.25*abs(y-x), you get snappiness on sudden
changes, but nice extreme smoothing for small jitters. i learned of this bandpass-driving-dynamic-cutoff frequency from here: https://cytomic.com/files/dsp/DynamicSmoothing.pdf enjoy! fin.
You can follow @mmalex.
Tip: mention @twtextapp on a Twitter thread with the keyword “unroll” to get a link to it.

Latest Threads Unrolled:

By continuing to use the site, you are consenting to the use of cookies as explained in our Cookie Policy to improve your experience.