7 ms·
Insert obligatory reference to the fast inverse square root calculation which, thanks to its ability to more quickly generate (1/x) by using a bit shift with a
by sushshshsh 6y ago
Insert obligatory reference to the fast inverse square root calculation which, thanks to its ability to more quickly generate (1/x) by using a bit shift with a magic number 0x5F3759DF, allowed performant lighting calculations for use in games. This number was known for this purpose for long before Quake (shout out SGI), but was popularized for the first time there
- ladyanita22 6y agoDamn, that's awesome
- blt 6y agoThe bit manipulation already generates an approximation of 1/sqrt(x), not just 1/x.
- Nition 6y agoFast inverse square root wasn't in Quake until Quake III though, right?
- sushshshsh 6y agoThat's correct, though there was plenty of other asm and bit level evil graphics voodoo that made quake able to run so fast on consumer hardware a few generations earlier than if they were stuck using slower division:)
- flohofwoe 6y agoThe most notable trick in Quake I (at least IMHO) is the triangle rasterizer line-loop which schedules the divide needed for perspective-correct texture mapping to the FPU so that this expensive divide can run in parallel to pixel-span rasterization on the integer ALU. To my young brain who's only done 8- and 16-bit assembly on simple CPUs before this was nothing short of rocket science :)
- skocznymroczny 6y agoIt's not the same without the original comments. Also, I don't know which is crazier, the magic number, or the fact that the code is casting a float to long bitwise and then working on it.
- sushshshsh 6y agoi = * (long * ) &y; // evil floating point bit level hacking i = 0x5f3759df - (i >> 1); // what the fuck?