From 014d339803cd937d0caf034bbd0a1b6656b26366 Mon Sep 17 00:00:00 2001 From: bolero-MURAKAMI Date: Tue, 3 Dec 2013 22:17:49 +0900 Subject: [PATCH] fix darkroom: add alpha and refraction material parameter --- example/darkroom/two_spheres.hpp | 12 +- sprout/darkroom/colors/rgb.hpp | 30 +++- sprout/darkroom/intersects/intersection.hpp | 62 ++++++-- sprout/darkroom/materials/material.hpp | 149 +++++++++++++++++--- sprout/darkroom/materials/plaid.hpp | 73 ++++++---- sprout/darkroom/materials/uniform.hpp | 10 +- sprout/utility/pack.hpp | 8 +- 7 files changed, 263 insertions(+), 81 deletions(-) diff --git a/example/darkroom/two_spheres.hpp b/example/darkroom/two_spheres.hpp index cd2fa5e5..d194a582 100644 --- a/example/darkroom/two_spheres.hpp +++ b/example/darkroom/two_spheres.hpp @@ -21,26 +21,22 @@ namespace darkcult { objects::aa_plane_direction::y, -2.0, materials::make_plaid_material_image( - colors::rgb_f(1.0, 0.0, 0.0), - colors::rgb_f(1.0, 1.0, 0.0), - 0.0, - 0.0 + colors::rgb_f(1.0, 0.0, 0.0), colors::rgb_f(1.0, 1.0, 0.0), + 0.0, 0.0 ) ), objects::make_sphere( coords::vector3d(-1.0, 0.5, 7.5), 2.5, materials::make_uniform_material_image( - colors::rgb_f(0.0, 0.0, 1.0), - 0.2 + colors::rgb_f(0.0, 0.0, 1.0), 0.2 ) ), objects::make_sphere( coords::vector3d(1.0, -1.0, 4.0), 1.0, materials::make_uniform_material_image( - colors::rgb_f(0.0, 1.0, 0.0), - 0.2 + colors::rgb_f(0.0, 1.0, 0.0), 0.2 ) ) ); diff --git a/sprout/darkroom/colors/rgb.hpp b/sprout/darkroom/colors/rgb.hpp index 43df547e..43cff05e 100644 --- a/sprout/darkroom/colors/rgb.hpp +++ b/sprout/darkroom/colors/rgb.hpp @@ -14,11 +14,21 @@ #include #include #include +#include +#include #include namespace sprout { namespace darkroom { namespace colors { + // + // has_alpha + // + template + struct has_alpha + : public sprout::integral_constant::value >= 4)> + {}; + // // r // g @@ -49,7 +59,13 @@ namespace sprout { { return sprout::darkroom::access::get<2>(sprout::forward(t)); } - template + // + // a + // + template< + typename T, + typename sprout::enabler_if::value>::type = sprout::enabler + > inline SPROUT_CONSTEXPR auto a(T&& t) SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::darkroom::access::get<3>(sprout::forward(t)))) @@ -57,13 +73,22 @@ namespace sprout { { return sprout::darkroom::access::get<3>(sprout::forward(t)); } + template< + typename T, + typename sprout::enabler_if::value>::type = sprout::enabler + > + inline SPROUT_CONSTEXPR typename sprout::darkroom::access::unit::type + a(T&&) + SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(typename sprout::darkroom::access::unit::type())) + { + return typename sprout::darkroom::access::unit::type(); + } // // rgb_t // rgb // typedef sprout::tuples::tuple rgb_t; - inline SPROUT_CONSTEXPR sprout::darkroom::colors::rgb_t rgb(std::uint8_t r = 0, std::uint8_t g = 0, std::uint8_t b = 0) { return sprout::darkroom::colors::rgb_t(r, g, b); @@ -74,7 +99,6 @@ namespace sprout { // rgb_f // typedef sprout::tuples::tuple rgb_f_t; - inline SPROUT_CONSTEXPR sprout::darkroom::colors::rgb_f_t rgb_f(double r = 0, double g = 0, double b = 0) { return sprout::darkroom::colors::rgb_f_t(r, g, b); diff --git a/sprout/darkroom/intersects/intersection.hpp b/sprout/darkroom/intersects/intersection.hpp index 235490a7..6e420303 100644 --- a/sprout/darkroom/intersects/intersection.hpp +++ b/sprout/darkroom/intersects/intersection.hpp @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -18,12 +19,33 @@ namespace sprout { namespace darkroom { namespace intersects { + // + // intersection + // + typedef sprout::tuples::tuple< + bool, + double, + sprout::darkroom::coords::vector3d_t, + sprout::darkroom::coords::vector3d_t, + sprout::darkroom::materials::material, + bool + > intersection; + + // + // has_is_from_inside + // + template + struct has_is_from_inside + : public sprout::integral_constant::value >= 6)> + {}; + // // does_intersect // distance // point_of_intersection // normal // material + // is_from_inside // template inline SPROUT_CONSTEXPR auto @@ -65,26 +87,36 @@ namespace sprout { { return sprout::darkroom::access::get<4>(sprout::forward(t)); } + template< + typename T, + typename sprout::enabler_if::value>::type = sprout::enabler + > + inline SPROUT_CONSTEXPR auto + is_from_inside(T&& t) + SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::darkroom::access::get<5>(sprout::forward(t)))) + -> decltype(sprout::darkroom::access::get<5>(sprout::forward(t))) + { + return sprout::darkroom::access::get<5>(sprout::forward(t)); + } + template< + typename T, + typename sprout::enabler_if::value>::type = sprout::enabler + > + inline SPROUT_CONSTEXPR typename sprout::darkroom::access::element<5, sprout::darkroom::intersects::intersection>::type + is_from_inside(T&&) + SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR((typename sprout::darkroom::access::element<5, sprout::darkroom::intersects::intersection>::type()))) + { + return typename sprout::darkroom::access::element<5, sprout::darkroom::intersects::intersection>::type(); + } // // make_intersection // - template - inline 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); + template + inline SPROUT_CONSTEXPR sprout::tuples::tuple + make_material_image(Elements const&... elems) { + return sprout::tuples::make_tuple(elems...); } - - // - // intersection - // - typedef sprout::tuples::tuple< - bool, - double, - sprout::darkroom::coords::vector3d_t, - sprout::darkroom::coords::vector3d_t, - sprout::darkroom::materials::material - > intersection; } // namespace intersects } // namespace darkroom } // namespace sprout diff --git a/sprout/darkroom/materials/material.hpp b/sprout/darkroom/materials/material.hpp index 23463438..02899930 100644 --- a/sprout/darkroom/materials/material.hpp +++ b/sprout/darkroom/materials/material.hpp @@ -8,9 +8,12 @@ #ifndef SPROUT_DARKROOM_MATERIALS_MATERIAL_HPP #define SPROUT_DARKROOM_MATERIALS_MATERIAL_HPP +#include #include #include +#include #include +#include #include #include #include @@ -19,10 +22,40 @@ namespace sprout { namespace darkroom { namespace materials { // - // color - // reflection + // material + // + typedef sprout::tuples::tuple material; + + // + // has_color + // has_reflection + // has_alpha + // has_refraction // template + struct has_color + : public sprout::integral_constant::value >= 1)> + {}; + template + struct has_reflection + : public sprout::integral_constant::value >= 2)> + {}; + template + struct has_alpha + : public sprout::integral_constant::value >= 3)> + {}; + template + struct has_refraction + : public sprout::integral_constant::value >= 4)> + {}; + + // + // color + // + template< + typename T, + typename sprout::enabler_if::type>::value>::type = sprout::enabler + > inline SPROUT_CONSTEXPR auto color(T&& t) SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::darkroom::access::get<0>(sprout::forward(t)))) @@ -30,7 +63,23 @@ namespace sprout { { return sprout::darkroom::access::get<0>(sprout::forward(t)); } - template + template< + typename T, + typename sprout::enabler_if::type>::value>::type = sprout::enabler + > + inline SPROUT_CONSTEXPR typename sprout::darkroom::access::element<0, sprout::darkroom::materials::material>::type + color(T&&) + SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR((typename sprout::darkroom::access::element<0, sprout::darkroom::materials::material>::type()))) + { + return typename sprout::darkroom::access::element<0, sprout::darkroom::materials::material>::type(); + } + // + // reflection + // + template< + typename T, + typename sprout::enabler_if::type>::value>::type = sprout::enabler + > inline SPROUT_CONSTEXPR auto reflection(T&& t) SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::darkroom::access::get<1>(sprout::forward(t)))) @@ -38,37 +87,97 @@ namespace sprout { { return sprout::darkroom::access::get<1>(sprout::forward(t)); } + template< + typename T, + typename sprout::enabler_if::type>::value>::type = sprout::enabler + > + inline SPROUT_CONSTEXPR typename sprout::darkroom::access::element<1, sprout::darkroom::materials::material>::type + reflection(T&&) + SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR((typename sprout::darkroom::access::element<1, sprout::darkroom::materials::material>::type()))) + { + return typename sprout::darkroom::access::element<1, sprout::darkroom::materials::material>::type(); + } + // + // alpha + // + template< + typename T, + typename sprout::enabler_if::type>::value>::type = sprout::enabler + > + inline SPROUT_CONSTEXPR auto + alpha(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< + typename T, + typename sprout::enabler_if::type>::value>::type = sprout::enabler + > + inline SPROUT_CONSTEXPR typename sprout::darkroom::access::element<2, sprout::darkroom::materials::material>::type + alpha(T&&) + SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR((typename sprout::darkroom::access::element<2, sprout::darkroom::materials::material>::type()))) + { + return typename sprout::darkroom::access::element<2, sprout::darkroom::materials::material>::type(); + } + // + // refraction + // + template< + typename T, + typename sprout::enabler_if::type>::value>::type = sprout::enabler + > + inline SPROUT_CONSTEXPR auto + refraction(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< + typename T, + typename sprout::enabler_if::type>::value>::type = sprout::enabler + > + inline SPROUT_CONSTEXPR typename sprout::darkroom::access::element<3, sprout::darkroom::materials::material>::type + refraction(T&&) + SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR((typename sprout::darkroom::access::element<3, sprout::darkroom::materials::material>::type()))) + { + return typename sprout::darkroom::access::element<1, sprout::darkroom::materials::material>::type(); + } // // calculate_material // + namespace detail { + template + inline SPROUT_CONSTEXPR auto + calculate_material_impl(Material const& mat, Unit const& u, Unit const& v, sprout::index_tuple) + -> decltype(sprout::tuples::make_tuple( + sprout::darkroom::materials::calculate(sprout::darkroom::access::get(mat), u, v)... + )) + { + return sprout::tuples::make_tuple( + sprout::darkroom::materials::calculate(sprout::darkroom::access::get(mat), u, v)... + ); + } + } // namespace detail template inline SPROUT_CONSTEXPR auto calculate_material(Material const& mat, Unit const& u, Unit const& v) - -> decltype(sprout::tuples::make_tuple( - sprout::darkroom::materials::calculate(sprout::darkroom::materials::color(mat), u, v), - sprout::darkroom::materials::calculate(sprout::darkroom::materials::reflection(mat), u, v) - )) + -> decltype(sprout::darkroom::materials::detail::calculate_material_impl(mat, u, v, sprout::tuples::tuple_indexes::make())) { - return sprout::tuples::make_tuple( - sprout::darkroom::materials::calculate(sprout::darkroom::materials::color(mat), u, v), - sprout::darkroom::materials::calculate(sprout::darkroom::materials::reflection(mat), u, v) - ); + return sprout::darkroom::materials::detail::calculate_material_impl(mat, u, v, sprout::tuples::tuple_indexes::make()); } // // make_material_image // - template - inline SPROUT_CONSTEXPR sprout::tuples::tuple - make_material_image(ColorImage const& col, ReflectionImage const& ref) { - return sprout::tuples::make_tuple(col, ref); + template + inline SPROUT_CONSTEXPR sprout::tuples::tuple + make_material_image(Images const&... images) { + return sprout::tuples::make_tuple(images...); } - - // - // material - // - typedef sprout::tuples::tuple material; } // namespace materials } // namespace darkroom } // namespace sprout diff --git a/sprout/darkroom/materials/plaid.hpp b/sprout/darkroom/materials/plaid.hpp index 7e7b4f35..207826dc 100644 --- a/sprout/darkroom/materials/plaid.hpp +++ b/sprout/darkroom/materials/plaid.hpp @@ -11,6 +11,9 @@ #include #include #include +#include +#include +#include #include namespace sprout { @@ -74,36 +77,56 @@ namespace sprout { // // make_plaid_material_image // - template - inline SPROUT_CONSTEXPR sprout::tuples::tuple< - sprout::darkroom::materials::plaid_element, - sprout::darkroom::materials::plaid_element + namespace detail { + template + inline SPROUT_CONSTEXPR auto + make_plaid_material_image_impl( + sprout::index_tuple, + Elements const&... elems + ) + -> decltype(sprout::tuples::make_tuple( + sprout::darkroom::materials::make_plaid(sprout::pack_get(elems...), sprout::pack_get(elems...))... + )) + { + return sprout::tuples::make_tuple( + sprout::darkroom::materials::make_plaid(sprout::pack_get(elems...), sprout::pack_get(elems...))... + ); + } + template + inline SPROUT_CONSTEXPR auto + make_plaid_material_image_impl( + Unit const& scale, + sprout::index_tuple, + Elements const&... elems + ) + -> decltype(sprout::tuples::make_tuple( + sprout::darkroom::materials::make_plaid(sprout::pack_get(elems...), sprout::pack_get(elems...), scale)... + )) + { + return sprout::tuples::make_tuple( + sprout::darkroom::materials::make_plaid(sprout::pack_get(elems...), sprout::pack_get(elems...), scale)... + ); + } + } // namespace detail + template< + typename... Elements, + typename sprout::enabler_if::type = sprout::enabler > - make_plaid_material_image( - Color const& col1, Color const& col2, - Reflection const& ref1, Reflection const& ref2 - ) + inline SPROUT_CONSTEXPR auto + make_plaid_material_image(Elements const&... elems) + -> decltype(sprout::darkroom::materials::detail::make_plaid_material_image_impl(sprout::make_index_tuple::make(), elems...)) { - return sprout::tuples::make_tuple( - sprout::darkroom::materials::make_plaid(col1, col2), - sprout::darkroom::materials::make_plaid(ref1, ref2) - ); + return sprout::darkroom::materials::detail::make_plaid_material_image_impl(sprout::make_index_tuple::make(), elems...); } - template - inline SPROUT_CONSTEXPR sprout::tuples::tuple< - sprout::darkroom::materials::plaid_element, - sprout::darkroom::materials::plaid_element + template< + typename Unit, typename... Elements, + typename sprout::enabler_if::type = sprout::enabler > - make_plaid_material_image( - Color const& col1, Color const& col2, - Reflection const& ref1, Reflection const& ref2, - Unit const& scale - ) + inline SPROUT_CONSTEXPR auto + make_plaid_material_image(Unit const& scale, Elements const&... elems) + -> decltype(sprout::darkroom::materials::detail::make_plaid_material_image_impl(scale, sprout::make_index_tuple::make(), elems...)) { - return sprout::tuples::make_tuple( - sprout::darkroom::materials::make_plaid(col1, col2, scale), - sprout::darkroom::materials::make_plaid(ref1, ref2, scale) - ); + return sprout::darkroom::materials::detail::make_plaid_material_image_impl(scale, sprout::make_index_tuple::make(), elems...); } } // namespace materials } // namespace darkroom diff --git a/sprout/darkroom/materials/uniform.hpp b/sprout/darkroom/materials/uniform.hpp index 5f634abd..ec93bb87 100644 --- a/sprout/darkroom/materials/uniform.hpp +++ b/sprout/darkroom/materials/uniform.hpp @@ -44,15 +44,13 @@ namespace sprout { // // make_uniform_material_image // - template + template inline SPROUT_CONSTEXPR sprout::tuples::tuple< - sprout::darkroom::materials::uniform_element, - sprout::darkroom::materials::uniform_element + sprout::darkroom::materials::uniform_element... > - make_uniform_material_image(Color const& col, Reflection const& ref) { + make_uniform_material_image(Elements const&... elems) { return sprout::tuples::make_tuple( - sprout::darkroom::materials::make_uniform(col), - sprout::darkroom::materials::make_uniform(ref) + sprout::darkroom::materials::make_uniform(elems)... ); } } // namespace materials diff --git a/sprout/utility/pack.hpp b/sprout/utility/pack.hpp index 81098d19..c6ace6ce 100644 --- a/sprout/utility/pack.hpp +++ b/sprout/utility/pack.hpp @@ -40,10 +40,10 @@ namespace sprout { struct pack_get_helper; template struct pack_get_helper > { - template - static SPROUT_CONSTEXPR T&& - eval(Args&&..., T&& t, ...) { - return sprout::forward(t); + template + static SPROUT_CONSTEXPR Head&& + eval(Args&&..., Head&& head, Tail&&...) { + return sprout::forward(head); } }; } // namespace detail