2013-08-08 09:54:33 +00:00
|
|
|
/*=============================================================================
|
2017-07-29 05:20:01 +00:00
|
|
|
Copyright (c) 2011-2017 Bolero MURAKAMI
|
2013-08-08 09:54:33 +00:00
|
|
|
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)
|
|
|
|
=============================================================================*/
|
2011-11-26 06:20:35 +00:00
|
|
|
#ifndef SPROUT_DARKROOM_MATERIALS_MATERIAL_HPP
|
|
|
|
#define SPROUT_DARKROOM_MATERIALS_MATERIAL_HPP
|
|
|
|
|
2013-12-03 13:17:49 +00:00
|
|
|
#include <type_traits>
|
2011-11-26 06:20:35 +00:00
|
|
|
#include <sprout/config.hpp>
|
|
|
|
#include <sprout/tuple/tuple.hpp>
|
2013-12-03 13:17:49 +00:00
|
|
|
#include <sprout/tuple/indexes.hpp>
|
2011-11-26 06:20:35 +00:00
|
|
|
#include <sprout/utility/forward.hpp>
|
2013-12-03 13:17:49 +00:00
|
|
|
#include <sprout/type_traits/enabler_if.hpp>
|
2011-11-26 06:20:35 +00:00
|
|
|
#include <sprout/darkroom/access/access.hpp>
|
|
|
|
#include <sprout/darkroom/colors/rgb.hpp>
|
2013-09-24 06:08:36 +00:00
|
|
|
#include <sprout/darkroom/materials/calculate.hpp>
|
2011-11-26 06:20:35 +00:00
|
|
|
|
|
|
|
namespace sprout {
|
|
|
|
namespace darkroom {
|
|
|
|
namespace materials {
|
|
|
|
//
|
2013-12-03 13:17:49 +00:00
|
|
|
// material
|
|
|
|
//
|
|
|
|
typedef sprout::tuples::tuple<sprout::darkroom::colors::rgb_f_t, double, double, double> material;
|
|
|
|
|
2011-11-26 06:20:35 +00:00
|
|
|
//
|
2013-12-03 13:17:49 +00:00
|
|
|
// has_color
|
|
|
|
// has_reflection
|
|
|
|
// has_alpha
|
|
|
|
// has_refraction
|
|
|
|
//
|
|
|
|
template<typename T>
|
|
|
|
struct has_color
|
2014-12-10 10:54:12 +00:00
|
|
|
: public sprout::bool_constant<(sprout::darkroom::access::size<T>::value >= 1)>
|
2013-12-03 13:17:49 +00:00
|
|
|
{};
|
|
|
|
template<typename T>
|
|
|
|
struct has_reflection
|
2014-12-10 10:54:12 +00:00
|
|
|
: public sprout::bool_constant<(sprout::darkroom::access::size<T>::value >= 2)>
|
2013-12-03 13:17:49 +00:00
|
|
|
{};
|
2011-11-26 06:20:35 +00:00
|
|
|
template<typename T>
|
2013-12-03 13:17:49 +00:00
|
|
|
struct has_alpha
|
2014-12-10 10:54:12 +00:00
|
|
|
: public sprout::bool_constant<(sprout::darkroom::access::size<T>::value >= 3)>
|
2013-12-03 13:17:49 +00:00
|
|
|
{};
|
|
|
|
template<typename T>
|
|
|
|
struct has_refraction
|
2014-12-10 10:54:12 +00:00
|
|
|
: public sprout::bool_constant<(sprout::darkroom::access::size<T>::value >= 4)>
|
2013-12-03 13:17:49 +00:00
|
|
|
{};
|
|
|
|
|
|
|
|
//
|
|
|
|
// color
|
|
|
|
//
|
|
|
|
template<
|
|
|
|
typename T,
|
|
|
|
typename sprout::enabler_if<sprout::darkroom::materials::has_color<typename std::decay<T>::type>::value>::type = sprout::enabler
|
|
|
|
>
|
2012-10-05 15:58:56 +00:00
|
|
|
inline SPROUT_CONSTEXPR auto
|
|
|
|
color(T&& t)
|
2014-08-14 13:55:49 +00:00
|
|
|
SPROUT_NOEXCEPT_IF_EXPR(sprout::darkroom::access::get<0>(SPROUT_FORWARD(T, t)))
|
2014-02-22 07:32:51 +00:00
|
|
|
-> decltype(sprout::darkroom::access::get<0>(SPROUT_FORWARD(T, t)))
|
2011-11-26 06:20:35 +00:00
|
|
|
{
|
2014-02-22 07:32:51 +00:00
|
|
|
return sprout::darkroom::access::get<0>(SPROUT_FORWARD(T, t));
|
2011-11-26 06:20:35 +00:00
|
|
|
}
|
2013-12-03 13:17:49 +00:00
|
|
|
template<
|
|
|
|
typename T,
|
|
|
|
typename sprout::enabler_if<!sprout::darkroom::materials::has_color<typename std::decay<T>::type>::value>::type = sprout::enabler
|
|
|
|
>
|
|
|
|
inline SPROUT_CONSTEXPR typename sprout::darkroom::access::element<0, sprout::darkroom::materials::material>::type
|
|
|
|
color(T&&)
|
2014-08-14 13:55:49 +00:00
|
|
|
SPROUT_NOEXCEPT_IF_EXPR((typename sprout::darkroom::access::element<0, sprout::darkroom::materials::material>::type()))
|
2013-12-03 13:17:49 +00:00
|
|
|
{
|
|
|
|
return typename sprout::darkroom::access::element<0, sprout::darkroom::materials::material>::type();
|
|
|
|
}
|
|
|
|
//
|
|
|
|
// reflection
|
|
|
|
//
|
|
|
|
template<
|
|
|
|
typename T,
|
|
|
|
typename sprout::enabler_if<sprout::darkroom::materials::has_reflection<typename std::decay<T>::type>::value>::type = sprout::enabler
|
|
|
|
>
|
2012-10-05 15:58:56 +00:00
|
|
|
inline SPROUT_CONSTEXPR auto
|
|
|
|
reflection(T&& t)
|
2014-08-14 13:55:49 +00:00
|
|
|
SPROUT_NOEXCEPT_IF_EXPR(sprout::darkroom::access::get<1>(SPROUT_FORWARD(T, t)))
|
2014-02-22 07:32:51 +00:00
|
|
|
-> decltype(sprout::darkroom::access::get<1>(SPROUT_FORWARD(T, t)))
|
2011-11-26 06:20:35 +00:00
|
|
|
{
|
2014-02-22 07:32:51 +00:00
|
|
|
return sprout::darkroom::access::get<1>(SPROUT_FORWARD(T, t));
|
2011-11-26 06:20:35 +00:00
|
|
|
}
|
2013-12-03 13:17:49 +00:00
|
|
|
template<
|
|
|
|
typename T,
|
|
|
|
typename sprout::enabler_if<!sprout::darkroom::materials::has_reflection<typename std::decay<T>::type>::value>::type = sprout::enabler
|
|
|
|
>
|
|
|
|
inline SPROUT_CONSTEXPR typename sprout::darkroom::access::element<1, sprout::darkroom::materials::material>::type
|
|
|
|
reflection(T&&)
|
2014-08-14 13:55:49 +00:00
|
|
|
SPROUT_NOEXCEPT_IF_EXPR((typename sprout::darkroom::access::element<1, sprout::darkroom::materials::material>::type()))
|
2013-12-03 13:17:49 +00:00
|
|
|
{
|
|
|
|
return typename sprout::darkroom::access::element<1, sprout::darkroom::materials::material>::type();
|
|
|
|
}
|
|
|
|
//
|
|
|
|
// alpha
|
|
|
|
//
|
|
|
|
template<
|
|
|
|
typename T,
|
|
|
|
typename sprout::enabler_if<sprout::darkroom::materials::has_alpha<typename std::decay<T>::type>::value>::type = sprout::enabler
|
|
|
|
>
|
|
|
|
inline SPROUT_CONSTEXPR auto
|
|
|
|
alpha(T&& t)
|
2014-08-14 13:55:49 +00:00
|
|
|
SPROUT_NOEXCEPT_IF_EXPR(sprout::darkroom::access::get<2>(SPROUT_FORWARD(T, t)))
|
2014-02-22 07:32:51 +00:00
|
|
|
-> decltype(sprout::darkroom::access::get<2>(SPROUT_FORWARD(T, t)))
|
2013-12-03 13:17:49 +00:00
|
|
|
{
|
2014-02-22 07:32:51 +00:00
|
|
|
return sprout::darkroom::access::get<2>(SPROUT_FORWARD(T, t));
|
2013-12-03 13:17:49 +00:00
|
|
|
}
|
|
|
|
template<
|
|
|
|
typename T,
|
|
|
|
typename sprout::enabler_if<!sprout::darkroom::materials::has_alpha<typename std::decay<T>::type>::value>::type = sprout::enabler
|
|
|
|
>
|
|
|
|
inline SPROUT_CONSTEXPR typename sprout::darkroom::access::element<2, sprout::darkroom::materials::material>::type
|
|
|
|
alpha(T&&)
|
2014-08-14 13:55:49 +00:00
|
|
|
SPROUT_NOEXCEPT_IF_EXPR((typename sprout::darkroom::access::element<2, sprout::darkroom::materials::material>::type()))
|
2013-12-03 13:17:49 +00:00
|
|
|
{
|
|
|
|
return typename sprout::darkroom::access::element<2, sprout::darkroom::materials::material>::type();
|
|
|
|
}
|
|
|
|
//
|
|
|
|
// refraction
|
|
|
|
//
|
|
|
|
template<
|
|
|
|
typename T,
|
|
|
|
typename sprout::enabler_if<sprout::darkroom::materials::has_refraction<typename std::decay<T>::type>::value>::type = sprout::enabler
|
|
|
|
>
|
|
|
|
inline SPROUT_CONSTEXPR auto
|
|
|
|
refraction(T&& t)
|
2014-08-14 13:55:49 +00:00
|
|
|
SPROUT_NOEXCEPT_IF_EXPR(sprout::darkroom::access::get<3>(SPROUT_FORWARD(T, t)))
|
2014-02-22 07:32:51 +00:00
|
|
|
-> decltype(sprout::darkroom::access::get<3>(SPROUT_FORWARD(T, t)))
|
2013-12-03 13:17:49 +00:00
|
|
|
{
|
2014-02-22 07:32:51 +00:00
|
|
|
return sprout::darkroom::access::get<3>(SPROUT_FORWARD(T, t));
|
2013-12-03 13:17:49 +00:00
|
|
|
}
|
|
|
|
template<
|
|
|
|
typename T,
|
|
|
|
typename sprout::enabler_if<!sprout::darkroom::materials::has_refraction<typename std::decay<T>::type>::value>::type = sprout::enabler
|
|
|
|
>
|
|
|
|
inline SPROUT_CONSTEXPR typename sprout::darkroom::access::element<3, sprout::darkroom::materials::material>::type
|
|
|
|
refraction(T&&)
|
2014-08-14 13:55:49 +00:00
|
|
|
SPROUT_NOEXCEPT_IF_EXPR((typename sprout::darkroom::access::element<3, sprout::darkroom::materials::material>::type()))
|
2013-12-03 13:17:49 +00:00
|
|
|
{
|
2013-12-12 14:29:50 +00:00
|
|
|
return typename sprout::darkroom::access::element<3, sprout::darkroom::materials::material>::type();
|
2013-12-03 13:17:49 +00:00
|
|
|
}
|
2011-11-26 06:20:35 +00:00
|
|
|
|
|
|
|
//
|
2013-09-24 06:08:36 +00:00
|
|
|
// calculate_material
|
2011-11-26 06:20:35 +00:00
|
|
|
//
|
2013-12-03 13:17:49 +00:00
|
|
|
namespace detail {
|
|
|
|
template<typename Material, typename Unit, sprout::index_t... Indexes>
|
|
|
|
inline SPROUT_CONSTEXPR auto
|
|
|
|
calculate_material_impl(Material const& mat, Unit const& u, Unit const& v, sprout::index_tuple<Indexes...>)
|
|
|
|
-> decltype(sprout::tuples::make_tuple(
|
|
|
|
sprout::darkroom::materials::calculate(sprout::darkroom::access::get<Indexes>(mat), u, v)...
|
|
|
|
))
|
|
|
|
{
|
|
|
|
return sprout::tuples::make_tuple(
|
|
|
|
sprout::darkroom::materials::calculate(sprout::darkroom::access::get<Indexes>(mat), u, v)...
|
|
|
|
);
|
|
|
|
}
|
|
|
|
} // namespace detail
|
2011-12-12 19:01:10 +00:00
|
|
|
template<typename Material, typename Unit>
|
2012-10-05 15:58:56 +00:00
|
|
|
inline SPROUT_CONSTEXPR auto
|
2013-09-24 06:08:36 +00:00
|
|
|
calculate_material(Material const& mat, Unit const& u, Unit const& v)
|
2013-12-03 13:17:49 +00:00
|
|
|
-> decltype(sprout::darkroom::materials::detail::calculate_material_impl(mat, u, v, sprout::tuples::tuple_indexes<Material>::make()))
|
2011-11-26 06:20:35 +00:00
|
|
|
{
|
2013-12-03 13:17:49 +00:00
|
|
|
return sprout::darkroom::materials::detail::calculate_material_impl(mat, u, v, sprout::tuples::tuple_indexes<Material>::make());
|
2011-11-26 06:20:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// make_material_image
|
|
|
|
//
|
2013-12-03 13:17:49 +00:00
|
|
|
template<typename... Images>
|
|
|
|
inline SPROUT_CONSTEXPR sprout::tuples::tuple<Images...>
|
|
|
|
make_material_image(Images const&... images) {
|
|
|
|
return sprout::tuples::make_tuple(images...);
|
2011-11-26 06:20:35 +00:00
|
|
|
}
|
|
|
|
} // namespace materials
|
|
|
|
} // namespace darkroom
|
|
|
|
} // namespace sprout
|
|
|
|
|
|
|
|
#endif // #ifndef SPROUT_DARKROOM_MATERIALS_MATERIAL_HPP
|