libs/yocto/yocto_scene.cpp
// Generates a ray from a camera for yimg::image plane coordinate uv and
// the lens coordinates luv.
Generates a ray from a camera for yimg::image plane coordinate uv and
the lens coordinates luv.
Generates a ray from a camera for yimg :: image plane coordinate uv and the lens coordinates luv .
ray3f eval_camera(
    const scene_camera* camera, const vec2f& image_uv, const vec2f& lens_uv) {
  auto film = camera->aspect >= 1
                  ? vec2f{camera->film, camera->film / camera->aspect}
                  : vec2f{camera->film * camera->aspect, camera->film};
  if (!camera->orthographic) {
    auto q = vec3f{film.x * (0.5f - image_uv.x), film.y * (image_uv.y - 0.5f),
        camera->lens};
    auto dc = -normalize(q);
    auto e = vec3f{
        lens_uv.x * camera->aperture / 2, lens_uv.y * camera->aperture / 2, 0};
    auto p = dc * camera->focus / abs(dc.z);
    auto d = normalize(p - e);
    return ray3f{transform_point(camera->frame, e),
        transform_direction(camera->frame, d)};
  } else {
    auto scale = 1 / camera->lens;
    auto q     = vec3f{film.x * (0.5f - image_uv.x) * scale,
        film.y * (image_uv.y - 0.5f) * scale, camera->lens};
    auto e = vec3f{-q.x, -q.y, 0} + vec3f{lens_uv.x * camera->aperture / 2,
                                        lens_uv.y * camera->aperture / 2, 0};
    auto p = vec3f{-q.x, -q.y, -camera->focus};
    auto d = normalize(p - e);
    return ray3f{transform_point(camera->frame, e),
        transform_direction(camera->frame, d)};
  }
}
ray3f eval_camera ( const scene_camera * camera , const vec2f & image_uv , const vec2f & lens_uv ) { auto film = camera -> aspect >= 1 ? vec2f { camera -> film , camera -> film / camera -> aspect } : vec2f { camera -> film * camera -> aspect , camera -> film } ; if ( ! camera -> orthographic ) { auto q = vec3f { film . x * ( 0.5f - image_uv . x ) , film . y * ( image_uv . y - 0.5f ) , camera -> lens } ; auto dc = - normalize ( q ) ; auto e = vec3f { lens_uv . x * camera -> aperture / 2 , lens_uv . y * camera -> aperture / 2 , 0 } ; auto p = dc * camera -> focus / abs ( dc . z ) ; auto d = normalize ( p - e ) ; return ray3f { transform_point ( camera -> frame , e ) , transform_direction ( camera -> frame , d ) } ; } else { auto scale = 1 / camera -> lens ; auto q = vec3f { film . x * ( 0.5f - image_uv . x ) * scale , film . y * ( image_uv . y - 0.5f ) * scale , camera -> lens } ; auto e = vec3f { - q . x , - q . y , 0 } + vec3f { lens_uv . x * camera -> aperture / 2 , lens_uv . y * camera -> aperture / 2 , 0 } ; auto p = vec3f { - q . x , - q . y , - camera -> focus } ; auto d = normalize ( p - e ) ; return ray3f { transform_point ( camera -> frame , e ) , transform_direction ( camera -> frame , d ) } ; } }
Generates a ray from a camera for yimg::image plane coordinate uv and
the lens coordinates luv.
Generates a ray from a camera for yimg :: image plane coordinate uv and the lens coordinates luv .
// ray direction through the lens center // point on the lens // point on the focus plane // correct ray direction to account for camera focusing // done // point on the lens // point on the focus plane // correct ray direction to account for camera focusing // done