From 212e9ea65226fe92a4f3456a9edc9f8e6a270096 Mon Sep 17 00:00:00 2001 From: bolero-MURAKAMI Date: Sat, 26 Nov 2011 15:20:35 +0900 Subject: [PATCH] =?UTF-8?q?sprout/darkroom/*=20=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sprout/darkroom.hpp | 18 ++ sprout/darkroom/access.hpp | 7 + sprout/darkroom/access/access.hpp | 48 ++++ sprout/darkroom/cameras.hpp | 7 + sprout/darkroom/cameras/simple_camera.hpp | 44 ++++ sprout/darkroom/colors.hpp | 7 + sprout/darkroom/colors/rgb.hpp | 122 ++++++++++ sprout/darkroom/coords.hpp | 7 + sprout/darkroom/coords/vector.hpp | 167 ++++++++++++++ sprout/darkroom/intersects.hpp | 7 + sprout/darkroom/intersects/intersection.hpp | 85 +++++++ sprout/darkroom/lights.hpp | 7 + sprout/darkroom/lights/point_light.hpp | 169 ++++++++++++++ sprout/darkroom/materials.hpp | 7 + sprout/darkroom/materials/material.hpp | 84 +++++++ sprout/darkroom/objects.hpp | 8 + sprout/darkroom/objects/intersect.hpp | 76 ++++++ sprout/darkroom/objects/sphere.hpp | 244 ++++++++++++++++++++ sprout/darkroom/pixels.hpp | 7 + sprout/darkroom/pixels/generate.hpp | 187 +++++++++++++++ sprout/darkroom/rays.hpp | 7 + sprout/darkroom/rays/ray.hpp | 63 +++++ sprout/darkroom/renderers.hpp | 7 + sprout/darkroom/renderers/whitted_style.hpp | 237 +++++++++++++++++++ sprout/darkroom/tracers.hpp | 7 + sprout/darkroom/tracers/raytracer.hpp | 54 +++++ sprout/tuple/tuple.hpp | 13 +- 27 files changed, 1692 insertions(+), 4 deletions(-) create mode 100644 sprout/darkroom.hpp create mode 100644 sprout/darkroom/access.hpp create mode 100644 sprout/darkroom/access/access.hpp create mode 100644 sprout/darkroom/cameras.hpp create mode 100644 sprout/darkroom/cameras/simple_camera.hpp create mode 100644 sprout/darkroom/colors.hpp create mode 100644 sprout/darkroom/colors/rgb.hpp create mode 100644 sprout/darkroom/coords.hpp create mode 100644 sprout/darkroom/coords/vector.hpp create mode 100644 sprout/darkroom/intersects.hpp create mode 100644 sprout/darkroom/intersects/intersection.hpp create mode 100644 sprout/darkroom/lights.hpp create mode 100644 sprout/darkroom/lights/point_light.hpp create mode 100644 sprout/darkroom/materials.hpp create mode 100644 sprout/darkroom/materials/material.hpp create mode 100644 sprout/darkroom/objects.hpp create mode 100644 sprout/darkroom/objects/intersect.hpp create mode 100644 sprout/darkroom/objects/sphere.hpp create mode 100644 sprout/darkroom/pixels.hpp create mode 100644 sprout/darkroom/pixels/generate.hpp create mode 100644 sprout/darkroom/rays.hpp create mode 100644 sprout/darkroom/rays/ray.hpp create mode 100644 sprout/darkroom/renderers.hpp create mode 100644 sprout/darkroom/renderers/whitted_style.hpp create mode 100644 sprout/darkroom/tracers.hpp create mode 100644 sprout/darkroom/tracers/raytracer.hpp diff --git a/sprout/darkroom.hpp b/sprout/darkroom.hpp new file mode 100644 index 00000000..f18cdae5 --- /dev/null +++ b/sprout/darkroom.hpp @@ -0,0 +1,18 @@ +#ifndef SPROUT_DARKROOM_HPP +#define SPROUT_DARKROOM_HPP + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#endif // #ifndef SPROUT_DARKROOM_HPP diff --git a/sprout/darkroom/access.hpp b/sprout/darkroom/access.hpp new file mode 100644 index 00000000..8e61af8c --- /dev/null +++ b/sprout/darkroom/access.hpp @@ -0,0 +1,7 @@ +#ifndef SPROUT_DARKROOM_ACCESS_HPP +#define SPROUT_DARKROOM_ACCESS_HPP + +#include +#include + +#endif // #ifndef SPROUT_DARKROOM_ACCESS_HPP diff --git a/sprout/darkroom/access/access.hpp b/sprout/darkroom/access/access.hpp new file mode 100644 index 00000000..d0afab39 --- /dev/null +++ b/sprout/darkroom/access/access.hpp @@ -0,0 +1,48 @@ +#ifndef SPROUT_DARKROOM_ACCESS_ACCESS_HPP +#define SPROUT_DARKROOM_ACCESS_ACCESS_HPP + +#include +#include +#include +#include + +namespace sprout { + namespace darkroom { + namespace access { + // + // element + // + template + struct element + : public sprout::tuples::tuple_element + {}; + // + // size + // + template + struct size + : public sprout::tuples::tuple_size + {}; + // + // unit + // + template + struct unit + : public sprout::darkroom::access::element<0, T> + {}; + // + // get + // + template + SPROUT_CONSTEXPR auto get( + T&& t + ) SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::tuples::get(sprout::forward(t)))) + -> decltype(sprout::tuples::get(sprout::forward(t))) + { + return sprout::tuples::get(sprout::forward(t)); + } + } // namespace access + } // namespace darkroom +} // namespace sprout + +#endif // #ifndef SPROUT_DARKROOM_ACCESS_ACCESS_HPP diff --git a/sprout/darkroom/cameras.hpp b/sprout/darkroom/cameras.hpp new file mode 100644 index 00000000..21a49a25 --- /dev/null +++ b/sprout/darkroom/cameras.hpp @@ -0,0 +1,7 @@ +#ifndef SPROUT_DARKROOM_CAMERAS_HPP +#define SPROUT_DARKROOM_CAMERAS_HPP + +#include +#include + +#endif // #ifndef SPROUT_DARKROOM_CAMERAS_HPP diff --git a/sprout/darkroom/cameras/simple_camera.hpp b/sprout/darkroom/cameras/simple_camera.hpp new file mode 100644 index 00000000..afbed2ff --- /dev/null +++ b/sprout/darkroom/cameras/simple_camera.hpp @@ -0,0 +1,44 @@ +#ifndef SPROUT_DARKROOM_CAMERAS_SIMPLE_CAMERA_HPP +#define SPROUT_DARKROOM_CAMERAS_SIMPLE_CAMERA_HPP + +#include +#include +#include + +namespace sprout { + namespace darkroom { + namespace cameras { + template + class basic_simple_camera { + public: + typedef Unit unit_type; + typedef sprout::tuples::tuple position_type; + typedef sprout::tuples::tuple ray_type; + private: + unit_type far_plane_; + public: + SPROUT_CONSTEXPR explicit basic_simple_camera( + unit_type const& far_plane + ) + : far_plane_(far_plane) + {} + SPROUT_CONSTEXPR ray_type operator()(unit_type const& u, unit_type const& v) const { + return ray_type( + position_type(0, 0, 0), + sprout::darkroom::coords::normalize(position_type(u, v, far_plane_)) + ); + } + }; + // + // make_simple_camera + // + template + SPROUT_CONSTEXPR inline sprout::darkroom::cameras::basic_simple_camera + make_simple_camera(Unit const& far_plane) { + return sprout::darkroom::cameras::basic_simple_camera(far_plane); + } + } // namespace cameras + } // namespace darkroom +} // namespace sprout + +#endif // #ifndef SPROUT_DARKROOM_CAMERAS_SIMPLE_CAMERA_HPP diff --git a/sprout/darkroom/colors.hpp b/sprout/darkroom/colors.hpp new file mode 100644 index 00000000..6e27b8c1 --- /dev/null +++ b/sprout/darkroom/colors.hpp @@ -0,0 +1,7 @@ +#ifndef SPROUT_DARKROOM_COLORS_HPP +#define SPROUT_DARKROOM_COLORS_HPP + +#include +#include + +#endif // #ifndef SPROUT_DARKROOM_COLORS_HPP diff --git a/sprout/darkroom/colors/rgb.hpp b/sprout/darkroom/colors/rgb.hpp new file mode 100644 index 00000000..26968981 --- /dev/null +++ b/sprout/darkroom/colors/rgb.hpp @@ -0,0 +1,122 @@ +#ifndef SPROUT_DARKROOM_COLORS_RGB_HPP +#define SPROUT_DARKROOM_COLORS_RGB_HPP + +#include +#include +#include +#include +#include +#include +#include + +namespace sprout { + namespace darkroom { + namespace colors { + // + // r + // g + // b + // a + // + template + SPROUT_CONSTEXPR auto r( + T&& t + ) SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::darkroom::access::get<0>(sprout::forward(t)))) + -> decltype(sprout::darkroom::access::get<0>(sprout::forward(t))) + { + return sprout::darkroom::access::get<0>(sprout::forward(t)); + } + template + SPROUT_CONSTEXPR auto g( + T&& t + ) SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::darkroom::access::get<1>(sprout::forward(t)))) + -> decltype(sprout::darkroom::access::get<1>(sprout::forward(t))) + { + return sprout::darkroom::access::get<1>(sprout::forward(t)); + } + template + SPROUT_CONSTEXPR auto b( + T&& t + ) SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::darkroom::access::get<2>(sprout::forward(t)))) + -> decltype(sprout::darkroom::access::get<2>(sprout::forward(t))) + { + return sprout::darkroom::access::get<2>(sprout::forward(t)); + } + template + SPROUT_CONSTEXPR auto a( + T&& t + ) SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::darkroom::access::get<3>(sprout::forward(t)))) + -> decltype(sprout::darkroom::access::get<3>(sprout::forward(t))) + { + return sprout::darkroom::access::get<3>(sprout::forward(t)); + } + + // + // rgb + // rgb_f + // + typedef sprout::tuples::tuple rgb; + typedef sprout::tuples::tuple rgb_f; + + // + // mul + // + template + SPROUT_CONSTEXPR inline Color mul(Color const& lhs, Fac const& rhs) { + return sprout::tuples::remake_clone( + lhs, + sprout::darkroom::colors::r(lhs) * rhs, + sprout::darkroom::colors::g(lhs) * rhs, + sprout::darkroom::colors::b(lhs) * rhs + ); + } + // + // add + // + template + SPROUT_CONSTEXPR inline Color1 add(Color1 const& lhs, Color2 const& rhs) { + return sprout::tuples::remake_clone( + lhs, + sprout::darkroom::colors::r(lhs) + sprout::darkroom::colors::r(rhs), + sprout::darkroom::colors::g(lhs) + sprout::darkroom::colors::g(rhs), + sprout::darkroom::colors::b(lhs) + sprout::darkroom::colors::b(rhs) + ); + } + // + // filter + // + template + SPROUT_CONSTEXPR inline Color1 filter(Color1 const& lhs, Color2 const& rhs) { + return sprout::tuples::remake_clone( + lhs, + sprout::darkroom::colors::r(lhs) * sprout::darkroom::colors::r(rhs), + sprout::darkroom::colors::g(lhs) * sprout::darkroom::colors::g(rhs), + sprout::darkroom::colors::b(lhs) * sprout::darkroom::colors::b(rhs) + ); + } + + // + // rgb_f_to_rgb + // + template + SPROUT_CONSTEXPR inline RGB rgb_f_to_rgb(RGB_F const& col) { + typedef typename sprout::darkroom::access::unit::type unit_type; + return sprout::tuples::make_clone( + sprout::darkroom::colors::r(col) < 0 ? std::numeric_limits::min() + : sprout::darkroom::colors::r(col) > 1 ? std::numeric_limits::max() + : sprout::darkroom::colors::r(col) * std::numeric_limits::max() + , + sprout::darkroom::colors::g(col) < 0 ? std::numeric_limits::min() + : sprout::darkroom::colors::g(col) > 1 ? std::numeric_limits::max() + : sprout::darkroom::colors::g(col) * std::numeric_limits::max() + , + sprout::darkroom::colors::b(col) < 0 ? std::numeric_limits::min() + : sprout::darkroom::colors::b(col) > 1 ? std::numeric_limits::max() + : sprout::darkroom::colors::b(col) * std::numeric_limits::max() + ); + } + } // namespace colors + } // namespace darkroom +} // namespace sprout + +#endif // #ifndef SPROUT_DARKROOM_COLORS_RGB_HPP diff --git a/sprout/darkroom/coords.hpp b/sprout/darkroom/coords.hpp new file mode 100644 index 00000000..234a2ee1 --- /dev/null +++ b/sprout/darkroom/coords.hpp @@ -0,0 +1,7 @@ +#ifndef SPROUT_DARKROOM_COORDS_HPP +#define SPROUT_DARKROOM_COORDS_HPP + +#include +#include + +#endif // #ifndef SPROUT_DARKROOM_COORDS_HPP diff --git a/sprout/darkroom/coords/vector.hpp b/sprout/darkroom/coords/vector.hpp new file mode 100644 index 00000000..c01b2484 --- /dev/null +++ b/sprout/darkroom/coords/vector.hpp @@ -0,0 +1,167 @@ +#ifndef SPROUT_DARKROOM_COORDS_VECTOR_HPP +#define SPROUT_DARKROOM_COORDS_VECTOR_HPP + +#include +#include +#include +#include +#include +#include + +namespace sprout { + namespace darkroom { + namespace coords { + // + // x + // y + // z + // + template + SPROUT_CONSTEXPR auto x( + T&& t + ) SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::darkroom::access::get<0>(sprout::forward(t)))) + -> decltype(sprout::darkroom::access::get<0>(sprout::forward(t))) + { + return sprout::darkroom::access::get<0>(sprout::forward(t)); + } + template + SPROUT_CONSTEXPR auto y( + T&& t + ) SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::darkroom::access::get<1>(sprout::forward(t)))) + -> decltype(sprout::darkroom::access::get<1>(sprout::forward(t))) + { + return sprout::darkroom::access::get<1>(sprout::forward(t)); + } + template + SPROUT_CONSTEXPR auto z( + T&& t + ) SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::darkroom::access::get<2>(sprout::forward(t)))) + -> decltype(sprout::darkroom::access::get<2>(sprout::forward(t))) + { + return sprout::darkroom::access::get<2>(sprout::forward(t)); + } + + // + // vector3d + // + typedef sprout::tuples::tuple vector3d; + + // + // length_sq + // + template + SPROUT_CONSTEXPR inline typename sprout::darkroom::access::unit::type + length_sq(Vector const& vec) { + return sprout::darkroom::coords::x(vec) * sprout::darkroom::coords::x(vec) + + sprout::darkroom::coords::y(vec) * sprout::darkroom::coords::y(vec) + + sprout::darkroom::coords::z(vec) * sprout::darkroom::coords::z(vec) + ; + } + // + // length + // + template + SPROUT_CONSTEXPR inline typename sprout::darkroom::access::unit::type + length(Vector const& vec) { + using std::sqrt; + return sqrt(sprout::darkroom::coords::length_sq(vec)); + } + // + // add + // + template + SPROUT_CONSTEXPR inline Vector1 add(Vector1 const& lhs, Vector2 const& rhs) { + return sprout::tuples::remake_clone( + lhs, + sprout::darkroom::coords::x(lhs) + sprout::darkroom::coords::x(rhs), + sprout::darkroom::coords::y(lhs) + sprout::darkroom::coords::y(rhs), + sprout::darkroom::coords::z(lhs) + sprout::darkroom::coords::z(rhs) + ); + } + // + // sub + // + template + SPROUT_CONSTEXPR inline Vector1 sub(Vector1 const& lhs, Vector2 const& rhs) { + return sprout::tuples::remake_clone( + lhs, + sprout::darkroom::coords::x(lhs) - sprout::darkroom::coords::x(rhs), + sprout::darkroom::coords::y(lhs) - sprout::darkroom::coords::y(rhs), + sprout::darkroom::coords::z(lhs) - sprout::darkroom::coords::z(rhs) + ); + } + // + // scale + // + template + SPROUT_CONSTEXPR inline Vector scale(Vector const& lhs, Fac const& rhs) { + return sprout::tuples::remake_clone( + lhs, + sprout::darkroom::coords::x(lhs) * rhs, + sprout::darkroom::coords::y(lhs) * rhs, + sprout::darkroom::coords::z(lhs) * rhs + ); + } + // + // dot + // + template + SPROUT_CONSTEXPR inline typename sprout::darkroom::access::unit::type + dot(Vector const& lhs, Vector const& rhs) { + return sprout::darkroom::coords::x(lhs) * sprout::darkroom::coords::x(rhs) + + sprout::darkroom::coords::y(lhs) * sprout::darkroom::coords::y(rhs) + + sprout::darkroom::coords::z(lhs) * sprout::darkroom::coords::z(rhs) + ; + } + // + // normalize + // + namespace detail { + template + SPROUT_CONSTEXPR inline Vector normalize_impl( + Vector const& vec, + typename sprout::darkroom::access::unit::type const& len + ) + { + return sprout::tuples::remake_clone( + vec, + sprout::darkroom::coords::x(vec) / len, + sprout::darkroom::coords::y(vec) / len, + sprout::darkroom::coords::z(vec) / len + ); + } + } // namespace detail + template + SPROUT_CONSTEXPR inline Vector normalize(Vector const& vec) { + return sprout::darkroom::coords::detail::normalize_impl( + vec, + sprout::darkroom::coords::length(vec) + ); + } + // + // reflect + // + template + SPROUT_CONSTEXPR inline Incident reflect(Incident const& incid, Normal const& nor) { + return sprout::darkroom::coords::sub( + incid, + sprout::darkroom::coords::scale(nor, sprout::darkroom::coords::dot(incid, nor) * 2) + ); + } + + // + // normal_to_color + // + template + SPROUT_CONSTEXPR Color normal_to_color(Normal const& nor) { + return sprout::tuples::make_clone( + 0.5 + sprout::darkroom::coords::x(nor) * 0.5, + 0.5 + sprout::darkroom::coords::y(nor) * 0.5, + 0.5 + sprout::darkroom::coords::z(nor) * 0.5 + ); + } + } // namespace coords + } // namespace darkroom +} // namespace sprout + +#endif // #ifndef SPROUT_DARKROOM_COORDS_VECTOR_HPP diff --git a/sprout/darkroom/intersects.hpp b/sprout/darkroom/intersects.hpp new file mode 100644 index 00000000..5314fbd5 --- /dev/null +++ b/sprout/darkroom/intersects.hpp @@ -0,0 +1,7 @@ +#ifndef SPROUT_DARKROOM_INTERSECTS_HPP +#define SPROUT_DARKROOM_INTERSECTS_HPP + +#include +#include + +#endif // #ifndef SPROUT_DARKROOM_INTERSECTS_HPP diff --git a/sprout/darkroom/intersects/intersection.hpp b/sprout/darkroom/intersects/intersection.hpp new file mode 100644 index 00000000..5942f138 --- /dev/null +++ b/sprout/darkroom/intersects/intersection.hpp @@ -0,0 +1,85 @@ +#ifndef SPROUT_DARKROOM_INTERSECTS_INTERSECTION_HPP +#define SPROUT_DARKROOM_INTERSECTS_INTERSECTION_HPP + +#include +#include +#include +#include +#include +#include + +namespace sprout { + namespace darkroom { + namespace intersects { + // + // does_intersect + // distance + // point_of_intersection + // normal + // material + // + template + SPROUT_CONSTEXPR auto does_intersect( + T&& t + ) SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::darkroom::access::get<0>(sprout::forward(t)))) + -> decltype(sprout::darkroom::access::get<0>(sprout::forward(t))) + { + return sprout::darkroom::access::get<0>(sprout::forward(t)); + } + template + SPROUT_CONSTEXPR auto distance( + T&& t + ) SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::darkroom::access::get<1>(sprout::forward(t)))) + -> decltype(sprout::darkroom::access::get<1>(sprout::forward(t))) + { + return sprout::darkroom::access::get<1>(sprout::forward(t)); + } + template + SPROUT_CONSTEXPR auto point_of_intersection( + T&& t + ) SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::darkroom::access::get<2>(sprout::forward(t)))) + -> decltype(sprout::darkroom::access::get<2>(sprout::forward(t))) + { + return sprout::darkroom::access::get<2>(sprout::forward(t)); + } + template + SPROUT_CONSTEXPR auto normal( + T&& t + ) SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::darkroom::access::get<3>(sprout::forward(t)))) + -> decltype(sprout::darkroom::access::get<3>(sprout::forward(t))) + { + return sprout::darkroom::access::get<3>(sprout::forward(t)); + } + template + SPROUT_CONSTEXPR auto material( + T&& t + ) SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::darkroom::access::get<4>(sprout::forward(t)))) + -> decltype(sprout::darkroom::access::get<4>(sprout::forward(t))) + { + return sprout::darkroom::access::get<4>(sprout::forward(t)); + } + + // + // make_intersection + // + template + SPROUT_CONSTEXPR sprout::tuples::tuple + make_intersection(bool b, Distance const& dist, Point const& p, Normal const& nor, Material const& mat) { + return sprout::tuples::make_tuple(b, dist, p, nor, mat); + } + + // + // intersection + // + typedef sprout::tuples::tuple< + bool, + double, + sprout::darkroom::coords::vector3d, + sprout::darkroom::coords::vector3d, + sprout::darkroom::materials::material + > intersection; + } // namespace intersects + } // namespace darkroom +} // namespace sprout + +#endif // #ifndef SPROUT_DARKROOM_INTERSECTS_INTERSECTION_HPP diff --git a/sprout/darkroom/lights.hpp b/sprout/darkroom/lights.hpp new file mode 100644 index 00000000..aee6dc02 --- /dev/null +++ b/sprout/darkroom/lights.hpp @@ -0,0 +1,7 @@ +#ifndef SPROUT_DARKROOM_LIGHTS_HPP +#define SPROUT_DARKROOM_LIGHTS_HPP + +#include +#include + +#endif // #ifndef SPROUT_DARKROOM_LIGHTS_HPP diff --git a/sprout/darkroom/lights/point_light.hpp b/sprout/darkroom/lights/point_light.hpp new file mode 100644 index 00000000..59637475 --- /dev/null +++ b/sprout/darkroom/lights/point_light.hpp @@ -0,0 +1,169 @@ +#ifndef SPROUT_DARKROOM_LIGHTS_POINT_LIGHT_HPP +#define SPROUT_DARKROOM_LIGHTS_POINT_LIGHT_HPP + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include HDR_ALGORITHM_SSCRISK_CEL_OR_SPROUT_DETAIL + +namespace sprout { + namespace darkroom { + namespace lights { + // + // basic_point_light + // + template< + typename Position = sprout::darkroom::coords::vector3d, + typename Color = sprout::darkroom::colors::rgb_f + > + class basic_point_light { + public: + typedef Position position_type; + typedef typename sprout::darkroom::access::unit::type unit_type; + typedef Color color_type; + private: + position_type pos_; + color_type col_; + private: + template + SPROUT_CONSTEXPR color_type shade_4( + Intersection const& inter, + unit_type const& intensity + ) const + { + return sprout::tuples::remake_clone( + col_, + sprout::darkroom::colors::r(col_) + * sprout::darkroom::colors::r( + sprout::darkroom::materials::color( + sprout::darkroom::intersects::material(inter) + ) + ) + * intensity + , + sprout::darkroom::colors::g(col_) + * sprout::darkroom::colors::g( + sprout::darkroom::materials::color( + sprout::darkroom::intersects::material(inter) + ) + ) + * intensity + , + sprout::darkroom::colors::b(col_) + * sprout::darkroom::colors::b( + sprout::darkroom::materials::color( + sprout::darkroom::intersects::material(inter) + ) + ) + * intensity + ); + } + template + SPROUT_CONSTEXPR color_type shade_3( + Intersection const& inter, + position_type const& diff, + position_type const& direction, + LightRayIntersection const& light_ray_inter + ) const + { + return shade_4( + inter, + !sprout::darkroom::intersects::does_intersect(light_ray_inter) + || sprout::darkroom::intersects::distance(light_ray_inter) + > sprout::darkroom::coords::length(diff) + || sprout::darkroom::intersects::distance(light_ray_inter) + < std::numeric_limits::epsilon() + ? NS_SSCRISK_CEL_OR_SPROUT_DETAIL::max( + std::numeric_limits::epsilon(), + sprout::darkroom::coords::dot( + direction, + sprout::darkroom::intersects::normal(inter) + ) + / (sprout::darkroom::coords::length(diff) + 1) + ) + : 0 + ); + } + template + SPROUT_CONSTEXPR color_type shade_2( + Intersection const& inter, + Objects const& objs, + position_type const& diff, + position_type const& direction + ) const + { + return shade_3( + inter, + diff, + direction, + sprout::darkroom::objects::intersect_list( + objs, + sprout::darkroom::rays::make_ray( + sprout::darkroom::coords::add( + sprout::darkroom::coords::scale( + direction, + std::numeric_limits::epsilon() * 256 + ), + sprout::darkroom::intersects::point_of_intersection(inter) + ), + direction + ) + ) + ); + } + template + SPROUT_CONSTEXPR color_type shade_1( + Intersection const& inter, + Objects const& objs, + position_type const& diff + ) const + { + return shade_2( + inter, + objs, + diff, + sprout::darkroom::coords::normalize(diff) + ); + } + public: + SPROUT_CONSTEXPR basic_point_light( + position_type const& pos, + color_type const& col + ) + : pos_(pos) + , col_(col) + {} + template + SPROUT_CONSTEXPR color_type operator()(Intersection const& inter, Objects const& objs) const { + return shade_1( + inter, + objs, + sprout::darkroom::coords::sub( + pos_, + sprout::darkroom::intersects::point_of_intersection(inter) + ) + ); + } + }; + // + // make_point_light + // + template + SPROUT_CONSTEXPR inline sprout::darkroom::lights::basic_point_light + make_point_light(Position const& pos, Color const& col) { + return sprout::darkroom::lights::basic_point_light(pos, col); + } + } // namespace lights + } // namespace darkroom +} // namespace sprout + +#endif // #ifndef SPROUT_DARKROOM_LIGHTS_POINT_LIGHT_HPP diff --git a/sprout/darkroom/materials.hpp b/sprout/darkroom/materials.hpp new file mode 100644 index 00000000..f9c21c68 --- /dev/null +++ b/sprout/darkroom/materials.hpp @@ -0,0 +1,7 @@ +#ifndef SPROUT_DARKROOM_MATERIALS_HPP +#define SPROUT_DARKROOM_MATERIALS_HPP + +#include +#include + +#endif // #ifndef SPROUT_DARKROOM_MATERIALS_HPP diff --git a/sprout/darkroom/materials/material.hpp b/sprout/darkroom/materials/material.hpp new file mode 100644 index 00000000..54d8455a --- /dev/null +++ b/sprout/darkroom/materials/material.hpp @@ -0,0 +1,84 @@ +#ifndef SPROUT_DARKROOM_MATERIALS_MATERIAL_HPP +#define SPROUT_DARKROOM_MATERIALS_MATERIAL_HPP + +#include +#include +#include +#include +#include + +namespace sprout { + namespace darkroom { + namespace materials { + // + // color + // reflection + // + template + SPROUT_CONSTEXPR auto color( + T&& t + ) SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::darkroom::access::get<0>(sprout::forward(t)))) + -> decltype(sprout::darkroom::access::get<0>(sprout::forward(t))) + { + return sprout::darkroom::access::get<0>(sprout::forward(t)); + } + template + SPROUT_CONSTEXPR auto reflection( + T&& t + ) SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::darkroom::access::get<1>(sprout::forward(t)))) + -> decltype(sprout::darkroom::access::get<1>(sprout::forward(t))) + { + return sprout::darkroom::access::get<1>(sprout::forward(t)); + } + + // + // calc_color + // calc_reflection + // + template + SPROUT_CONSTEXPR auto calc_color(Image&& t, Position const&, Normal const&) SPROUT_NOEXCEPT + -> decltype(t) + { + return t; + } + template + SPROUT_CONSTEXPR auto calc_reflection(Image&& t, Position const&, Normal const&) SPROUT_NOEXCEPT + -> decltype(t) + { + return t; + } + + // + // calc_material + // + template + SPROUT_CONSTEXPR auto calc_material(Material const& mat, Position const& pos, Normal const& nor) + -> decltype(sprout::tuples::make_tuple( + sprout::darkroom::materials::calc_color(sprout::darkroom::materials::color(mat), pos, nor), + sprout::darkroom::materials::calc_reflection(sprout::darkroom::materials::reflection(mat), pos, nor) + )) + { + return sprout::tuples::make_tuple( + sprout::darkroom::materials::calc_color(sprout::darkroom::materials::color(mat), pos, nor), + sprout::darkroom::materials::calc_reflection(sprout::darkroom::materials::reflection(mat), pos, nor) + ); + } + + // + // make_material_image + // + template + SPROUT_CONSTEXPR sprout::tuples::tuple + make_material_image(ColorImage const& col, ReflectionImage const& ref) { + return sprout::tuples::make_tuple(col, ref); + } + + // + // material + // + typedef sprout::tuples::tuple material; + } // namespace materials + } // namespace darkroom +} // namespace sprout + +#endif // #ifndef SPROUT_DARKROOM_MATERIALS_MATERIAL_HPP diff --git a/sprout/darkroom/objects.hpp b/sprout/darkroom/objects.hpp new file mode 100644 index 00000000..343a2198 --- /dev/null +++ b/sprout/darkroom/objects.hpp @@ -0,0 +1,8 @@ +#ifndef SPROUT_DARKROOM_OBJECTS_HPP +#define SPROUT_DARKROOM_OBJECTS_HPP + +#include +#include +#include + +#endif // #ifndef SPROUT_DARKROOM_OBJECTS_HPP diff --git a/sprout/darkroom/objects/intersect.hpp b/sprout/darkroom/objects/intersect.hpp new file mode 100644 index 00000000..452a2b0b --- /dev/null +++ b/sprout/darkroom/objects/intersect.hpp @@ -0,0 +1,76 @@ +#ifndef SPROUT_DARKROOM_OBJECTS_INTERSECT_HPP +#define SPROUT_DARKROOM_OBJECTS_INTERSECT_HPP + +#include +#include +#include +#include + +namespace sprout { + namespace darkroom { + namespace objects { + // + // intersect + // + template + SPROUT_CONSTEXPR inline typename Object::template intersection::type + intersect(Object const& obj, Ray const& ray) { + return obj.intersect(ray); + } + + // + // intersect_list + // + namespace detail { + template + struct intersect_list_impl { + private: + template + SPROUT_CONSTEXPR typename sprout::darkroom::access::unit::type + ::template intersection::type + comp(A const& a, B const& b) const { + return sprout::darkroom::intersects::does_intersect(a) + && sprout::darkroom::intersects::does_intersect(b) + ? sprout::darkroom::intersects::distance(a) < sprout::darkroom::intersects::distance(b) + ? a + : b + : sprout::darkroom::intersects::does_intersect(a) + ? a + : b + ; + } + public: + template + SPROUT_CONSTEXPR typename sprout::darkroom::access::unit::type + ::template intersection::type + operator()(Objects const& objs, Ray const& ray) const { + return comp( + sprout::darkroom::objects::intersect(sprout::darkroom::access::get(objs), ray), + intersect_list_impl()(objs, ray) + ); + } + }; + template<> + struct intersect_list_impl<0> { + public: + template + SPROUT_CONSTEXPR typename sprout::darkroom::access::unit::type + ::template intersection::type + operator()(Objects const& objs, Ray const& ray) const { + return sprout::darkroom::objects::intersect(sprout::darkroom::access::get<0>(objs), ray); + } + }; + } // namespace detail + template + SPROUT_CONSTEXPR inline typename sprout::darkroom::access::unit::type + ::template intersection::type + intersect_list(Objects const& objs, Ray const& ray) { + return sprout::darkroom::objects::detail::intersect_list_impl< + sprout::darkroom::access::size::value - 1 + >()(objs, ray); + } + } // namespace objects + } // namespace darkroom +} // namespace sprout + +#endif // #ifndef SPROUT_DARKROOM_OBJECTS_INTERSECT_HPP diff --git a/sprout/darkroom/objects/sphere.hpp b/sprout/darkroom/objects/sphere.hpp new file mode 100644 index 00000000..1022865c --- /dev/null +++ b/sprout/darkroom/objects/sphere.hpp @@ -0,0 +1,244 @@ +#ifndef SPROUT_DARKROOM_OBJECTS_SPHERE_HPP +#define SPROUT_DARKROOM_OBJECTS_SPHERE_HPP + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace sprout { + namespace darkroom { + namespace objects { + // + // basic_sphere + // + template + class basic_sphere { + public: + typedef Material material_type; + typedef Position position_type; + typedef typename sprout::darkroom::access::unit::type unit_type; + typedef unit_type radius_type; + public: + template + struct intersection { + typedef sprout::tuples::tuple< + bool, + unit_type, + position_type, + position_type, + decltype(sprout::darkroom::materials::calc_material( + std::declval(), + std::declval(), + std::declval() + )) + > type; + }; + private: + typedef sprout::tuples::tuple zwo_type; + typedef sprout::tuples::tuple drei_type; + struct zw { + SPROUT_STATIC_CONSTEXPR std::size_t hit_side = 0; + SPROUT_STATIC_CONSTEXPR std::size_t does_intersect = 1; + SPROUT_STATIC_CONSTEXPR std::size_t distance = 2; + }; + struct dr { + SPROUT_STATIC_CONSTEXPR std::size_t point_of_intersection = 0; + SPROUT_STATIC_CONSTEXPR std::size_t normal = 1; + }; + private: + position_type pos_; + radius_type rad_; + material_type mat_; + private: + template + SPROUT_CONSTEXPR zwo_type zweitens_2( + Ray const& ray, + unit_type const& i1, + unit_type const& i2, + int hit_side, + bool does_intersect + ) const + { + return zwo_type( + hit_side, + does_intersect, + hit_side < 0 ? i2 + : hit_side > 0 ? i1 + : -1 + ); + } + template + SPROUT_CONSTEXPR zwo_type zweitens_1( + Ray const& ray, + unit_type const& i1, + unit_type const& i2 + ) const + { + return zweitens_2( + ray, + i1, + i2, + i2 > 0 + ? i1 < 0 ? -1 : 1 + : 0 + , + i2 > 0 + ); + } + template + SPROUT_CONSTEXPR zwo_type zweitens( + Ray const& ray, + bool neg, + unit_type const& b, + unit_type const& det + ) const + { + return neg + ? zweitens_1(ray, b - det, b + det) + : zwo_type(0, false, -1) + ; + } + template + SPROUT_CONSTEXPR drei_type drittens_1( + Ray const& ray, + typename sprout::darkroom::access::unit::type point_of_intersection + ) const + { + return drei_type( + point_of_intersection, + sprout::darkroom::coords::normalize( + sprout::darkroom::coords::sub(point_of_intersection, pos_) + ) + ); + } + template + SPROUT_CONSTEXPR drei_type drittens( + Ray const& ray, + bool neg, + unit_type const& distance + ) const + { + return neg + ? drittens_1(ray, sprout::darkroom::rays::point_of_intersection(ray, distance)) + : drei_type( + sprout::tuples::make_clone(0, 0, 0), + sprout::tuples::make_clone(1, 1, 1) + ) + ; + } + template + SPROUT_CONSTEXPR typename intersection::type intersect_5( + Ray const& ray, + zwo_type const& zwo, + drei_type const& drei + ) const + { + return typename intersection::type( + sprout::tuples::get(zwo), + sprout::tuples::get(zwo), + sprout::tuples::get(drei), + sprout::tuples::get(drei), + sprout::darkroom::materials::calc_material( + mat_, + sprout::tuples::get(drei), + sprout::tuples::get(drei) + ) + ); + } + template + SPROUT_CONSTEXPR typename intersection::type intersect_4( + Ray const& ray, + zwo_type const& zwo + ) const + { + return intersect_5( + ray, + zwo, + drittens( + ray, + sprout::tuples::get(zwo), + sprout::tuples::get(zwo) + ) + ); + } + template + SPROUT_CONSTEXPR typename intersection::type intersect_3( + Ray const& ray, + unit_type const& b, + unit_type const& det_sq + ) const + { + using std::sqrt; + return intersect_4( + ray, + zweitens( + ray, + det_sq > 0, + b, + sqrt(det_sq) + ) + ); + } + template + SPROUT_CONSTEXPR typename intersection::type intersect_2( + Ray const& ray, + position_type const& v, + unit_type const& b + ) const + { + return intersect_3( + ray, + b, + b * b - sprout::darkroom::coords::length_sq(v) + rad_ * rad_ + ); + } + template + SPROUT_CONSTEXPR typename intersection::type intersect_1( + Ray const& ray, + position_type const& v + ) const + { + return intersect_2( + ray, + v, + -sprout::darkroom::coords::dot(v, sprout::darkroom::rays::direction(ray)) + ); + } + public: + SPROUT_CONSTEXPR basic_sphere( + position_type const& pos, + radius_type rad, + material_type const& mat + ) + : pos_(pos) + , rad_(rad) + , mat_(mat) + {}; + template + SPROUT_CONSTEXPR typename intersection::type intersect(Ray const& ray) const { + return intersect_1( + ray, + sprout::darkroom::coords::sub(sprout::darkroom::rays::position(ray), pos_) + ); + } + }; + // + // make_sphere + // + template + SPROUT_CONSTEXPR inline sprout::darkroom::objects::basic_sphere + make_sphere(Position const& pos, Radius const& rad, Material const& mat) { + return sprout::darkroom::objects::basic_sphere(pos, rad, mat); + } + } // namespace objects + } // namespace darkroom +} // namespace sprout + +#endif // #ifndef SPROUT_DARKROOM_OBJECTS_SPHERE_HPP diff --git a/sprout/darkroom/pixels.hpp b/sprout/darkroom/pixels.hpp new file mode 100644 index 00000000..21892570 --- /dev/null +++ b/sprout/darkroom/pixels.hpp @@ -0,0 +1,7 @@ +#ifndef SPROUT_DARKROOM_PIXELS_HPP +#define SPROUT_DARKROOM_PIXELS_HPP + +#include +#include + +#endif // #ifndef SPROUT_DARKROOM_PIXELS_HPP diff --git a/sprout/darkroom/pixels/generate.hpp b/sprout/darkroom/pixels/generate.hpp new file mode 100644 index 00000000..ef8dd666 --- /dev/null +++ b/sprout/darkroom/pixels/generate.hpp @@ -0,0 +1,187 @@ +#ifndef SPROUT_DARKROOM_PIXELS_GENERATE_HPP +#define SPROUT_DARKROOM_PIXELS_GENERATE_HPP + +#include +#include +#include +#include +#include +#include +#include + +namespace sprout { + namespace darkroom { + namespace pixels { + // + // generate + // + namespace detail { + template< + typename Pixels, + typename RayTracer, + typename Renderer, + typename Camera, + typename Objects, + typename Lights, + std::ptrdiff_t... XIndexes + > + SPROUT_CONSTEXPR inline typename sprout::fixed_container_traits::value_type + generate_impl_line( + RayTracer const& raytracer, + Renderer const& renderer, + Camera const& camera, + Objects const& objs, + Lights const& lights, + typename sprout::fixed_container_traits< + typename sprout::fixed_container_traits::value_type + >::size_type x + , + typename sprout::fixed_container_traits::size_type y, + typename sprout::fixed_container_traits< + typename sprout::fixed_container_traits::value_type + >::size_type width + , + typename sprout::fixed_container_traits::size_type height, + std::size_t depth_max, + sprout::index_tuple + ) + { + typedef typename sprout::fixed_container_traits::value_type pixel_line_type; + typedef typename sprout::fixed_container_traits::value_type pixel_type; + return sprout::make_clone( + sprout::darkroom::colors::rgb_f_to_rgb( + raytracer.template operator()( + renderer, + camera, + objs, + lights, + x + XIndexes, + y, + width, + height, + depth_max + ) + )... + ); + } + template< + typename Pixels, + typename RayTracer, + typename Renderer, + typename Camera, + typename Objects, + typename Lights, + std::ptrdiff_t... YIndexes + > + SPROUT_CONSTEXPR inline Pixels + generate_impl( + RayTracer const& raytracer, + Renderer const& renderer, + Camera const& camera, + Objects const& objs, + Lights const& lights, + typename sprout::fixed_container_traits< + typename sprout::fixed_container_traits::value_type + >::size_type x + , + typename sprout::fixed_container_traits::size_type y, + typename sprout::fixed_container_traits< + typename sprout::fixed_container_traits::value_type + >::size_type width + , + typename sprout::fixed_container_traits::size_type height, + std::size_t depth_max, + sprout::index_tuple + ) + { + return sprout::make_clone( + sprout::darkroom::pixels::detail::generate_impl_line( + raytracer, + renderer, + camera, + objs, + lights, + x, + y + YIndexes, + width, + height, + depth_max, + typename sprout::index_range< + 0, + sprout::fixed_container_traits< + typename sprout::fixed_container_traits::value_type + >::fixed_size + >::type() + )... + ); + } + } // namespace detail + template< + typename Pixels, + typename RayTracer, + typename Renderer, + typename Camera, + typename Objects, + typename Lights + > + SPROUT_CONSTEXPR inline Pixels generate( + RayTracer const& raytracer, + Renderer const& renderer, + Camera const& camera, + Objects const& objs, + Lights const& lights, + typename sprout::fixed_container_traits< + typename sprout::fixed_container_traits::value_type + >::size_type x + = 0 + , + typename sprout::fixed_container_traits::size_type y + = 0 + , + typename sprout::fixed_container_traits< + typename sprout::fixed_container_traits::value_type + >::size_type width + = sprout::fixed_container_traits< + typename sprout::fixed_container_traits::value_type + >::fixed_size + , + typename sprout::fixed_container_traits::size_type height + = sprout::fixed_container_traits::fixed_size + , + std::size_t depth_max = 8 + ) + { + return sprout::darkroom::pixels::detail::generate_impl( + raytracer, + renderer, + camera, + objs, + lights, + x, + y, + width, + height, + depth_max, + typename sprout::index_range< + 0, + sprout::fixed_container_traits::fixed_size + >::type() + ); + } + + // + // color_pixels + // + template + struct color_pixels { + public: + typedef sprout::array< + sprout::array, + Height + > type; + }; + } // namespace pixels + } // namespace darkroom +} // namespace sprout + +#endif // #ifndef SPROUT_DARKROOM_PIXELS_GENERATE_HPP diff --git a/sprout/darkroom/rays.hpp b/sprout/darkroom/rays.hpp new file mode 100644 index 00000000..9c79389c --- /dev/null +++ b/sprout/darkroom/rays.hpp @@ -0,0 +1,7 @@ +#ifndef SPROUT_DARKROOM_RAYS_HPP +#define SPROUT_DARKROOM_RAYS_HPP + +#include +#include + +#endif // #ifndef SPROUT_DARKROOM_RAYS_HPP diff --git a/sprout/darkroom/rays/ray.hpp b/sprout/darkroom/rays/ray.hpp new file mode 100644 index 00000000..968ce4c7 --- /dev/null +++ b/sprout/darkroom/rays/ray.hpp @@ -0,0 +1,63 @@ +#ifndef SPROUT_DARKROOM_RAYS_RAY_HPP +#define SPROUT_DARKROOM_RAYS_RAY_HPP + +#include +#include +#include +#include +#include + +namespace sprout { + namespace darkroom { + namespace rays { + // + // position + // direction + // + template + SPROUT_CONSTEXPR auto position( + T&& t + ) SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::darkroom::access::get<0>(sprout::forward(t)))) + -> decltype(sprout::darkroom::access::get<0>(sprout::forward(t))) + { + return sprout::darkroom::access::get<0>(sprout::forward(t)); + } + template + SPROUT_CONSTEXPR auto direction( + T&& t + ) SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::darkroom::access::get<1>(sprout::forward(t)))) + -> decltype(sprout::darkroom::access::get<1>(sprout::forward(t))) + { + return sprout::darkroom::access::get<1>(sprout::forward(t)); + } + + // + // make_ray + // + template + SPROUT_CONSTEXPR sprout::tuples::tuple + make_ray(Position const& pos, Direction const& dir) { + return sprout::tuples::make_tuple(pos, dir); + } + + // + // ray + // + typedef sprout::tuples::tuple ray; + + // + // point_of_intersection + // + template + SPROUT_CONSTEXPR inline typename sprout::darkroom::access::unit::type + point_of_intersection(Ray const& ray, Distance const& dist) { + return sprout::darkroom::coords::add( + sprout::darkroom::rays::position(ray), + sprout::darkroom::coords::scale(sprout::darkroom::rays::direction(ray), dist) + ); + } + } // namespace ray + } // namespace darkroom +} // namespace sprout + +#endif // #ifndef SPROUT_DARKROOM_RAYS_RAY_HPP diff --git a/sprout/darkroom/renderers.hpp b/sprout/darkroom/renderers.hpp new file mode 100644 index 00000000..9871c828 --- /dev/null +++ b/sprout/darkroom/renderers.hpp @@ -0,0 +1,7 @@ +#ifndef SPROUT_DARKROOM_RENDERERS_HPP +#define SPROUT_DARKROOM_RENDERERS_HPP + +#include +#include + +#endif // #ifndef SPROUT_DARKROOM_RENDERERS_HPP diff --git a/sprout/darkroom/renderers/whitted_style.hpp b/sprout/darkroom/renderers/whitted_style.hpp new file mode 100644 index 00000000..9d8cc8b7 --- /dev/null +++ b/sprout/darkroom/renderers/whitted_style.hpp @@ -0,0 +1,237 @@ +#ifndef SPROUT_DARKROOM_RENDERERS_WHITTED_STYLE_HPP +#define SPROUT_DARKROOM_RENDERERS_WHITTED_STYLE_HPP + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace sprout { + namespace darkroom { + namespace renderers { + // + // whitted_mirror + // + class whitted_mirror { + private: + template< + typename Color, + typename Camera, + typename Objects, + typename Lights, + typename Ray, + typename Intersection, + typename Tracer, + typename Direction + > + SPROUT_CONSTEXPR Color color_1( + Camera const& camera, + Objects const& objs, + Lights const& lights, + Ray const& ray, + Intersection const& inter, + Tracer const& tracer, + std::size_t depth_max, + Direction const& reflect_dir + ) const + { + return tracer.template operator()( + camera, + objs, + lights, + sprout::tuples::remake_clone( + ray, + sprout::darkroom::coords::add( + sprout::darkroom::intersects::point_of_intersection(inter), + sprout::darkroom::coords::scale( + reflect_dir, + std::numeric_limits::type>::epsilon() * 256 + ) + // !!! +// sprout::darkroom::coords::scale( +// sprout::darkroom::intersects::normal(inter), +// std::numeric_limits::type>::epsilon() * 256 +// ) + ), + reflect_dir + ), + depth_max - 1 + ); + } + public: + template< + typename Color, + typename Camera, + typename Objects, + typename Lights, + typename Ray, + typename Intersection, + typename Tracer + > + SPROUT_CONSTEXPR Color operator()( + Camera const& camera, + Objects const& objs, + Lights const& lights, + Ray const& ray, + Intersection const& inter, + Tracer const& tracer, + std::size_t depth_max + ) const + { + typedef typename std::decay< + decltype(sprout::darkroom::materials::reflection(sprout::darkroom::intersects::material(inter))) + >::type reflection_type; + return depth_max > 0 + && sprout::darkroom::intersects::does_intersect(inter) + && sprout::darkroom::materials::reflection(sprout::darkroom::intersects::material(inter)) + > std::numeric_limits::epsilon() + ? color_1( + camera, + objs, + lights, + ray, + inter, + tracer, + depth_max, + sprout::darkroom::coords::reflect( + sprout::darkroom::rays::direction(ray), + sprout::darkroom::intersects::normal(inter) + ) + ) + : sprout::tuples::make_clone(0, 0, 0) + ; + } + }; + // + // whitted_style + // + class whitted_style { + private: + template< + typename Color, + typename Ray, + typename Intersection + > + SPROUT_CONSTEXPR Color color_3( + Ray const& ray, + Intersection const& inter, + Color const& diffuse_color, + Color const& mirror_color + ) const + { + return sprout::darkroom::intersects::does_intersect(inter) + ? sprout::darkroom::colors::add( + sprout::darkroom::colors::mul( + diffuse_color, + 1 - sprout::darkroom::materials::reflection(sprout::darkroom::intersects::material(inter)) + ), + sprout::darkroom::colors::mul( + sprout::darkroom::colors::filter( + sprout::darkroom::materials::color(sprout::darkroom::intersects::material(inter)), + mirror_color + ), + sprout::darkroom::materials::reflection(sprout::darkroom::intersects::material(inter)) + ) + ) + : sprout::darkroom::coords::normal_to_color(sprout::darkroom::rays::direction(ray)) + ; + } + template< + typename Color, + typename Camera, + typename Objects, + typename Lights, + typename Ray, + typename Intersection + > + SPROUT_CONSTEXPR Color color_2( + Camera const& camera, + Objects const& objs, + Lights const& lights, + Ray const& ray, + std::size_t depth_max, + Intersection const& inter, + Color const& diffuse_color + ) const + { + return color_3( + ray, + inter, + diffuse_color, + sprout::darkroom::renderers::whitted_mirror().template operator()( + camera, + objs, + lights, + ray, + inter, + *this, + depth_max + ) + ); + } + template< + typename Color, + typename Camera, + typename Objects, + typename Lights, + typename Ray, + typename Intersection + > + SPROUT_CONSTEXPR Color color_1( + Camera const& camera, + Objects const& objs, + Lights const& lights, + Ray const& ray, + std::size_t depth_max, + Intersection const& inter + ) const + { + return color_2( + camera, + objs, + lights, + ray, + depth_max, + inter, + lights.template operator()(inter, objs) + ); + } + public: + template< + typename Color, + typename Camera, + typename Objects, + typename Lights, + typename Ray + > + SPROUT_CONSTEXPR Color operator()( + Camera const& camera, + Objects const& objs, + Lights const& lights, + Ray const& ray, + std::size_t depth_max + ) const + { + return color_1( + camera, + objs, + lights, + ray, + depth_max, + sprout::darkroom::objects::intersect_list(objs, ray) + ); + } + }; + } // namespace renderers + } // namespace darkroom +} // namespace sprout + +#endif // #ifndef SPROUT_DARKROOM_RENDERERS_WHITTED_STYLE_HPP diff --git a/sprout/darkroom/tracers.hpp b/sprout/darkroom/tracers.hpp new file mode 100644 index 00000000..e5e15885 --- /dev/null +++ b/sprout/darkroom/tracers.hpp @@ -0,0 +1,7 @@ +#ifndef SPROUT_DARKROOM_TRACERS_HPP +#define SPROUT_DARKROOM_TRACERS_HPP + +#include +#include + +#endif // #ifndef SPROUT_DARKROOM_TRACERS_HPP diff --git a/sprout/darkroom/tracers/raytracer.hpp b/sprout/darkroom/tracers/raytracer.hpp new file mode 100644 index 00000000..a351a80c --- /dev/null +++ b/sprout/darkroom/tracers/raytracer.hpp @@ -0,0 +1,54 @@ +#ifndef SPROUT_DARKROOM_TRACERS_RAYTRACER_HPP +#define SPROUT_DARKROOM_TRACERS_RAYTRACER_HPP + +#include +#include +#include + +namespace sprout { + namespace darkroom { + namespace tracers { + // + // raytracer + // + template + class raytracer { + public: + typedef Color color_type; + public: + template< + typename Renderer, + typename Camera, + typename Objects, + typename Lights, + typename Unit + > + SPROUT_CONSTEXPR color_type operator()( + Renderer const& renderer, + Camera const& camera, + Objects const& objs, + Lights const& lights, + Unit const& x, + Unit const& y, + Unit const& width, + Unit const& height, + std::size_t depth_max = 8 + ) const + { + return renderer.template operator()( + camera, + objs, + lights, + camera.template operator()( + static_cast(x) / width - 0.5, + static_cast(y) / height - 0.5 + ), + depth_max + ); + } + }; + } // namespace tracers + } // namespace darkroom +} // namespace sprout + +#endif // #ifndef SPROUT_DARKROOM_TRACERS_RAYTRACER_HPP diff --git a/sprout/tuple/tuple.hpp b/sprout/tuple/tuple.hpp index aa5c1242..aa2452b5 100644 --- a/sprout/tuple/tuple.hpp +++ b/sprout/tuple/tuple.hpp @@ -129,7 +129,7 @@ namespace sprout { : inherited_type() , base_type() {} - SPROUT_CONSTEXPR explicit tuple_impl(const Head& h, Tail const&... tail) + SPROUT_CONSTEXPR explicit tuple_impl(Head const& h, Tail const&... tail) : inherited_type(tail...) , base_type(h) {} @@ -215,10 +215,15 @@ namespace sprout { : inherited_type(elements...) {} template - SPROUT_CONSTEXPR explicit tuple(UTypes&&... elements) - : inherited_type(sprout::forward(elements)...) + SPROUT_CONSTEXPR explicit tuple(UTypes const&... elements) + : inherited_type(elements...) {} - SPROUT_CONSTEXPR tuple(tuple const &) = default; + // !!! +// template +// SPROUT_CONSTEXPR explicit tuple(UTypes&&... elements) +// : inherited_type(sprout::forward(elements)...) +// {} + SPROUT_CONSTEXPR tuple(tuple const&) = default; SPROUT_CONSTEXPR tuple(tuple&&) = default; template SPROUT_CONSTEXPR tuple(sprout::tuples::tuple const& t)