4 #include <curand_kernel.h> 20 float aperture,
float focus) {
21 lens_radius = aperture / 2.0f;
22 float rad = deg * 3.14159265359f / 180.0f;
23 height = tan(rad / 2.0f);
24 width = height * aspect;
27 w = (from - lookat).normalize();
28 u = (vup.cross(w)).normalize();
31 left_corner = orgin - u * width * focus - v * height * focus - w * focus;
32 horizontal = u * 2.0f * width * focus;
33 vertical = v * 2.0f * height * focus;
36 __device__
ray get_ray(
float a,
float b, curandState* local_rand_state) {
37 vec3 rd = random_unit_sphere(local_rand_state) * lens_radius;
38 vec3 offset = u * rd.x + v * rd.y;
39 return ray(orgin + offset, left_corner + horizontal * a + vertical * b - orgin - offset);