mstdn.social is one of the many independent Mastodon servers you can use to participate in the fediverse.
A general-purpose Mastodon server with a 500 character limit. All languages are welcome.

Administered by:

Server stats:

13K
active users

#bittwiddling

0 posts0 participants0 posts today

I'm sure this has been done many times before, but I'm still happy to be bit-twiddling in #shaders. The star is this line:

(vertex_index & 3u) + (vertex_index >> 2u)

"Give me the first two bits but add one if the third bit is set.”

The shader generates a UV-mapped quad (right-triangle pair) from the 0 through 5 vertex indices. The screenshot code is abridged; full code is at the link.

github.com/shanecelis/bevy/blo #gamedev #bevyengine #bittwiddling #wgsl

In 2013, past me wrote some mysterious code. Effectively, it was this.

uint8_t decay(uint8_t x) { return (x >> 1) | (x >> 2); }

Sort of a low level multiply by 0.75, but with an | instead of a +. The target was an 8 bit AVR. Is there any good reason for using | here? I vaguely remember a bug where certain values didn't decay, but testing shows all 255 nonzero values of x do decay.

Any thoughts?