what I am trying to do is improving my actual Ray Tracer to create a Distributed Ray Tracer. I have been wandering on internet and all I could found about its implementation was just short stuff like:
-Replace single ray with distribution of rays -Shoot multiple rays distributed over an interval -Shoot multiple rays through each pixel and vary each ray randomly
My question is: What does a "distribution" mean? How can I vary a distribution of rays that go through a pixel? In my normal Ray Tracer I shoot one ray per pixel. For "distribution" of rays I can understand that I should shoot multiple rays instead of only one. But at the same time I shoot the ray through my pixel with coordinates (x,y).
for (int x = 0; x < WINDOW_WIDTH; x++)
{
for (int y = 0; y < WINDOW_HEIGHT; y++)
{
Vec3<float> rayDir = camera->pixelToWorld(x, y) - camera->position;
}
}
So, how can I "vary each ray randomly" ? Thanks.
There are several usages of distributed ray tracing, it can be used for:
(1) antialiasing
(2) depth of field effects
(3) motion blur effects
For (1), the idea is simply to launch in each pixel a bunch of rays instead of a single ray. Each ray will be thrown through the center of the pixel jittered a little bit by random dx and dy (dx and dy will be smaller than the size of the pixel).
For (2), it is slightly more complicated, but it is roughly the same idea: each ray is shot as a line that starts from the observer and that goes through the center of a pixel (possibly jittered if you do (1), but let us now forget about it for now). This time, this is the observer position that you are jittering, you will jitter the position of the observer a little bit in the direction orthogonal to the screen. Again, by averaging the contribution of a number of rays in each pixel, the background will be more "blurred" than the foreground, because the ray will deviate more in the background.
For (3), it is just the same idea, but this time this is the position of the moving objects that are jittered.
Note: there is also (4): complex materials with glossy effects (they require to understand a little bit of material, notion of BRDF = Bidirectional Reflection Distribution Function).