Hi
I have written a simple CPU raytracer which just generated this image:
I just realized that I am calculating the secondary rays origin incorrectly. I was simply adding a random number to the x and y of the origin point. This is fine when my lookat point is at the same height at my camera position but if it is higher or lower, my square aperture will be tilted. How do I find a random point in the aperture rectangle around my camera?
Some code:
//primary ray
Ray newRay = camera.GetRay(x, y, HEIGHT, WIDTH, antiX, antiY);
//convergent point on focal plane
Vec3 focalPoint = newRay.calculate(camera.focalLength);
double origX = randOrigin(generator);
double origY = randOrigin(generator);
Vec3 randomOrigin(newRay.origin.x + origX, newRay.origin.y + origY, newRay.origin.z);
//direction to focal plane
Vec3 focalDir(focalPoint - randomOrigin);
focalDir = focalDir.normalized();
newRay = Ray(randomOrigin, focalDir);
Thanks