From a4c71d0e9f2a3db8125c603aa08e684e351ff8b7 Mon Sep 17 00:00:00 2001 From: bolero-MURAKAMI Date: Tue, 13 Dec 2011 04:01:10 +0900 Subject: [PATCH] =?UTF-8?q?sprout/darkroom/materials/material.hpp=20?= =?UTF-8?q?=E3=83=9E=E3=83=86=E3=83=AA=E3=82=A2=E3=83=AB=E3=81=AE=E4=BB=95?= =?UTF-8?q?=E6=A7=98=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sprout/darkroom/materials/material.hpp | 68 ++++++++++++++++++++------ sprout/darkroom/objects/aa_plane.hpp | 24 ++++++--- sprout/darkroom/objects/sphere.hpp | 55 ++++++++++++++++----- 3 files changed, 114 insertions(+), 33 deletions(-) diff --git a/sprout/darkroom/materials/material.hpp b/sprout/darkroom/materials/material.hpp index 54d8455a..4ca44d0d 100644 --- a/sprout/darkroom/materials/material.hpp +++ b/sprout/darkroom/materials/material.hpp @@ -35,32 +35,32 @@ namespace sprout { // calc_color // calc_reflection // - template - SPROUT_CONSTEXPR auto calc_color(Image&& t, Position const&, Normal const&) SPROUT_NOEXCEPT - -> decltype(t) + template + SPROUT_CONSTEXPR auto calc_color(Image&& t, Unit const& u, Unit const& v) SPROUT_NOEXCEPT + -> decltype(sprout::forward(t).template operator()(u, v)) { - return t; + return sprout::forward(t).template operator()(u, v); } - template - SPROUT_CONSTEXPR auto calc_reflection(Image&& t, Position const&, Normal const&) SPROUT_NOEXCEPT - -> decltype(t) + template + SPROUT_CONSTEXPR auto calc_reflection(Image&& t, Unit const& u, Unit const& v) SPROUT_NOEXCEPT + -> decltype(sprout::forward(t).template operator()(u, v)) { - return t; + return sprout::forward(t).template operator()(u, v); } // // calc_material // - template - SPROUT_CONSTEXPR auto calc_material(Material const& mat, Position const& pos, Normal const& nor) + template + SPROUT_CONSTEXPR auto calc_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), pos, nor), - sprout::darkroom::materials::calc_reflection(sprout::darkroom::materials::reflection(mat), pos, nor) + sprout::darkroom::materials::calc_color(sprout::darkroom::materials::color(mat), u, v), + sprout::darkroom::materials::calc_reflection(sprout::darkroom::materials::reflection(mat), u, v) )) { 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) + sprout::darkroom::materials::calc_color(sprout::darkroom::materials::color(mat), u, v), + sprout::darkroom::materials::calc_reflection(sprout::darkroom::materials::reflection(mat), u, v) ); } @@ -77,6 +77,46 @@ namespace sprout { // material // typedef sprout::tuples::tuple material; + + // + // uniform_element + // + template + class uniform_element { + public: + typedef Element result_type; + private: + result_type elem_; + public: + SPROUT_CONSTEXPR explicit uniform_element(result_type const& elem) + : elem_(elem) + {} + template + SPROUT_CONSTEXPR result_type operator()(Unit const&, Unit const&) const { + return elem_; + } + }; + // + // make_uniform + // + template + SPROUT_CONSTEXPR sprout::darkroom::materials::uniform_element + make_uniform(Element const& elem) { + return sprout::darkroom::materials::uniform_element(elem); + } + // + // make_uniform_material_image + // + template + SPROUT_CONSTEXPR sprout::tuples::tuple< + sprout::darkroom::materials::uniform_element, + sprout::darkroom::materials::uniform_element + > make_uniform_material_image(Color const& col, Reflection const& ref) { + return sprout::tuples::make_tuple( + sprout::darkroom::materials::make_uniform(col), + sprout::darkroom::materials::make_uniform(ref) + ); + } } // namespace materials } // namespace darkroom } // namespace sprout diff --git a/sprout/darkroom/objects/aa_plane.hpp b/sprout/darkroom/objects/aa_plane.hpp index acabcf48..2281a097 100644 --- a/sprout/darkroom/objects/aa_plane.hpp +++ b/sprout/darkroom/objects/aa_plane.hpp @@ -44,8 +44,8 @@ namespace sprout { position_type, decltype(sprout::darkroom::materials::calc_material( std::declval(), - std::declval(), - std::declval() + std::declval(), + std::declval() )) > type; }; @@ -71,16 +71,27 @@ namespace sprout { position_type const& normal ) const { + using std::fmod; return typename intersection::type( does_intersect, distance, point_of_intersection, normal, - sprout::darkroom::materials::calc_material( + is_x() ? sprout::darkroom::materials::calc_material( // ! Tile mat_, - point_of_intersection, - normal + fmod(sprout::darkroom::coords::z(point_of_intersection), 0.5), + fmod(sprout::darkroom::coords::y(point_of_intersection), 0.5) ) + : is_y() ? sprout::darkroom::materials::calc_material( + mat_, + fmod(sprout::darkroom::coords::x(point_of_intersection), 0.5), + fmod(sprout::darkroom::coords::z(point_of_intersection), 0.5) + ) + : sprout::darkroom::materials::calc_material( + mat_, + fmod(sprout::darkroom::coords::x(point_of_intersection), 0.5), + fmod(sprout::darkroom::coords::y(point_of_intersection), 0.5) + ) ); } template @@ -95,10 +106,9 @@ namespace sprout { does_intersect, distance, point_of_intersection, - (is_x() ? position_type(hit_side > 0 ? 1 : -1, 0, 0) + is_x() ? position_type(hit_side > 0 ? 1 : -1, 0, 0) : is_y() ? position_type(0, hit_side > 0 ? 1 : -1, 0) : position_type(0, 0, hit_side > 0 ? 1 : -1) - ) ); } template diff --git a/sprout/darkroom/objects/sphere.hpp b/sprout/darkroom/objects/sphere.hpp index 1022865c..db8d759f 100644 --- a/sprout/darkroom/objects/sphere.hpp +++ b/sprout/darkroom/objects/sphere.hpp @@ -35,8 +35,8 @@ namespace sprout { position_type, decltype(sprout::darkroom::materials::calc_material( std::declval(), - std::declval(), - std::declval() + std::declval(), + std::declval() )) > type; }; @@ -52,6 +52,8 @@ namespace sprout { SPROUT_STATIC_CONSTEXPR std::size_t point_of_intersection = 0; SPROUT_STATIC_CONSTEXPR std::size_t normal = 1; }; + private: + SPROUT_STATIC_CONSTEXPR unit_type pi = 3.1415926535897932384626433832795; private: position_type pos_; radius_type rad_; @@ -133,6 +135,40 @@ namespace sprout { ) ; } + template + SPROUT_CONSTEXPR typename intersection::type intersect_6( + Ray const& ray, + zwo_type const& zwo, + drei_type const& drei, + Point const& poi + ) const + { + using std::atan2; + using std::sqrt; + 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( // ! Spherical + mat_, + atan2( + sprout::darkroom::coords::x(poi), + sprout::darkroom::coords::z(poi) + ) + / (2 * pi) + , + atan2( + sqrt( + sprout::darkroom::coords::x(poi) * sprout::darkroom::coords::x(poi) + + sprout::darkroom::coords::y(poi) * sprout::darkroom::coords::y(poi) + ), + sprout::darkroom::coords::z(poi) + ) + / (2 * pi) + ) + ); + } template SPROUT_CONSTEXPR typename intersection::type intersect_5( Ray const& ray, @@ -140,16 +176,11 @@ namespace sprout { 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) - ) + return intersect_6( + ray, + zwo, + drei, + sprout::tuples::get(drei) ); } template