From dfcb6bcf31c57c39a660828c2733032d3d2608d8 Mon Sep 17 00:00:00 2001 From: bolero-MURAKAMI Date: Tue, 24 Sep 2013 15:08:36 +0900 Subject: [PATCH] fix darkroom: fix template operator() member-function call -> calcurate() free-function --- sprout/darkroom/access/access.hpp | 2 +- sprout/darkroom/cameras.hpp | 1 + sprout/darkroom/cameras/calculate.hpp | 49 +++++++ sprout/darkroom/lights.hpp | 1 + sprout/darkroom/lights/calculate.hpp | 138 +++++++++++++++++++ sprout/darkroom/lights/light_list.hpp | 61 ++------ sprout/darkroom/materials.hpp | 1 + sprout/darkroom/materials/calculate.hpp | 49 +++++++ sprout/darkroom/materials/material.hpp | 34 +---- sprout/darkroom/materials/plaid.hpp | 4 +- sprout/darkroom/materials/texture_map.hpp | 12 +- sprout/darkroom/objects/aa_plane.hpp | 8 +- sprout/darkroom/objects/intersect.hpp | 61 ++++++-- sprout/darkroom/objects/object_list.hpp | 2 +- sprout/darkroom/objects/polygon/triangle.hpp | 4 +- sprout/darkroom/objects/sphere.hpp | 4 +- sprout/darkroom/pixels/generate.hpp | 4 +- sprout/darkroom/renderers.hpp | 1 + sprout/darkroom/renderers/calculate.hpp | 55 ++++++++ sprout/darkroom/renderers/infinity.hpp | 30 ++++ sprout/darkroom/renderers/whitted_style.hpp | 19 +-- sprout/darkroom/tracers.hpp | 1 + sprout/darkroom/tracers/calculate.hpp | 56 ++++++++ sprout/darkroom/tracers/raytracer.hpp | 7 +- tools/darkroom/darkcult.sh | 19 ++- 25 files changed, 494 insertions(+), 129 deletions(-) create mode 100644 sprout/darkroom/cameras/calculate.hpp create mode 100644 sprout/darkroom/lights/calculate.hpp create mode 100644 sprout/darkroom/materials/calculate.hpp create mode 100644 sprout/darkroom/renderers/calculate.hpp create mode 100644 sprout/darkroom/tracers/calculate.hpp diff --git a/sprout/darkroom/access/access.hpp b/sprout/darkroom/access/access.hpp index 0ff50a14..90f00295 100644 --- a/sprout/darkroom/access/access.hpp +++ b/sprout/darkroom/access/access.hpp @@ -11,8 +11,8 @@ #include #include #include -#include #include +#include namespace sprout { namespace darkroom { diff --git a/sprout/darkroom/cameras.hpp b/sprout/darkroom/cameras.hpp index bc2064a1..1d7d3980 100644 --- a/sprout/darkroom/cameras.hpp +++ b/sprout/darkroom/cameras.hpp @@ -9,6 +9,7 @@ #define SPROUT_DARKROOM_CAMERAS_HPP #include +#include #include #include diff --git a/sprout/darkroom/cameras/calculate.hpp b/sprout/darkroom/cameras/calculate.hpp new file mode 100644 index 00000000..9834e702 --- /dev/null +++ b/sprout/darkroom/cameras/calculate.hpp @@ -0,0 +1,49 @@ +/*============================================================================= + Copyright (c) 2011-2013 Bolero MURAKAMI + https://github.com/bolero-MURAKAMI/Sprout + + Distributed under the Boost Software License, Version 1.0. (See accompanying + file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +=============================================================================*/ +#ifndef SPROUT_DARKROOM_CAMERAS_CALCULATE_HPP +#define SPROUT_DARKROOM_CAMERAS_CALCULATE_HPP + +#include +#include + +namespace sprout { + namespace darkroom { + namespace cameras { + // + // calculate_result + // + template + struct calculate_result + : public sprout::identity + {}; + template + struct calculate_result + : public sprout::darkroom::cameras::calculate_result + {}; + template + struct calculate_result + : public sprout::darkroom::cameras::calculate_result + {}; + template + struct calculate_result + : public sprout::darkroom::cameras::calculate_result + {}; + + // + // calculate + // + template + inline SPROUT_CONSTEXPR typename sprout::darkroom::cameras::calculate_result::type + calculate(Camera const& camera, Unit2D const& x, Unit2D const& y, Unit2D const& width, Unit2D const& height) { + return camera(x, y, width, height); + } + } // namespace cameras + } // namespace darkroom +} // namespace sprout + +#endif // #ifndef SPROUT_DARKROOM_CAMERAS_CALCULATE_HPP diff --git a/sprout/darkroom/lights.hpp b/sprout/darkroom/lights.hpp index 005c0816..0243dc5d 100644 --- a/sprout/darkroom/lights.hpp +++ b/sprout/darkroom/lights.hpp @@ -9,6 +9,7 @@ #define SPROUT_DARKROOM_LIGHTS_HPP #include +#include #include #include #include diff --git a/sprout/darkroom/lights/calculate.hpp b/sprout/darkroom/lights/calculate.hpp new file mode 100644 index 00000000..7c87d873 --- /dev/null +++ b/sprout/darkroom/lights/calculate.hpp @@ -0,0 +1,138 @@ +/*============================================================================= + Copyright (c) 2011-2013 Bolero MURAKAMI + https://github.com/bolero-MURAKAMI/Sprout + + Distributed under the Boost Software License, Version 1.0. (See accompanying + file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +=============================================================================*/ +#ifndef SPROUT_DARKROOM_LIGHTS_CALCULATE_HPP +#define SPROUT_DARKROOM_LIGHTS_CALCULATE_HPP + +#include +#include +#include +#include +#include +#include + +namespace sprout { + namespace darkroom { + namespace lights { + template + struct calculate_result; + + namespace detail { + template + struct calculate_result; + + template + struct calculate_result + : public sprout::identity + {}; + template + struct calculate_result + : public sprout::darkroom::lights::calculate_result::type, Intersection, Objects> + {}; + } // namespace detail + + // + // calculate_result + // + template + struct calculate_result + : public sprout::darkroom::lights::detail::calculate_result< + Light, Intersection, Objects, + sprout::darkroom::access::is_tuple::value + > + {}; + template + struct calculate_result + : public sprout::darkroom::lights::calculate_result + {}; + template + struct calculate_result + : public sprout::darkroom::lights::calculate_result + {}; + template + struct calculate_result + : public sprout::darkroom::lights::calculate_result + {}; + + // + // calculate + // + template< + typename Light, typename Intersection, typename Objects, + typename sprout::enabler_if::value>::type = sprout::enabler + > + inline SPROUT_CONSTEXPR typename sprout::darkroom::lights::calculate_result::type + calculate(Light const& light, Intersection const& inter, Objects const& objs); + template< + typename Light, typename Intersection, typename Objects, + typename sprout::enabler_if::value>::type = sprout::enabler + > + inline SPROUT_CONSTEXPR typename sprout::darkroom::lights::calculate_result::type + calculate(Light const& light, Intersection const& inter, Objects const& objs); + + namespace detail { + template + inline SPROUT_CONSTEXPR typename sprout::darkroom::lights::calculate_result::type + calculate_2(Color const& col) { + return col; + } + template + inline SPROUT_CONSTEXPR typename sprout::darkroom::lights::calculate_result::type + calculate_2(Color1 const& col1, Color2 const& col2, Tail const&... tail) { + return sprout::darkroom::lights::detail::calculate_2( + sprout::darkroom::colors::add(col1, col2), + tail... + ); + } + template + inline SPROUT_CONSTEXPR typename sprout::darkroom::lights::calculate_result::type + calculate_1( + Lights const& lights, Intersection const& inter, Objects const& objs, + sprout::index_tuple + ) + { + return sprout::darkroom::lights::detail::calculate_2( + sprout::darkroom::lights::calculate(sprout::darkroom::access::get(lights), inter, objs)... + ); + } + } // namespace detail + // + // calculate_list + // + template + inline SPROUT_CONSTEXPR typename sprout::darkroom::lights::calculate_result::type + calculate_list(Lights const& lights, Intersection const& inter, Objects const& objs) { + return sprout::darkroom::lights::detail::calculate_1( + lights, inter, objs, + sprout::tuple_indexes::make() + ); + } + + // + // calculate + // + template< + typename Light, typename Intersection, typename Objects, + typename sprout::enabler_if::value>::type + > + inline SPROUT_CONSTEXPR typename sprout::darkroom::lights::calculate_result::type + calculate(Light const& light, Intersection const& inter, Objects const& objs) { + return light(inter, objs); + } + template< + typename Light, typename Intersection, typename Objects, + typename sprout::enabler_if::value>::type + > + inline SPROUT_CONSTEXPR typename sprout::darkroom::lights::calculate_result::type + calculate(Light const& light, Intersection const& inter, Objects const& objs) { + return sprout::darkroom::lights::calculate_list(light, inter, objs); + } + } // namespace lights + } // namespace darkroom +} // namespace sprout + +#endif // #ifndef SPROUT_DARKROOM_LIGHTS_CALCULATE_HPP diff --git a/sprout/darkroom/lights/light_list.hpp b/sprout/darkroom/lights/light_list.hpp index 2ae7bf78..6fdb3463 100644 --- a/sprout/darkroom/lights/light_list.hpp +++ b/sprout/darkroom/lights/light_list.hpp @@ -9,66 +9,21 @@ #define SPROUT_DARKROOM_LIGHTS_LIGHT_LIST_HPP #include -#include -#include -#include -#include -#include +#include +#include namespace sprout { namespace darkroom { namespace lights { // - // light_list + // make_object_list // template - class light_list { - public: - typedef sprout::tuples::tuple lights_type; - typedef typename sprout::darkroom::access::unit::type::color_type color_type; - private: - lights_type lights_; - private: - template - SPROUT_CONSTEXPR color_type - shade_2(Color const& col) const { - return col; - } - template - SPROUT_CONSTEXPR color_type - shade_2(Color1 const& col1, Color2 const& col2, Tail const&... tail) const { - return shade_2( - sprout::darkroom::colors::add(col1, col2), - tail... - ); - } - template - SPROUT_CONSTEXPR color_type - shade_1( - Intersection const& inter, Objects const& objs, - sprout::index_tuple - ) const - { - return shade_2(sprout::darkroom::access::get(lights_).template operator()(inter, objs)...); - } - public: - explicit SPROUT_CONSTEXPR light_list(Lights const&... lights) - : lights_(lights...) - {} - template - SPROUT_CONSTEXPR color_type - operator()(Intersection const& inter, Objects const& objs) const { - return shade_1(inter, objs, sprout::index_pack::make()); - } - }; - - // - // make_light_list - // - template - inline SPROUT_CONSTEXPR sprout::darkroom::lights::light_list - make_light_list(Lights const&... lights) { - return sprout::darkroom::lights::light_list(lights...); + inline SPROUT_CONSTEXPR auto + make_light_list(Lights&&... lights) + -> decltype(sprout::make_tuple(sprout::forward(lights)...)) + { + return sprout::make_tuple(sprout::forward(lights)...); } } // namespace lights } // namespace darkroom diff --git a/sprout/darkroom/materials.hpp b/sprout/darkroom/materials.hpp index 40e92f89..af14b54e 100644 --- a/sprout/darkroom/materials.hpp +++ b/sprout/darkroom/materials.hpp @@ -9,6 +9,7 @@ #define SPROUT_DARKROOM_MATERIALS_HPP #include +#include #include #include #include diff --git a/sprout/darkroom/materials/calculate.hpp b/sprout/darkroom/materials/calculate.hpp new file mode 100644 index 00000000..fc954cf1 --- /dev/null +++ b/sprout/darkroom/materials/calculate.hpp @@ -0,0 +1,49 @@ +/*============================================================================= + Copyright (c) 2011-2013 Bolero MURAKAMI + https://github.com/bolero-MURAKAMI/Sprout + + Distributed under the Boost Software License, Version 1.0. (See accompanying + file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +=============================================================================*/ +#ifndef SPROUT_DARKROOM_MATERIALS_CALCULATE_HPP +#define SPROUT_DARKROOM_MATERIALS_CALCULATE_HPP + +#include +#include + +namespace sprout { + namespace darkroom { + namespace materials { + // + // calculate_result + // + template + struct calculate_result + : public sprout::identity + {}; + template + struct calculate_result + : public sprout::darkroom::materials::calculate_result + {}; + template + struct calculate_result + : public sprout::darkroom::materials::calculate_result + {}; + template + struct calculate_result + : public sprout::darkroom::materials::calculate_result + {}; + + // + // calculate + // + template + inline SPROUT_CONSTEXPR typename sprout::darkroom::materials::calculate_result::type + calculate(Image const& image, Unit const& u, Unit const& v) { + return image(u, v); + } + } // namespace materials + } // namespace darkroom +} // namespace sprout + +#endif // #ifndef SPROUT_DARKROOM_MATERIALS_CALCULATE_HPP diff --git a/sprout/darkroom/materials/material.hpp b/sprout/darkroom/materials/material.hpp index d81689e8..23463438 100644 --- a/sprout/darkroom/materials/material.hpp +++ b/sprout/darkroom/materials/material.hpp @@ -13,6 +13,7 @@ #include #include #include +#include namespace sprout { namespace darkroom { @@ -39,40 +40,19 @@ namespace sprout { } // - // calc_color - // calc_reflection - // - template - inline SPROUT_CONSTEXPR auto - calc_color(Image&& t, Unit const& u, Unit const& v) - SPROUT_NOEXCEPT - -> decltype(sprout::forward(t).template operator()(u, v)) - { - return sprout::forward(t).template operator()(u, v); - } - template - inline SPROUT_CONSTEXPR auto - calc_reflection(Image&& t, Unit const& u, Unit const& v) - SPROUT_NOEXCEPT - -> decltype(sprout::forward(t).template operator()(u, v)) - { - return sprout::forward(t).template operator()(u, v); - } - - // - // calc_material + // calculate_material // template inline SPROUT_CONSTEXPR auto - calc_material(Material const& mat, Unit const& u, Unit const& v) + calculate_material(Material const& mat, Unit const& u, Unit const& v) -> decltype(sprout::tuples::make_tuple( - sprout::darkroom::materials::calc_color(sprout::darkroom::materials::color(mat), u, v), - sprout::darkroom::materials::calc_reflection(sprout::darkroom::materials::reflection(mat), u, v) + sprout::darkroom::materials::calculate(sprout::darkroom::materials::color(mat), u, v), + sprout::darkroom::materials::calculate(sprout::darkroom::materials::reflection(mat), u, v) )) { return sprout::tuples::make_tuple( - sprout::darkroom::materials::calc_color(sprout::darkroom::materials::color(mat), u, v), - sprout::darkroom::materials::calc_reflection(sprout::darkroom::materials::reflection(mat), u, v) + sprout::darkroom::materials::calculate(sprout::darkroom::materials::color(mat), u, v), + sprout::darkroom::materials::calculate(sprout::darkroom::materials::reflection(mat), u, v) ); } diff --git a/sprout/darkroom/materials/plaid.hpp b/sprout/darkroom/materials/plaid.hpp index b2aeaf7d..7e7b4f35 100644 --- a/sprout/darkroom/materials/plaid.hpp +++ b/sprout/darkroom/materials/plaid.hpp @@ -31,7 +31,7 @@ namespace sprout { private: template SPROUT_CONSTEXPR result_type - calc_1(Unit const& u, Unit const& v) const { + calculate_1(Unit const& u, Unit const& v) const { return (u >= 0 && v >= 0) || (u < 0 && v < 0) ? elem1_ : elem2_; } public: @@ -43,7 +43,7 @@ namespace sprout { template SPROUT_CONSTEXPR result_type operator()(Unit const& u, Unit const& v) const { - return calc_1( + return calculate_1( (u < 0 ? scale_ + sprout::fmod(u, scale_) : sprout::fmod(u, scale_) diff --git a/sprout/darkroom/materials/texture_map.hpp b/sprout/darkroom/materials/texture_map.hpp index 8c174e6e..2182d09c 100644 --- a/sprout/darkroom/materials/texture_map.hpp +++ b/sprout/darkroom/materials/texture_map.hpp @@ -92,12 +92,12 @@ namespace sprout { } template SPROUT_CONSTEXPR result_type - calc_nearest(Unit const& x, Unit const& y) const { + calculate_nearest(Unit const& x, Unit const& y) const { return get_color(x, y); } template SPROUT_CONSTEXPR result_type - calc_bilinear_1( + calculate_bilinear_1( Unit const& x, Unit const& x0, Unit const& y, Unit const& y0 ) const @@ -110,8 +110,8 @@ namespace sprout { } template SPROUT_CONSTEXPR result_type - calc_bilinear(Unit const& x, Unit const& y) const { - return calc_bilinear_1( + calculate_bilinear(Unit const& x, Unit const& y) const { + return calculate_bilinear_1( x, sprout::floor(x), y, sprout::floor(y) ); @@ -119,8 +119,8 @@ namespace sprout { template SPROUT_CONSTEXPR result_type calc(Unit const& x, Unit const& y) const { - return is_nearest() ? calc_nearest(x, y) - : calc_bilinear(x, y) + return is_nearest() ? calculate_nearest(x, y) + : calculate_bilinear(x, y) ; } public: diff --git a/sprout/darkroom/objects/aa_plane.hpp b/sprout/darkroom/objects/aa_plane.hpp index cb6f2074..8709aee3 100644 --- a/sprout/darkroom/objects/aa_plane.hpp +++ b/sprout/darkroom/objects/aa_plane.hpp @@ -49,7 +49,7 @@ namespace sprout { unit_type, position_type, position_type, - decltype(sprout::darkroom::materials::calc_material( + decltype(sprout::darkroom::materials::calculate_material( std::declval(), std::declval(), std::declval() @@ -84,17 +84,17 @@ namespace sprout { : is_y() ? position_type(0, hit_side > 0 ? 1 : -1, 0) : position_type(0, 0, hit_side > 0 ? 1 : -1) , - is_x() ? sprout::darkroom::materials::calc_material( + is_x() ? sprout::darkroom::materials::calculate_material( mat_, sprout::darkroom::coords::z(point_of_intersection), sprout::darkroom::coords::y(point_of_intersection) ) - : is_y() ? sprout::darkroom::materials::calc_material( + : is_y() ? sprout::darkroom::materials::calculate_material( mat_, sprout::darkroom::coords::x(point_of_intersection), sprout::darkroom::coords::z(point_of_intersection) ) - : sprout::darkroom::materials::calc_material( + : sprout::darkroom::materials::calculate_material( mat_, sprout::darkroom::coords::x(point_of_intersection), sprout::darkroom::coords::y(point_of_intersection) diff --git a/sprout/darkroom/objects/intersect.hpp b/sprout/darkroom/objects/intersect.hpp index 7caf7688..1f1f1d3b 100644 --- a/sprout/darkroom/objects/intersect.hpp +++ b/sprout/darkroom/objects/intersect.hpp @@ -11,12 +11,53 @@ #include #include #include +#include #include #include namespace sprout { namespace darkroom { namespace objects { + template + struct intersection_result; + + namespace detail { + template + struct intersection_result; + + template + struct intersection_result + : public Object::template intersection + {}; + template + struct intersection_result + : public sprout::darkroom::objects::intersection_result::type, Ray> + {}; + } // namespace detail + + // + // intersection_result + // + template + struct intersection_result + : public sprout::darkroom::objects::detail::intersection_result< + Object, Ray, + sprout::darkroom::access::is_tuple::value + > + {}; + template + struct intersection_result + : public sprout::darkroom::objects::intersection_result + {}; + template + struct intersection_result + : public sprout::darkroom::objects::intersection_result + {}; + template + struct intersection_result + : public sprout::darkroom::objects::intersection_result + {}; + // // intersect // @@ -24,13 +65,13 @@ namespace sprout { typename Object, typename Ray, typename sprout::enabler_if::value>::type = sprout::enabler > - inline SPROUT_CONSTEXPR typename Object::template intersection::type + inline SPROUT_CONSTEXPR typename sprout::darkroom::objects::intersection_result::type intersect(Object const& obj, Ray const& ray); template< typename Object, typename Ray, typename sprout::enabler_if::value>::type = sprout::enabler > - inline SPROUT_CONSTEXPR typename Object::template intersection::type + inline SPROUT_CONSTEXPR typename sprout::darkroom::objects::intersection_result::type intersect(Object const& obj, Ray const& ray); namespace detail { @@ -38,7 +79,7 @@ namespace sprout { struct intersect_list_impl { private: template - SPROUT_CONSTEXPR typename sprout::darkroom::access::unit::type::template intersection::type + SPROUT_CONSTEXPR typename sprout::darkroom::objects::intersection_result::type comp(A const& a, B const& b) const { return sprout::darkroom::intersects::does_intersect(a) && sprout::darkroom::intersects::does_intersect(b) @@ -52,7 +93,7 @@ namespace sprout { } public: template - SPROUT_CONSTEXPR typename sprout::darkroom::access::unit::type ::template intersection::type + SPROUT_CONSTEXPR typename sprout::darkroom::objects::intersection_result::type operator()(Objects const& objs, Ray const& ray) const { return comp( sprout::darkroom::objects::intersect(sprout::darkroom::access::get(objs), ray), @@ -64,7 +105,7 @@ namespace sprout { struct intersect_list_impl<0> { public: template - SPROUT_CONSTEXPR typename sprout::darkroom::access::unit::type::template intersection::type + SPROUT_CONSTEXPR typename sprout::darkroom::objects::intersection_result::type operator()(Objects const& objs, Ray const& ray) const { return sprout::darkroom::objects::intersect(sprout::darkroom::access::get<0>(objs), ray); } @@ -74,7 +115,7 @@ namespace sprout { // intersect_list // template - inline SPROUT_CONSTEXPR typename sprout::darkroom::access::unit::type::template intersection::type + inline SPROUT_CONSTEXPR typename sprout::darkroom::objects::intersection_result::type intersect_list(Objects const& objs, Ray const& ray) { return sprout::darkroom::objects::detail::intersect_list_impl< sprout::darkroom::access::size::value - 1 @@ -86,17 +127,17 @@ namespace sprout { // template< typename Object, typename Ray, - typename sprout::enabler_if::value>::type = sprout::enabler + typename sprout::enabler_if::value>::type > - inline SPROUT_CONSTEXPR typename Object::template intersection::type + inline SPROUT_CONSTEXPR typename sprout::darkroom::objects::intersection_result::type intersect(Object const& obj, Ray const& ray) { return obj.intersect(ray); } template< typename Object, typename Ray, - typename sprout::enabler_if::value>::type = sprout::enabler + typename sprout::enabler_if::value>::type > - inline SPROUT_CONSTEXPR typename sprout::darkroom::access::unit::type::template intersection::type + inline SPROUT_CONSTEXPR typename sprout::darkroom::objects::intersection_result::type intersect(Object const& obj, Ray const& ray) { return sprout::darkroom::objects::intersect_list(obj, ray); } diff --git a/sprout/darkroom/objects/object_list.hpp b/sprout/darkroom/objects/object_list.hpp index f1bfbaf1..2c3480a9 100644 --- a/sprout/darkroom/objects/object_list.hpp +++ b/sprout/darkroom/objects/object_list.hpp @@ -10,7 +10,7 @@ #include #include -#include +#include namespace sprout { namespace darkroom { diff --git a/sprout/darkroom/objects/polygon/triangle.hpp b/sprout/darkroom/objects/polygon/triangle.hpp index 346d13da..0d74fe55 100644 --- a/sprout/darkroom/objects/polygon/triangle.hpp +++ b/sprout/darkroom/objects/polygon/triangle.hpp @@ -39,7 +39,7 @@ namespace sprout { unit_type, position_type, position_type, - decltype(sprout::darkroom::materials::calc_material( + decltype(sprout::darkroom::materials::calculate_material( std::declval(), std::declval(), std::declval() @@ -72,7 +72,7 @@ namespace sprout { : position_type(0, 0, 0) , normal_,//hit_side > 0 ? normal_ : sprout::darkroom::coords::negate(normal_), - sprout::darkroom::materials::calc_material(mat_, unit_type(0), unit_type(0)) // ??? + sprout::darkroom::materials::calculate_material(mat_, unit_type(0), unit_type(0)) // ??? ); } template diff --git a/sprout/darkroom/objects/sphere.hpp b/sprout/darkroom/objects/sphere.hpp index d17106c4..1d944dcc 100644 --- a/sprout/darkroom/objects/sphere.hpp +++ b/sprout/darkroom/objects/sphere.hpp @@ -42,7 +42,7 @@ namespace sprout { unit_type, position_type, position_type, - decltype(sprout::darkroom::materials::calc_material( + decltype(sprout::darkroom::materials::calculate_material( std::declval(), std::declval(), std::declval() @@ -128,7 +128,7 @@ namespace sprout { sprout::tuples::get(zwo), sprout::tuples::get(drei), sprout::tuples::get(drei), - sprout::darkroom::materials::calc_material( // ! Spherical + sprout::darkroom::materials::calculate_material( // ! Spherical mat_, sprout::atan2( sprout::darkroom::coords::z(normal), diff --git a/sprout/darkroom/pixels/generate.hpp b/sprout/darkroom/pixels/generate.hpp index 27fc9378..5f16d5f6 100644 --- a/sprout/darkroom/pixels/generate.hpp +++ b/sprout/darkroom/pixels/generate.hpp @@ -16,6 +16,7 @@ #include #include #include +#include namespace sprout { namespace darkroom { @@ -50,7 +51,8 @@ namespace sprout { typedef typename sprout::container_traits::value_type pixel_type; return sprout::make( sprout::darkroom::colors::rgb_f_to_rgb( - raytracer.template operator()( + sprout::darkroom::tracers::calculate( + raytracer, renderer, camera, objs, lights, x + XIndexes, y, width, height, depth_max ) diff --git a/sprout/darkroom/renderers.hpp b/sprout/darkroom/renderers.hpp index a389d2de..2a4fee47 100644 --- a/sprout/darkroom/renderers.hpp +++ b/sprout/darkroom/renderers.hpp @@ -9,6 +9,7 @@ #define SPROUT_DARKROOM_RENDERERS_HPP #include +#include #include #include diff --git a/sprout/darkroom/renderers/calculate.hpp b/sprout/darkroom/renderers/calculate.hpp new file mode 100644 index 00000000..d76b505b --- /dev/null +++ b/sprout/darkroom/renderers/calculate.hpp @@ -0,0 +1,55 @@ +/*============================================================================= + Copyright (c) 2011-2013 Bolero MURAKAMI + https://github.com/bolero-MURAKAMI/Sprout + + Distributed under the Boost Software License, Version 1.0. (See accompanying + file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +=============================================================================*/ +#ifndef SPROUT_DARKROOM_RENDERERS_CALCULATE_HPP +#define SPROUT_DARKROOM_RENDERERS_CALCULATE_HPP + +#include +#include +#include + +namespace sprout { + namespace darkroom { + namespace renderers { + // + // calculate_result + // + template + struct calculate_result + : public sprout::identity + {}; + template + struct calculate_result + : public sprout::darkroom::renderers::calculate_result + {}; + template + struct calculate_result + : public sprout::darkroom::renderers::calculate_result + {}; + template + struct calculate_result + : public sprout::darkroom::renderers::calculate_result + {}; + + // + // calculate + // + template + inline SPROUT_CONSTEXPR typename sprout::darkroom::renderers::calculate_result::type + calculate( + Renderer const& renderer, + Camera const& camera, Objects const& objs, Lights const& lights, + Ray const& ray, std::size_t depth_max + ) + { + return renderer.template operator()(camera, objs, lights, ray, depth_max); + } + } // namespace renderers + } // namespace darkroom +} // namespace sprout + +#endif // #ifndef SPROUT_DARKROOM_RENDERERS_CALCULATE_HPP diff --git a/sprout/darkroom/renderers/infinity.hpp b/sprout/darkroom/renderers/infinity.hpp index 58f7ad59..8fe97566 100644 --- a/sprout/darkroom/renderers/infinity.hpp +++ b/sprout/darkroom/renderers/infinity.hpp @@ -10,6 +10,7 @@ #include #include +#include #include #include @@ -83,6 +84,35 @@ namespace sprout { make_uniform_color(Color const& color) { return sprout::darkroom::renderers::uniform_color(color); } + + // + // infinity_result + // + template + struct infinity_result + : public sprout::identity + {}; + template + struct infinity_result + : public sprout::darkroom::renderers::infinity_result + {}; + template + struct infinity_result + : public sprout::darkroom::renderers::infinity_result + {}; + template + struct infinity_result + : public sprout::darkroom::renderers::infinity_result + {}; + + // + // calculate_infinity + // + template + inline SPROUT_CONSTEXPR typename sprout::darkroom::renderers::infinity_result::type + calculate_infinity(InfinityColor const& infinity_color, Vector const& dir) { + return infinity_color.template operator()(dir); + } } // namespace renderers } // namespace darkroom } // namespace sprout diff --git a/sprout/darkroom/renderers/whitted_style.hpp b/sprout/darkroom/renderers/whitted_style.hpp index ae90675b..88e3037f 100644 --- a/sprout/darkroom/renderers/whitted_style.hpp +++ b/sprout/darkroom/renderers/whitted_style.hpp @@ -20,6 +20,8 @@ #include #include #include +#include +#include #include namespace sprout { @@ -33,18 +35,19 @@ namespace sprout { template< typename Color, typename Camera, typename Objects, typename Lights, - typename Ray, typename Intersection, typename Tracer, + typename Ray, typename Intersection, typename Renderer, 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, + Ray const& ray, Intersection const& inter, Renderer const& renderer, std::size_t depth_max, Direction const& reflect_dir ) const { - return tracer.template operator()( + return sprout::darkroom::renderers::calculate( + renderer, camera, objs, lights, sprout::tuples::remake( ray, @@ -69,12 +72,12 @@ namespace sprout { template< typename Color, typename Camera, typename Objects, typename Lights, - typename Ray, typename Intersection, typename Tracer + typename Ray, typename Intersection, typename Renderer > SPROUT_CONSTEXPR Color operator()( Camera const& camera, Objects const& objs, Lights const& lights, - Ray const& ray, Intersection const& inter, Tracer const& tracer, + Ray const& ray, Intersection const& inter, Renderer const& renderer, std::size_t depth_max ) const { @@ -87,7 +90,7 @@ namespace sprout { > sprout::numeric_limits::epsilon() ? color_1( camera, objs, lights, - ray, inter, tracer, + ray, inter, renderer, depth_max, sprout::darkroom::coords::reflect( sprout::darkroom::rays::direction(ray), @@ -126,7 +129,7 @@ namespace sprout { sprout::darkroom::materials::reflection(sprout::darkroom::intersects::material(inter)) ) ) - : infinity_color_.template operator()(sprout::darkroom::rays::direction(ray)) + : sprout::darkroom::renderers::calculate_infinity(infinity_color_, sprout::darkroom::rays::direction(ray)) ; } template< @@ -165,7 +168,7 @@ namespace sprout { return color_2( camera, objs, lights, ray, depth_max, inter, - lights.template operator()(inter, objs) + sprout::darkroom::lights::calculate(lights, inter, objs) ); } public: diff --git a/sprout/darkroom/tracers.hpp b/sprout/darkroom/tracers.hpp index c65d5a01..e9ac3bfd 100644 --- a/sprout/darkroom/tracers.hpp +++ b/sprout/darkroom/tracers.hpp @@ -9,6 +9,7 @@ #define SPROUT_DARKROOM_TRACERS_HPP #include +#include #include #endif // #ifndef SPROUT_DARKROOM_TRACERS_HPP diff --git a/sprout/darkroom/tracers/calculate.hpp b/sprout/darkroom/tracers/calculate.hpp new file mode 100644 index 00000000..a9c6a35e --- /dev/null +++ b/sprout/darkroom/tracers/calculate.hpp @@ -0,0 +1,56 @@ +/*============================================================================= + Copyright (c) 2011-2013 Bolero MURAKAMI + https://github.com/bolero-MURAKAMI/Sprout + + Distributed under the Boost Software License, Version 1.0. (See accompanying + file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +=============================================================================*/ +#ifndef SPROUT_DARKROOM_TRACERS_CALCULATE_HPP +#define SPROUT_DARKROOM_TRACERS_CALCULATE_HPP + +#include +#include +#include + +namespace sprout { + namespace darkroom { + namespace tracers { + // + // calculate_result + // + template + struct calculate_result + : public sprout::identity + {}; + template + struct calculate_result + : public sprout::darkroom::tracers::calculate_result + {}; + template + struct calculate_result + : public sprout::darkroom::tracers::calculate_result + {}; + template + struct calculate_result + : public sprout::darkroom::tracers::calculate_result + {}; + + // + // calculate + // + template + inline SPROUT_CONSTEXPR typename sprout::darkroom::tracers::calculate_result::type + calculate( + Tracer const& tracer, + Renderer const& renderer, Camera const& camera, Objects const& objs, Lights const& lights, + Unit2D const& x, Unit2D const& y, Unit2D const& width, Unit2D const& height, + std::size_t depth_max = 8 + ) + { + return tracer(renderer, camera, objs, lights, x, y, width, height, depth_max); + } + } // namespace tracers + } // namespace darkroom +} // namespace sprout + +#endif // #ifndef SPROUT_DARKROOM_TRACERS_CALCULATE_HPP diff --git a/sprout/darkroom/tracers/raytracer.hpp b/sprout/darkroom/tracers/raytracer.hpp index a22014c2..3b398e02 100644 --- a/sprout/darkroom/tracers/raytracer.hpp +++ b/sprout/darkroom/tracers/raytracer.hpp @@ -11,6 +11,8 @@ #include #include #include +#include +#include namespace sprout { namespace darkroom { @@ -30,9 +32,10 @@ namespace sprout { std::size_t depth_max = 8 ) const { - return renderer.template operator()( + return sprout::darkroom::renderers::calculate( + renderer, camera, objs, lights, - camera.template operator()(x, y, width, height), + sprout::darkroom::cameras::calculate(camera, x, y, width, height), depth_max ); } diff --git a/tools/darkroom/darkcult.sh b/tools/darkroom/darkcult.sh index d604382c..36f15643 100755 --- a/tools/darkroom/darkcult.sh +++ b/tools/darkroom/darkcult.sh @@ -138,22 +138,21 @@ for ((y=0; y&2 "error: compile failed." + echo "" + echo >&2 "error: compile(${binname}) failed." exit 1 fi - ${binname} > ${stagedir}/${y}/${x}.ppm + ${bin} > ${stagedir}/${y}/${x}.ppm done echo ""