r/qbasic • u/20260819 • Sep 06 '26
elementary ray tracing experiment
⬆️⬆️ignore the pictures above which are not up-to-date
just a basic one. for study purpose. the "world" consists of a background and two balls. the background is an infinitely faraway color palette with azimuth = hue and altitude = lightness. the balls don't have any colors, only reflect and refract
controls
move mouse = change camera direction
left drag = move lmb ball
left hold + wheel = change lmb ball radius
left hold then right hold + wheel = change lmb ball refractive index
right drag = move rmb ball
right hold + wheel = change rmb ball radius
right hold then left hold + wheel = change rmb ball refractive index
wheel forward = camera position forward
wheel backward = camera position backward
[shift] key hold + wheel = change focus distance
[ctrl] key hold + wheel = change view angle
[alt] key hold + wheel = change aperture
[z] key hold + wheel = change background periodicity
[space] + move mouse = auto focus
[w] key = camera position up
[s] key = camera position down
[a] key = camera position left
[d] key = camera position right
[x] key = help you find the balls when you get lost
[z] key = change background
[c] key = full resolution render
control tricks
the mouse controls suck. qbjs doesn't support "mousemovement" command. if your mouse cursor reaches the left-most edge of the screen and you want to move to the left further, quickly move your mouse to the right then move your mouse to the left. my program ignores mouse movements that are too fast so you can use this trick to continue moving if your mouse cursor reaches the edge
the [x] key actually direct your camera toward the centre of mass of the two balls. it's useful when you want to align the placement before full resolution rendering
if you want to temporarily exit full screen (without exiting the program) you can use the standard windows key combo [alt]+[tab] etc. when you come back just click anywhere on the program screen and full screen mode would be restored
suggested usage
the program initially runs at low resolution so as to maintain real time response. at real time mode the program gives you a rough idea how the scene looks like. move the 2 balls around, change their parameters (positions, radii, refractive indices) and see what happens. if you spot an arrangement that you're interested in getting more details, hit [c] and wait for full resolution render. after completion hit any key to return to real time mode
if you want to explore the inside world (camera inside a ball) i suggest you disable the depth of field effect first (turn aperture to 0) as it would be easier to see what's in the scene. finding the correct focus distance are quite challenging when the camera is inside a ball. auto focus may not work as it always focus on the surfaces

