4 ms·
It was actually precomputed at one point, but there are two things that make it less appealing. They don't feature in the article until part #3, unfortunately.
by krajzeg 10y ago
It was actually precomputed at one point, but there are two things that make it less appealing. They don't feature in the article until part #3, unfortunately.
The first is flexible range - the light has adjustable brightness which makes it bigger/smaller. The second is the flickering effect applied to each line. Both these things mean that any access to the precomputed table would have to be scaled anyway, which would remove most of its benefit - to the point where all it would save would be one subtraction (sqrt() is taken from a precalculated table in the final version).
- Scaevolus 10y agoCould you memoize the table for each brightness? (presumably flickering is +/- brightness).
- krajzeg 10y agoSure, it's possible, and flickering is indeed the same as scaling the brightness (but randomly each line). I was under the impression that the table needed would be too big, but now that I actually calculated it (max_range^2*light_levels), it's nothing back-breaking. I'm concentrating more on the game right now than on making the engine even faster, but I'll try to look into before writing the next part - thanks!