2013-08-08 09:54:33 +00:00
|
|
|
/*=============================================================================
|
|
|
|
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)
|
|
|
|
=============================================================================*/
|
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
|
|
|
|
: public sprout::integral_constant<bool, (sprout::darkroom::access::size<T>::value >= 1)>
|
|
|
|
{};
|
|
|
|
template<typename T>
|
|
|
|
struct has_reflection
|
|
|
|
: public sprout::integral_constant<bool, (sprout::darkroom::access::size<T>::value >= 2)>
|
|
|
|
{};
|
2011-11-26 06:20:35 +00:00
|
|
|
template<typename T>
|
2013-12-03 13:17:49 +00:00
|
|
|
struct has_alpha
|
|
|
|
: public sprout::integral_constant<bool, (sprout::darkroom::access::size<T>::value >= 3)>
|
|
|
|
{};
|
|
|
|
template<typename T>
|
|
|
|
struct has_refraction
|
|
|
|
: public sprout::integral_constant<bool, (sprout::darkroom::access::size<T>::value >= 4)>
|
|
|
|
{};
|
|
|
|
|
|
|
|
//
|
|
|
|
// 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)
|
|
|
|
SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::darkroom::access::get<0>(sprout::forward<T>(t))))
|
|
|
|
-> decltype(sprout::darkroom::access::get<0>(sprout::forward<T>(t)))
|
2011-11-26 06:20:35 +00:00
|
|
|
{
|
|
|
|
return sprout::darkroom::access::get<0>(sprout::forward<T>(t));
|
|
|
|
}
|
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&&)
|
|
|
|
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<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)
|
|
|
|
SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::darkroom::access::get<1>(sprout::forward<T>(t))))
|
|
|
|
-> decltype(sprout::darkroom::access::get<1>(sprout::forward<T>(t)))
|
2011-11-26 06:20:35 +00:00
|
|
|
{
|
|
|
|
return sprout::darkroom::access::get<1>(sprout::forward<T>(t));
|
|
|
|
}
|
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&&)
|
|
|
|
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<sprout::darkroom::materials::has_alpha<typename std::decay<T>::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>(t))))
|
|
|
|
-> decltype(sprout::darkroom::access::get<2>(sprout::forward<T>(t)))
|
|
|
|
{
|
|
|
|
return sprout::darkroom::access::get<2>(sprout::forward<T>(t));
|
|
|
|
}
|
|
|
|
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&&)
|
|
|
|
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<sprout::darkroom::materials::has_refraction<typename std::decay<T>::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>(t))))
|
|
|
|
-> decltype(sprout::darkroom::access::get<3>(sprout::forward<T>(t)))
|
|
|
|
{
|
|
|
|
return sprout::darkroom::access::get<3>(sprout::forward<T>(t));
|
|
|
|
}
|
|
|
|
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&&)
|
|
|
|
SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR((typename sprout::darkroom::access::element<3, sprout::darkroom::materials::material>::type())))
|
|
|
|
{
|
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
|