mirror of
https://github.com/bolero-MURAKAMI/Sprout.git
synced 2024-12-23 21:25:49 +00:00
sprout/darkroom/materials/material.hpp マテリアルの仕様変更
This commit is contained in:
parent
3e028096fd
commit
a4c71d0e9f
3 changed files with 114 additions and 33 deletions
|
@ -35,32 +35,32 @@ namespace sprout {
|
||||||
// calc_color
|
// calc_color
|
||||||
// calc_reflection
|
// calc_reflection
|
||||||
//
|
//
|
||||||
template<typename Image, typename Position, typename Normal>
|
template<typename Image, typename Unit>
|
||||||
SPROUT_CONSTEXPR auto calc_color(Image&& t, Position const&, Normal const&) SPROUT_NOEXCEPT
|
SPROUT_CONSTEXPR auto calc_color(Image&& t, Unit const& u, Unit const& v) SPROUT_NOEXCEPT
|
||||||
-> decltype(t)
|
-> decltype(sprout::forward<Image>(t).template operator()(u, v))
|
||||||
{
|
{
|
||||||
return t;
|
return sprout::forward<Image>(t).template operator()(u, v);
|
||||||
}
|
}
|
||||||
template<typename Image, typename Position, typename Normal>
|
template<typename Image, typename Unit>
|
||||||
SPROUT_CONSTEXPR auto calc_reflection(Image&& t, Position const&, Normal const&) SPROUT_NOEXCEPT
|
SPROUT_CONSTEXPR auto calc_reflection(Image&& t, Unit const& u, Unit const& v) SPROUT_NOEXCEPT
|
||||||
-> decltype(t)
|
-> decltype(sprout::forward<Image>(t).template operator()(u, v))
|
||||||
{
|
{
|
||||||
return t;
|
return sprout::forward<Image>(t).template operator()(u, v);
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// calc_material
|
// calc_material
|
||||||
//
|
//
|
||||||
template<typename Material, typename Position, typename Normal>
|
template<typename Material, typename Unit>
|
||||||
SPROUT_CONSTEXPR auto calc_material(Material const& mat, Position const& pos, Normal const& nor)
|
SPROUT_CONSTEXPR auto calc_material(Material const& mat, Unit const& u, Unit const& v)
|
||||||
-> decltype(sprout::tuples::make_tuple(
|
-> decltype(sprout::tuples::make_tuple(
|
||||||
sprout::darkroom::materials::calc_color(sprout::darkroom::materials::color(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), pos, nor)
|
sprout::darkroom::materials::calc_reflection(sprout::darkroom::materials::reflection(mat), u, v)
|
||||||
))
|
))
|
||||||
{
|
{
|
||||||
return sprout::tuples::make_tuple(
|
return sprout::tuples::make_tuple(
|
||||||
sprout::darkroom::materials::calc_color(sprout::darkroom::materials::color(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), pos, nor)
|
sprout::darkroom::materials::calc_reflection(sprout::darkroom::materials::reflection(mat), u, v)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,6 +77,46 @@ namespace sprout {
|
||||||
// material
|
// material
|
||||||
//
|
//
|
||||||
typedef sprout::tuples::tuple<sprout::darkroom::colors::rgb_f, double> material;
|
typedef sprout::tuples::tuple<sprout::darkroom::colors::rgb_f, double> material;
|
||||||
|
|
||||||
|
//
|
||||||
|
// uniform_element
|
||||||
|
//
|
||||||
|
template<typename Element>
|
||||||
|
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<typename Unit>
|
||||||
|
SPROUT_CONSTEXPR result_type operator()(Unit const&, Unit const&) const {
|
||||||
|
return elem_;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
//
|
||||||
|
// make_uniform
|
||||||
|
//
|
||||||
|
template<typename Element>
|
||||||
|
SPROUT_CONSTEXPR sprout::darkroom::materials::uniform_element<Element>
|
||||||
|
make_uniform(Element const& elem) {
|
||||||
|
return sprout::darkroom::materials::uniform_element<Element>(elem);
|
||||||
|
}
|
||||||
|
//
|
||||||
|
// make_uniform_material_image
|
||||||
|
//
|
||||||
|
template<typename Color, typename Reflection>
|
||||||
|
SPROUT_CONSTEXPR sprout::tuples::tuple<
|
||||||
|
sprout::darkroom::materials::uniform_element<Color>,
|
||||||
|
sprout::darkroom::materials::uniform_element<Reflection>
|
||||||
|
> 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 materials
|
||||||
} // namespace darkroom
|
} // namespace darkroom
|
||||||
} // namespace sprout
|
} // namespace sprout
|
||||||
|
|
|
@ -44,8 +44,8 @@ namespace sprout {
|
||||||
position_type,
|
position_type,
|
||||||
decltype(sprout::darkroom::materials::calc_material(
|
decltype(sprout::darkroom::materials::calc_material(
|
||||||
std::declval<material_type const&>(),
|
std::declval<material_type const&>(),
|
||||||
std::declval<position_type const&>(),
|
std::declval<unit_type const&>(),
|
||||||
std::declval<position_type const&>()
|
std::declval<unit_type const&>()
|
||||||
))
|
))
|
||||||
> type;
|
> type;
|
||||||
};
|
};
|
||||||
|
@ -71,16 +71,27 @@ namespace sprout {
|
||||||
position_type const& normal
|
position_type const& normal
|
||||||
) const
|
) const
|
||||||
{
|
{
|
||||||
|
using std::fmod;
|
||||||
return typename intersection<Ray>::type(
|
return typename intersection<Ray>::type(
|
||||||
does_intersect,
|
does_intersect,
|
||||||
distance,
|
distance,
|
||||||
point_of_intersection,
|
point_of_intersection,
|
||||||
normal,
|
normal,
|
||||||
sprout::darkroom::materials::calc_material(
|
is_x() ? sprout::darkroom::materials::calc_material( // ! Tile
|
||||||
mat_,
|
mat_,
|
||||||
point_of_intersection,
|
fmod(sprout::darkroom::coords::z(point_of_intersection), 0.5),
|
||||||
normal
|
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<typename Ray>
|
template<typename Ray>
|
||||||
|
@ -95,10 +106,9 @@ namespace sprout {
|
||||||
does_intersect,
|
does_intersect,
|
||||||
distance,
|
distance,
|
||||||
point_of_intersection,
|
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)
|
: is_y() ? position_type(0, hit_side > 0 ? 1 : -1, 0)
|
||||||
: position_type(0, 0, hit_side > 0 ? 1 : -1)
|
: position_type(0, 0, hit_side > 0 ? 1 : -1)
|
||||||
)
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
template<typename Ray>
|
template<typename Ray>
|
||||||
|
|
|
@ -35,8 +35,8 @@ namespace sprout {
|
||||||
position_type,
|
position_type,
|
||||||
decltype(sprout::darkroom::materials::calc_material(
|
decltype(sprout::darkroom::materials::calc_material(
|
||||||
std::declval<material_type const&>(),
|
std::declval<material_type const&>(),
|
||||||
std::declval<position_type const&>(),
|
std::declval<unit_type const&>(),
|
||||||
std::declval<position_type const&>()
|
std::declval<unit_type const&>()
|
||||||
))
|
))
|
||||||
> type;
|
> type;
|
||||||
};
|
};
|
||||||
|
@ -52,6 +52,8 @@ namespace sprout {
|
||||||
SPROUT_STATIC_CONSTEXPR std::size_t point_of_intersection = 0;
|
SPROUT_STATIC_CONSTEXPR std::size_t point_of_intersection = 0;
|
||||||
SPROUT_STATIC_CONSTEXPR std::size_t normal = 1;
|
SPROUT_STATIC_CONSTEXPR std::size_t normal = 1;
|
||||||
};
|
};
|
||||||
|
private:
|
||||||
|
SPROUT_STATIC_CONSTEXPR unit_type pi = 3.1415926535897932384626433832795;
|
||||||
private:
|
private:
|
||||||
position_type pos_;
|
position_type pos_;
|
||||||
radius_type rad_;
|
radius_type rad_;
|
||||||
|
@ -133,6 +135,40 @@ namespace sprout {
|
||||||
)
|
)
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
template<typename Ray, typename Point>
|
||||||
|
SPROUT_CONSTEXPR typename intersection<Ray>::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<Ray>::type(
|
||||||
|
sprout::tuples::get<zw::does_intersect>(zwo),
|
||||||
|
sprout::tuples::get<zw::distance>(zwo),
|
||||||
|
sprout::tuples::get<dr::point_of_intersection>(drei),
|
||||||
|
sprout::tuples::get<dr::normal>(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<typename Ray>
|
template<typename Ray>
|
||||||
SPROUT_CONSTEXPR typename intersection<Ray>::type intersect_5(
|
SPROUT_CONSTEXPR typename intersection<Ray>::type intersect_5(
|
||||||
Ray const& ray,
|
Ray const& ray,
|
||||||
|
@ -140,16 +176,11 @@ namespace sprout {
|
||||||
drei_type const& drei
|
drei_type const& drei
|
||||||
) const
|
) const
|
||||||
{
|
{
|
||||||
return typename intersection<Ray>::type(
|
return intersect_6(
|
||||||
sprout::tuples::get<zw::does_intersect>(zwo),
|
ray,
|
||||||
sprout::tuples::get<zw::distance>(zwo),
|
zwo,
|
||||||
sprout::tuples::get<dr::point_of_intersection>(drei),
|
drei,
|
||||||
sprout::tuples::get<dr::normal>(drei),
|
sprout::tuples::get<dr::point_of_intersection>(drei)
|
||||||
sprout::darkroom::materials::calc_material(
|
|
||||||
mat_,
|
|
||||||
sprout::tuples::get<dr::point_of_intersection>(drei),
|
|
||||||
sprout::tuples::get<dr::normal>(drei)
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
template<typename Ray>
|
template<typename Ray>
|
||||||
|
|
Loading…
Reference in a new issue