In smallpt's source at line 90 the direction is multiplied by 140
and I was wondering where that number is coming from. I was hoping for it to be explained in the slides attached to the source but I couldn't find an explanation for where that number is coming from.
If I increase the number(to 160.0
for example) it starts giving some kind of weird zoom-out effect:
And if I decrease the number(in this example to 125.0
) I get this partially black picture:
As I understand it, after I've simplified smallpt a little bit, in the main
function we get a random point in each subpixel normalized by the width/height between -0.5
and 0.5
, and then calculate the new ray direction by multiplying the x and y axis by these offsets, then adding everything together to obtain the new direction, something like this:
fov_scale = 2.0 * tan(vertical_fov / 2.0)
cam_x_axis = vec3(aspect_ratio * fov_scale, 0, 0)
cam_y_axis = normalize(cross(cam_x_axis, cam_direction))
for x, y:
for sx, sy, samps:
// not using smallpt's tent filter
x_in_subpixel = x + sx * 0.5 + erand48(Xi) * 0.5
y_in_subpixel = y + sy * 0.5 + erand48(Xi) * 0.5
// normalize them between -0.5 and 0.5
new_x = x_in_subpixel / w - 0.5
new_y = y_in_subpixel / h - 0.5
offset_x = cam_x_axis * new_x
offset_y = cam_y_axis * new_y
new_direction = cam_direction + offset_x + offset_y
// here we can see that magic number
new_ray = ray(cam_position + new_direction * 140, normalize(new_direction))
So my questions are:
- What does this number mean?
- Can I calculate it programmatically to be exactly what is expected(maybe depending on the field of view, width/height of the image)?