4 ms·
He mentions the front to back optimization, keeping track of the max height.
by ironSkillet 6y ago
He mentions the front to back optimization, keeping track of the max height.
- jameshart 6y agoHe misses the additional optimization of tracking one ray at a time - depth first rather than breadth first. You don’t need to hold a complete z-buffer, just know the last height/distance you drew, and keep scanning out along the line until you find another terrain point high enough to see.
- s-macke 6y agoAuthor here. But then you have a division of each coordinate. And this was more expensive than a memory lookup. So you might end up with a table as well. You have to test and optimize both approaches to be really sure.
- jameshart 6y agoI’m not sure why a division is necessary. When you send a ray out in a given direction through the screen, you can calculate its height in world space at distance z just by multiplication; and you can construct that ray entirely by multiplication and addition of values that are constant for the frame. So you can march a point out in increasing z along a ray pointing towards the bottom of the screen, then when it hits the ground, move it up the screen until it stops hitting the ground, then draw that line and start increasing z again. The perspective correction division just disappears completely. I don’t disagree that you need to benchmark approaches to see if they will work, but it’s got to be interesting to consider if it’s possible to avoid allocating a buffer to store the height reached per column, right?