4 ms·
The ray-scene hit test uses comparison between distances, which involves a square root for each sphere. If you switch to using squared distances, the comparison
by jng 7y ago
The ray-scene hit test uses comparison between distances, which involves a square root for each sphere. If you switch to using squared distances, the comparison will work equally well and the code will be a lot faster in many cases. You will need to reorganize the code a bit, since the moment you actually find the hit, you may need to do the square root to calculate the actual distance (but it will only be once per pixel instead of once per pixel per object in the scene).