4 ms·
IDK, but it seems super wasteful: Why not compute RDX and RDX*RDX outside the inner loop? Why not precompute COX, COY, COZ and EQC once per scene?
by Anotheroneagain 3y ago
IDK, but it seems super wasteful:
Why not compute RDX and RDX*RDX outside the inner loop?
Why not precompute COX, COY, COZ and EQC once per scene?
- ggambetta 3y ago(COX, COY and COZ) vary per pixel and per sphere, hence so does EQC, so can't really compute them once per scene, unless I'm missing something? RDX yes, and I did that (and a lot more) in the later iterations where performance started to become an issue.
- Anotheroneagain 3y agoI don't see why they would vary? They must remain constant for each object.
- ggambetta 3y agoIf you're talking about the first iteration, you're right (ROX, ROY, ROZ) is hardcoded to (0, 0, 0), but I decided to implement a general algorithm anyway, because performance wasn't a problem at that point. If you can find optimizations that don't obliterate code readability for the fifth iteration (https://gabrielgambetta.com/zx-raytracer-5-src.html https://gabrielgambetta.com/zx-raytracer-5-src.html), I'm all ears :)
- Anotheroneagain 3y agoI mean still there are obvious calculations that stay the same. DZ is always one, you can just skip it. 1212 is the same for all pixels, all are constants, you could do it once per sphere. 2100 A stays the same.
- ggambetta 3y agoThese are good ones, thanks!