Mostly geometry.
Been a long time since I’ve written anything here.  Lately I’ve been working on a new multiplayer WebGL voxel engine for (an educational platform to teach kids programming via games).  It’s not live yet, but a bunch of neat ideas have come out of this project.  In this post I want to talk about the lighting model and share some of the tricks which were used to speed up processing.
We could do operations on each channel using bit masking/shifting and looping, however there is a better way:  We’ll use a general pattern of splitting the coefficients in half and masking out the even/odd components separately so we have some extra space to work.  This can be done by bit-wise &’ing with the mask 0xf0f0f0f: function lightLessThan (a, b) { let r = 0; for (let i = 0; i < 8; ++i) { if ((a & (0xf << i)) < (b & (0xf << i))) { r |= 0xf << i; } } return r; } const COMPONENT_MASK = 0xf0f0f0f const BORROW_GUARD = 0x20202020 const CARRY_MASK = 0x10101010 function wlpHalfLT (a, b) { const d = (((a & COMPONENT_MASK) | BORROW_GUARD) - (b & COMPONENT_MASK)) & CARRY_MASK; return (d >>> 1) | (d >>> 2) | (d >>> 3) | (d >>> 4); } function wlpLT (a:number, b:number) { return wlpHalfLT(a, b) | (wlpHalfLT(a >> 4, b >> 4) << 4); } function wlpMax (a, b) { return a ^ ((a ^ b) & wlpLT(a, b)); } function wlpDecHalf (x) { // compute component-wise decrement const d = ((x & 0xf0f0f0f) | 0x20202020) - 0x1010101; // check for underflow const b = d & 0x10101010; // saturate underflowed values return (d + (b >> 4)) & 0x0f0f0f0f; } // decrement then saturate each 4 bit component of x function wlpDec (x) { return wlpDecHalf(x) | (wlpDecHalf(x >> 4) << 4); } Thanks to for supporting this project. This entry was posted in ,. Bookmark the permalink. 3 Responses to Voxel lighting. Ihor Vlasyuk February 21, 2018 at 5:47 am Hooray. You are alive.

## Thanks for update best blog ever Reply

Dakror March 3, 2018 at 9:08 am Wohoo, so glad to be reading from you again.
Thanks for all the amazing posts.

### 2020 at 10:45 pm Multidirectional sun light is impossible in chunked infinite world

Just because you cannot predict opacity of blocks that are outside loaded area. 