Raytracer
|
Public Member Functions | |
void | setup () |
Set up the camera with the given parameters. | |
void | render (const Interfaces::IHittable &world) |
Render the scene with the given camera. | |
Core::Ray | getRay (double u, double v) const |
Get the ray for the given pixel. | |
Utils::Vec3 | sampleSquare () const |
Sample a square. | |
Utils::Vec3 | sampleDisk (double radius) const |
Sample a disk. | |
Utils::Vec3 | sampleDefocusDisk () const |
Sample the defocus disk. | |
Utils::Color | rayColor (const Ray ray, int depth, const Interfaces::IHittable &world) const |
Get the color of the ray. | |
void | progress (const std::chrono::steady_clock::time_point &start, int j) const |
Print the progress of the rendering. | |
Raytracer::Core::Ray Raytracer::Core::Camera::getRay | ( | double | i, |
double | j ) const |
Get the ray for the given pixel.
This function calculates the sample location based on the pixel location and the pixel delta u and v vectors. The origin is set to the center of the camera if the defocus angle is less than or equal to 0. Otherwise, the origin is set to a point on the defocus disk. The direction is set to the sample location minus the origin. The time is set to a random double.
i | The x coordinate of the pixel. |
j | The y coordinate of the pixel. |
void Raytracer::Core::Camera::progress | ( | const std::chrono::steady_clock::time_point & | start, |
int | j ) const |
Print the progress of the rendering.
This function prints the progress of the rendering to the standard error stream. The progress is printed as a percentage and the time elapsed is printed in seconds.
start | The start time of the rendering. |
j | The y coordinate of the pixel. |
Raytracer::Utils::Color Raytracer::Core::Camera::rayColor | ( | const Ray | ray, |
int | depth, | ||
const Interfaces::IHittable & | world ) const |
Get the color of the ray.
This function returns the color of the ray based on the depth and the world. If the depth is less than or equal to 0, the function returns black. If the ray does not hit anything in the world, the function returns the background color. If the ray scatters, the function returns the emission color plus the scatter color.
ray | The ray to get the color of. |
depth | The depth of the ray. |
world | The world to get the color from. |
void Raytracer::Core::Camera::render | ( | const Interfaces::IHittable & | world | ) |
Render the scene with the given camera.
This function sets up the camera and prints the PPM header. It then loops through each pixel in the image and calculates the pixel color based on the number of samples per pixel. The pixel color is then written to the output stream.
world | The world to render. |
Raytracer::Utils::Vec3 Raytracer::Core::Camera::sampleDefocusDisk | ( | ) | const |
Sample the defocus disk.
This function returns a random point in the defocus disk.
Raytracer::Utils::Vec3 Raytracer::Core::Camera::sampleDisk | ( | double | radius | ) | const |
Sample a disk.
This function returns a random point in a disk centered at the origin with a radius of 1.
radius | The radius of the disk. |
Raytracer::Utils::Vec3 Raytracer::Core::Camera::sampleSquare | ( | ) | const |
Sample a square.
This function returns a random point in a square centered at the origin with a side length of 1.
void Raytracer::Core::Camera::setup | ( | ) |
Set up the camera with the given parameters.
This function calculates the image height based on the aspect ratio and the image width. It also calculates the viewport height and width based on the vertical field of view and the focus distance. The pixel sample scale is calculated based on the number of samples per pixel. The camera's center is set to the look from point. The camera's u, v, and w vectors are calculated based on the look from, look at, and v up points. The viewport u and v vectors are calculated based on the viewport width and height and the u and v vectors. The pixel delta u and v vectors are calculated based on the viewport u and v vectors and the image width and height. The pixel zero location is calculated based on the viewport upper left corner and the pixel delta u and v vectors. The defocus disk u and v vectors are calculated based on the defocus angle and the u and v vectors.