1
0
mirror of https://github.com/ssloy/tinyraytracer.git synced 2025-03-15 11:19:38 +01:00

Updated Home (markdown)

Dmitry V. Sokolov 2019-01-22 13:18:39 +01:00
parent 8889c04f13
commit 506800f05f

@ -141,7 +141,7 @@ Where it comes from? Pretty simple. Our camera is placed in the origin and it fa
<img src="https://raw.githubusercontent.com/ssloy/tinyraytracer/master/trace.png"/>
As i said, the camera is placed at the origin, and the scene is projected at the screen that lies the plane z = -1. The field of view specifies what sector of the space will be visible at the screen. In our image the screen is 16 pixels wide; can you compute its length in world coordinates? It is pretty simple: let us focus on the triangle formed by the red, gray and gray dashed line. It is easy to see that tan(field of view / 2) = (screen width) * 0.5 / (screen-camera distance). We placed the screen at the distance of 1 from the camera, thus (screen width) = 2 * tan(field of view / 2).
As i said, the camera is placed at the origin, and the scene is projected at the screen that lies in the plane z = -1. The field of view specifies what sector of the space will be visible at the screen. In our image the screen is 16 pixels wide; can you compute its length in world coordinates? It is pretty simple: let us focus on the triangle formed by the red, gray and gray dashed line. It is easy to see that tan(field of view / 2) = (screen width) * 0.5 / (screen-camera distance). We placed the screen at the distance of 1 from the camera, thus (screen width) = 2 * tan(field of view / 2).
Now let us say that we want to cast a vector through the center of the 12th pixel of the screen, i.e. we want to compute the blue vector. How can we do that? What is the distance from the left of the screen to the tip of the blue vector? First of all, it is 12+0.5 pixels. We know that 16 pixels of the screen correspond to 2 * tan(fov/2) world units. Thus, tip of the vector is located at (12+0.5)/16 * 2*tan(fov/2) world units from the left edge, or at the distance of (12+0.5) * 2/16 * tan(fov/2) - tan(fov/2) from the intersection between the screen and the -z axis. Add the screen aspect ratio to the computations and you will find exactly the formulas for the ray direction.