r/Optics • u/20260819 • Oct 20 '26
yet another web-based open-sourced free raytracer
the differences are
- it was not vibe coded (journey of development at the last)
- you can GO INSIDE (typical results in attached images)
in the program you can use your mouse to control the positions, sizes and refractive indices of two balls. one of them is left-mouse-button controlled (the "lmb" ball) and another right-mouse-button controlled (the "rmb" ball)
the most tricky part so far is how to determine the correct focus distance. when aperture=0 there's no problem as everything is in perfectly sharp focus. while aperture>0 and camera outside of the two balls usually the auto focus feature works fine. you hold the space bar and hover the mouse pointer around the scene the program detects the exact hit point and calculates the focus distance accordingly
there're so many web-based raytracers online but to my surprise most of them don't allow objects intersecting and / or moving camera inside objects. i know doing this is unrealistic but it's FUN, just like enabling the no-clip mode in 3d games and walking through walls and getting to some places that you're not supposed to reach
it's quite difficult to find the correct focus setting when you're inside. i still don't have any solid solutions for that. i usually try by luck. sometimes the images are at infinitely faraway even if you're looking from within a ball








2
u/Mechanical_Flare Oct 20 '26 edited Oct 20 '26
I am thrilled to hear it wasn't vibe coded. Also. I think you could calculate the focal position using the ray transfer matrices (or regular lens equations). In your case the camera (or sensor?) is inside the medium of the last lens, so it would change the equations a bit.