diff options
| author | ladevieq <ladevie.quentin@gmail.com> | 2021-01-09 20:42:24 +0100 |
|---|---|---|
| committer | ladevieq <ladevie.quentin@gmail.com> | 2021-01-09 20:43:09 +0100 |
| commit | 2db0d27e7f1744443958717c19b732eed57455f2 (patch) | |
| tree | 839b8ea513c8c239f015071ab083bd50f03854a5 /src/camera.cpp | |
| parent | 4379b46b46563c5a709df8d567ef75affc3fd31c (diff) | |
Replace old classes with compute shader structs
Diffstat (limited to 'src/camera.cpp')
| -rw-r--r-- | src/camera.cpp | 28 |
1 files changed, 8 insertions, 20 deletions
diff --git a/src/camera.cpp b/src/camera.cpp index c7e2e35..6cb7b83 100644 --- a/src/camera.cpp +++ b/src/camera.cpp @@ -5,34 +5,22 @@ camera::camera( point3 position, point3 target, - double v_fov, - double aspect_ratio, - double aperture, - double focus_dist + float v_fov, + float aspect_ratio, + float aperture, + float focus_dist ) : position(position), lens_radius(aperture / 2.0) { - forward = (target - position).unit(); + auto forward = (target - position).unit(); right = forward.cross(vec3{ 0.0, 1.0, 0.0 }).unit(); up = right.cross(forward).unit(); auto h = tan(deg_to_rad(v_fov) / 2.0); - viewport_height = 2.0 * h; - viewport_width = viewport_height * aspect_ratio; + auto viewport_height = 2.0 * h; + auto viewport_width = viewport_height * aspect_ratio; horizontal = focus_dist * viewport_width * right; vertical = focus_dist * viewport_height * up; - bottom_left_pixel = position - horizontal / 2.0 - vertical / 2.0 - forward * focus_dist; -} - -ray camera::get_ray(double u, double v) const { - vec3 rd = lens_radius * random_in_unit_disk(); - vec3 offset = rd.x * right + rd.y * up; - - point3 viewport_pixel = bottom_left_pixel + u * horizontal + v * vertical; - - return ray { - position + offset, - viewport_pixel - position - offset - }; + first_pixel = position - horizontal / 2.0 - vertical / 2.0 + focus_dist * forward; } |
