1#ifndef TATOOINE_RENDERING_DIRECT_VOLUME_H
2#define TATOOINE_RENDERING_DIRECT_VOLUME_H
11template <arithmetic DistOnRay, arithmetic CameraReal, arithmetic AABBReal,
12 regular_invocable<vec<AABBReal, 3>> DomainCheck,
typename Shader>
15 DomainCheck&& domain_check, DistOnRay
const distance_on_ray,
19 using color_t = std::invoke_result_t<Shader, pos_type, viewdir_t>;
21 using alpha_t =
typename color_t::value_type;
23 "Shader must return a vector with 4 components.");
28 rendered_image.template insert_vertex_property<rgb_t>(
"rendering");
29 auto const bg_color = rgb_t::ones();
31 std::vector<std::tuple<ray<CameraReal, 3>, AABBReal, size_t,
size_t>> rays;
32 for (
size_t y = 0; y < cam.plane_height(); ++y) {
33 for (
size_t x = 0; x < cam.plane_width(); ++x) {
34 rendering(x, y) = bg_color;
35 auto r = cam.ray(x, y);
38 rays.push_back(std::tuple{r, i->t, x, y});
42#pragma omp parallel for
43 for (
size_t i = 0; i < rays.size(); ++i) {
44 auto const [r, t, x, y] = rays[i];
45 auto accumulated_color = rgb_t::zeros();
46 auto accumulated_alpha = alpha_t(0);
48 pos_type cur_pos = r(cur_t);
55 if (domain_check(cur_pos)) {
56 auto const rgba = shader(cur_pos, r.direction());
57 auto const rgb =
vec{rgba(0), rgba(1), rgba(2)};
58 auto const alpha = rgba(3);
59 accumulated_color += (1 - accumulated_alpha) * alpha * rgb;
60 accumulated_alpha += (1 - accumulated_alpha) * alpha;
62 cur_t += distance_on_ray;
65 rendering(x, y) = accumulated_color * accumulated_alpha +
66 bg_color * (1 - accumulated_alpha);
68 return rendered_image;
Definition: rectilinear_grid.h:38
Definition: tensor_concepts.h:23
auto direct_volume(camera< CameraReal > const &cam, axis_aligned_bounding_box< AABBReal, 3 > const &aabb, DomainCheck &&domain_check, DistOnRay const distance_on_ray, Shader &&shader)
Definition: direct_volume.h:13
Definition: axis_aligned_bounding_box.h:103
auto constexpr is_inside(pos_type const &p) const
Definition: axis_aligned_bounding_box.h:191
auto check_intersection(ray_type const &r, Real const =0) const -> optional_intersection_type override
Definition: axis_aligned_bounding_box.h:33
Definition: linspace.h:26