fix darkroom: add alpha and refraction material parameter

This commit is contained in:
bolero-MURAKAMI 2013-12-03 22:17:49 +09:00
parent 4b5dd8ccc5
commit 014d339803
7 changed files with 263 additions and 81 deletions

View file

@ -21,26 +21,22 @@ namespace darkcult {
objects::aa_plane_direction::y, objects::aa_plane_direction::y,
-2.0, -2.0,
materials::make_plaid_material_image( materials::make_plaid_material_image(
colors::rgb_f(1.0, 0.0, 0.0), colors::rgb_f(1.0, 0.0, 0.0), colors::rgb_f(1.0, 1.0, 0.0),
colors::rgb_f(1.0, 1.0, 0.0), 0.0, 0.0
0.0,
0.0
) )
), ),
objects::make_sphere( objects::make_sphere(
coords::vector3d(-1.0, 0.5, 7.5), coords::vector3d(-1.0, 0.5, 7.5),
2.5, 2.5,
materials::make_uniform_material_image( materials::make_uniform_material_image(
colors::rgb_f(0.0, 0.0, 1.0), colors::rgb_f(0.0, 0.0, 1.0), 0.2
0.2
) )
), ),
objects::make_sphere( objects::make_sphere(
coords::vector3d(1.0, -1.0, 4.0), coords::vector3d(1.0, -1.0, 4.0),
1.0, 1.0,
materials::make_uniform_material_image( materials::make_uniform_material_image(
colors::rgb_f(0.0, 1.0, 0.0), colors::rgb_f(0.0, 1.0, 0.0), 0.2
0.2
) )
) )
); );

View file

@ -14,11 +14,21 @@
#include <sprout/tuple/tuple.hpp> #include <sprout/tuple/tuple.hpp>
#include <sprout/tuple/functions.hpp> #include <sprout/tuple/functions.hpp>
#include <sprout/utility/forward.hpp> #include <sprout/utility/forward.hpp>
#include <sprout/type_traits/integral_constant.hpp>
#include <sprout/type_traits/enabler_if.hpp>
#include <sprout/darkroom/access/access.hpp> #include <sprout/darkroom/access/access.hpp>
namespace sprout { namespace sprout {
namespace darkroom { namespace darkroom {
namespace colors { namespace colors {
//
// has_alpha
//
template<typename T>
struct has_alpha
: public sprout::integral_constant<bool, (sprout::darkroom::access::size<T>::value >= 4)>
{};
// //
// r // r
// g // g
@ -49,7 +59,13 @@ namespace sprout {
{ {
return sprout::darkroom::access::get<2>(sprout::forward<T>(t)); return sprout::darkroom::access::get<2>(sprout::forward<T>(t));
} }
template<typename T> //
// a
//
template<
typename T,
typename sprout::enabler_if<sprout::darkroom::colors::has_alpha<T>::value>::type = sprout::enabler
>
inline SPROUT_CONSTEXPR auto inline SPROUT_CONSTEXPR auto
a(T&& t) a(T&& t)
SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::darkroom::access::get<3>(sprout::forward<T>(t)))) SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::darkroom::access::get<3>(sprout::forward<T>(t))))
@ -57,13 +73,22 @@ namespace sprout {
{ {
return 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::colors::has_alpha<T>::value>::type = sprout::enabler
>
inline SPROUT_CONSTEXPR typename sprout::darkroom::access::unit<T>::type
a(T&&)
SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(typename sprout::darkroom::access::unit<T>::type()))
{
return typename sprout::darkroom::access::unit<T>::type();
}
// //
// rgb_t // rgb_t
// rgb // rgb
// //
typedef sprout::tuples::tuple<std::uint8_t, std::uint8_t, std::uint8_t> rgb_t; typedef sprout::tuples::tuple<std::uint8_t, std::uint8_t, std::uint8_t> rgb_t;
inline SPROUT_CONSTEXPR sprout::darkroom::colors::rgb_t inline SPROUT_CONSTEXPR sprout::darkroom::colors::rgb_t
rgb(std::uint8_t r = 0, std::uint8_t g = 0, std::uint8_t b = 0) { rgb(std::uint8_t r = 0, std::uint8_t g = 0, std::uint8_t b = 0) {
return sprout::darkroom::colors::rgb_t(r, g, b); return sprout::darkroom::colors::rgb_t(r, g, b);
@ -74,7 +99,6 @@ namespace sprout {
// rgb_f // rgb_f
// //
typedef sprout::tuples::tuple<double, double, double> rgb_f_t; typedef sprout::tuples::tuple<double, double, double> rgb_f_t;
inline SPROUT_CONSTEXPR sprout::darkroom::colors::rgb_f_t inline SPROUT_CONSTEXPR sprout::darkroom::colors::rgb_f_t
rgb_f(double r = 0, double g = 0, double b = 0) { rgb_f(double r = 0, double g = 0, double b = 0) {
return sprout::darkroom::colors::rgb_f_t(r, g, b); return sprout::darkroom::colors::rgb_f_t(r, g, b);

View file

@ -11,6 +11,7 @@
#include <sprout/config.hpp> #include <sprout/config.hpp>
#include <sprout/tuple/tuple.hpp> #include <sprout/tuple/tuple.hpp>
#include <sprout/utility/forward.hpp> #include <sprout/utility/forward.hpp>
#include <sprout/type_traits/enabler_if.hpp>
#include <sprout/darkroom/access/access.hpp> #include <sprout/darkroom/access/access.hpp>
#include <sprout/darkroom/coords/vector.hpp> #include <sprout/darkroom/coords/vector.hpp>
#include <sprout/darkroom/materials/material.hpp> #include <sprout/darkroom/materials/material.hpp>
@ -18,12 +19,33 @@
namespace sprout { namespace sprout {
namespace darkroom { namespace darkroom {
namespace intersects { namespace intersects {
//
// intersection
//
typedef sprout::tuples::tuple<
bool,
double,
sprout::darkroom::coords::vector3d_t,
sprout::darkroom::coords::vector3d_t,
sprout::darkroom::materials::material,
bool
> intersection;
//
// has_is_from_inside
//
template<typename T>
struct has_is_from_inside
: public sprout::integral_constant<bool, (sprout::darkroom::access::size<T>::value >= 6)>
{};
// //
// does_intersect // does_intersect
// distance // distance
// point_of_intersection // point_of_intersection
// normal // normal
// material // material
// is_from_inside
// //
template<typename T> template<typename T>
inline SPROUT_CONSTEXPR auto inline SPROUT_CONSTEXPR auto
@ -65,26 +87,36 @@ namespace sprout {
{ {
return sprout::darkroom::access::get<4>(sprout::forward<T>(t)); return sprout::darkroom::access::get<4>(sprout::forward<T>(t));
} }
template<
typename T,
typename sprout::enabler_if<sprout::darkroom::intersects::has_is_from_inside<T>::value>::type = sprout::enabler
>
inline SPROUT_CONSTEXPR auto
is_from_inside(T&& t)
SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::darkroom::access::get<5>(sprout::forward<T>(t))))
-> decltype(sprout::darkroom::access::get<5>(sprout::forward<T>(t)))
{
return sprout::darkroom::access::get<5>(sprout::forward<T>(t));
}
template<
typename T,
typename sprout::enabler_if<!sprout::darkroom::intersects::has_is_from_inside<T>::value>::type = sprout::enabler
>
inline SPROUT_CONSTEXPR typename sprout::darkroom::access::element<5, sprout::darkroom::intersects::intersection>::type
is_from_inside(T&&)
SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR((typename sprout::darkroom::access::element<5, sprout::darkroom::intersects::intersection>::type())))
{
return typename sprout::darkroom::access::element<5, sprout::darkroom::intersects::intersection>::type();
}
// //
// make_intersection // make_intersection
// //
template<typename Distance, typename Point, typename Normal, typename Material> template<typename... Elements>
inline SPROUT_CONSTEXPR sprout::tuples::tuple<bool, Distance, Point, Normal, Material> inline SPROUT_CONSTEXPR sprout::tuples::tuple<Elements...>
make_intersection(bool b, Distance const& dist, Point const& p, Normal const& nor, Material const& mat) { make_material_image(Elements const&... elems) {
return sprout::tuples::make_tuple(b, dist, p, nor, mat); return sprout::tuples::make_tuple(elems...);
} }
//
// intersection
//
typedef sprout::tuples::tuple<
bool,
double,
sprout::darkroom::coords::vector3d_t,
sprout::darkroom::coords::vector3d_t,
sprout::darkroom::materials::material
> intersection;
} // namespace intersects } // namespace intersects
} // namespace darkroom } // namespace darkroom
} // namespace sprout } // namespace sprout

View file

@ -8,9 +8,12 @@
#ifndef SPROUT_DARKROOM_MATERIALS_MATERIAL_HPP #ifndef SPROUT_DARKROOM_MATERIALS_MATERIAL_HPP
#define SPROUT_DARKROOM_MATERIALS_MATERIAL_HPP #define SPROUT_DARKROOM_MATERIALS_MATERIAL_HPP
#include <type_traits>
#include <sprout/config.hpp> #include <sprout/config.hpp>
#include <sprout/tuple/tuple.hpp> #include <sprout/tuple/tuple.hpp>
#include <sprout/tuple/indexes.hpp>
#include <sprout/utility/forward.hpp> #include <sprout/utility/forward.hpp>
#include <sprout/type_traits/enabler_if.hpp>
#include <sprout/darkroom/access/access.hpp> #include <sprout/darkroom/access/access.hpp>
#include <sprout/darkroom/colors/rgb.hpp> #include <sprout/darkroom/colors/rgb.hpp>
#include <sprout/darkroom/materials/calculate.hpp> #include <sprout/darkroom/materials/calculate.hpp>
@ -19,10 +22,40 @@ namespace sprout {
namespace darkroom { namespace darkroom {
namespace materials { namespace materials {
// //
// color // material
// reflection //
typedef sprout::tuples::tuple<sprout::darkroom::colors::rgb_f_t, double, double, double> material;
//
// has_color
// has_reflection
// has_alpha
// has_refraction
// //
template<typename T> 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)>
{};
template<typename T>
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
>
inline SPROUT_CONSTEXPR auto inline SPROUT_CONSTEXPR auto
color(T&& t) color(T&& t)
SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::darkroom::access::get<0>(sprout::forward<T>(t)))) SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::darkroom::access::get<0>(sprout::forward<T>(t))))
@ -30,7 +63,23 @@ namespace sprout {
{ {
return sprout::darkroom::access::get<0>(sprout::forward<T>(t)); return sprout::darkroom::access::get<0>(sprout::forward<T>(t));
} }
template<typename T> 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
>
inline SPROUT_CONSTEXPR auto inline SPROUT_CONSTEXPR auto
reflection(T&& t) reflection(T&& t)
SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::darkroom::access::get<1>(sprout::forward<T>(t)))) SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::darkroom::access::get<1>(sprout::forward<T>(t))))
@ -38,37 +87,97 @@ namespace sprout {
{ {
return sprout::darkroom::access::get<1>(sprout::forward<T>(t)); return sprout::darkroom::access::get<1>(sprout::forward<T>(t));
} }
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())))
{
return typename sprout::darkroom::access::element<1, sprout::darkroom::materials::material>::type();
}
// //
// calculate_material // calculate_material
// //
template<typename Material, typename Unit> namespace detail {
template<typename Material, typename Unit, sprout::index_t... Indexes>
inline SPROUT_CONSTEXPR auto inline SPROUT_CONSTEXPR auto
calculate_material(Material const& mat, Unit const& u, Unit const& v) calculate_material_impl(Material const& mat, Unit const& u, Unit const& v, sprout::index_tuple<Indexes...>)
-> decltype(sprout::tuples::make_tuple( -> decltype(sprout::tuples::make_tuple(
sprout::darkroom::materials::calculate(sprout::darkroom::materials::color(mat), u, v), sprout::darkroom::materials::calculate(sprout::darkroom::access::get<Indexes>(mat), u, v)...
sprout::darkroom::materials::calculate(sprout::darkroom::materials::reflection(mat), u, v)
)) ))
{ {
return sprout::tuples::make_tuple( return sprout::tuples::make_tuple(
sprout::darkroom::materials::calculate(sprout::darkroom::materials::color(mat), u, v), sprout::darkroom::materials::calculate(sprout::darkroom::access::get<Indexes>(mat), u, v)...
sprout::darkroom::materials::calculate(sprout::darkroom::materials::reflection(mat), u, v)
); );
} }
} // namespace detail
template<typename Material, typename Unit>
inline SPROUT_CONSTEXPR auto
calculate_material(Material const& mat, Unit const& u, Unit const& v)
-> decltype(sprout::darkroom::materials::detail::calculate_material_impl(mat, u, v, sprout::tuples::tuple_indexes<Material>::make()))
{
return sprout::darkroom::materials::detail::calculate_material_impl(mat, u, v, sprout::tuples::tuple_indexes<Material>::make());
}
// //
// make_material_image // make_material_image
// //
template<typename ColorImage, typename ReflectionImage> template<typename... Images>
inline SPROUT_CONSTEXPR sprout::tuples::tuple<ColorImage, ReflectionImage> inline SPROUT_CONSTEXPR sprout::tuples::tuple<Images...>
make_material_image(ColorImage const& col, ReflectionImage const& ref) { make_material_image(Images const&... images) {
return sprout::tuples::make_tuple(col, ref); return sprout::tuples::make_tuple(images...);
} }
//
// material
//
typedef sprout::tuples::tuple<sprout::darkroom::colors::rgb_f_t, double> material;
} // namespace materials } // namespace materials
} // namespace darkroom } // namespace darkroom
} // namespace sprout } // namespace sprout

View file

@ -11,6 +11,9 @@
#include <cstdint> #include <cstdint>
#include <sprout/config.hpp> #include <sprout/config.hpp>
#include <sprout/tuple/tuple.hpp> #include <sprout/tuple/tuple.hpp>
#include <sprout/index_tuple/make_index_tuple.hpp>
#include <sprout/utility/pack.hpp>
#include <sprout/type_traits/enabler_if.hpp>
#include <sprout/math/fmod.hpp> #include <sprout/math/fmod.hpp>
namespace sprout { namespace sprout {
@ -74,37 +77,57 @@ namespace sprout {
// //
// make_plaid_material_image // make_plaid_material_image
// //
template<typename Color, typename Reflection> namespace detail {
inline SPROUT_CONSTEXPR sprout::tuples::tuple< template<typename... Elements, sprout::index_t... Indexes>
sprout::darkroom::materials::plaid_element<Color>, inline SPROUT_CONSTEXPR auto
sprout::darkroom::materials::plaid_element<Reflection> make_plaid_material_image_impl(
> sprout::index_tuple<Indexes...>,
make_plaid_material_image( Elements const&... elems
Color const& col1, Color const& col2,
Reflection const& ref1, Reflection const& ref2
) )
-> decltype(sprout::tuples::make_tuple(
sprout::darkroom::materials::make_plaid(sprout::pack_get<Indexes * 2>(elems...), sprout::pack_get<Indexes * 2 + 1>(elems...))...
))
{ {
return sprout::tuples::make_tuple( return sprout::tuples::make_tuple(
sprout::darkroom::materials::make_plaid(col1, col2), sprout::darkroom::materials::make_plaid(sprout::pack_get<Indexes * 2>(elems...), sprout::pack_get<Indexes * 2 + 1>(elems...))...
sprout::darkroom::materials::make_plaid(ref1, ref2)
); );
} }
template<typename Color, typename Reflection, typename Unit> template<typename Unit, typename... Elements, sprout::index_t... Indexes>
inline SPROUT_CONSTEXPR sprout::tuples::tuple< inline SPROUT_CONSTEXPR auto
sprout::darkroom::materials::plaid_element<Color, Unit>, make_plaid_material_image_impl(
sprout::darkroom::materials::plaid_element<Reflection, Unit> Unit const& scale,
> sprout::index_tuple<Indexes...>,
make_plaid_material_image( Elements const&... elems
Color const& col1, Color const& col2,
Reflection const& ref1, Reflection const& ref2,
Unit const& scale
) )
-> decltype(sprout::tuples::make_tuple(
sprout::darkroom::materials::make_plaid(sprout::pack_get<Indexes * 2>(elems...), sprout::pack_get<Indexes * 2 + 1>(elems...), scale)...
))
{ {
return sprout::tuples::make_tuple( return sprout::tuples::make_tuple(
sprout::darkroom::materials::make_plaid(col1, col2, scale), sprout::darkroom::materials::make_plaid(sprout::pack_get<Indexes * 2>(elems...), sprout::pack_get<Indexes * 2 + 1>(elems...), scale)...
sprout::darkroom::materials::make_plaid(ref1, ref2, scale)
); );
} }
} // namespace detail
template<
typename... Elements,
typename sprout::enabler_if<sizeof...(Elements) % 2 == 0>::type = sprout::enabler
>
inline SPROUT_CONSTEXPR auto
make_plaid_material_image(Elements const&... elems)
-> decltype(sprout::darkroom::materials::detail::make_plaid_material_image_impl(sprout::make_index_tuple<sizeof...(Elements) / 2>::make(), elems...))
{
return sprout::darkroom::materials::detail::make_plaid_material_image_impl(sprout::make_index_tuple<sizeof...(Elements) / 2>::make(), elems...);
}
template<
typename Unit, typename... Elements,
typename sprout::enabler_if<sizeof...(Elements) % 2 == 0>::type = sprout::enabler
>
inline SPROUT_CONSTEXPR auto
make_plaid_material_image(Unit const& scale, Elements const&... elems)
-> decltype(sprout::darkroom::materials::detail::make_plaid_material_image_impl(scale, sprout::make_index_tuple<sizeof...(Elements) / 2>::make(), elems...))
{
return sprout::darkroom::materials::detail::make_plaid_material_image_impl(scale, sprout::make_index_tuple<sizeof...(Elements) / 2>::make(), elems...);
}
} // namespace materials } // namespace materials
} // namespace darkroom } // namespace darkroom
} // namespace sprout } // namespace sprout

View file

@ -44,15 +44,13 @@ namespace sprout {
// //
// make_uniform_material_image // make_uniform_material_image
// //
template<typename Color, typename Reflection> template<typename... Elements>
inline SPROUT_CONSTEXPR sprout::tuples::tuple< inline SPROUT_CONSTEXPR sprout::tuples::tuple<
sprout::darkroom::materials::uniform_element<Color>, sprout::darkroom::materials::uniform_element<Elements>...
sprout::darkroom::materials::uniform_element<Reflection>
> >
make_uniform_material_image(Color const& col, Reflection const& ref) { make_uniform_material_image(Elements const&... elems) {
return sprout::tuples::make_tuple( return sprout::tuples::make_tuple(
sprout::darkroom::materials::make_uniform(col), sprout::darkroom::materials::make_uniform(elems)...
sprout::darkroom::materials::make_uniform(ref)
); );
} }
} // namespace materials } // namespace materials

View file

@ -40,10 +40,10 @@ namespace sprout {
struct pack_get_helper; struct pack_get_helper;
template<typename... Args> template<typename... Args>
struct pack_get_helper<sprout::types::type_tuple<Args...> > { struct pack_get_helper<sprout::types::type_tuple<Args...> > {
template<typename T> template<typename Head, typename... Tail>
static SPROUT_CONSTEXPR T&& static SPROUT_CONSTEXPR Head&&
eval(Args&&..., T&& t, ...) { eval(Args&&..., Head&& head, Tail&&...) {
return sprout::forward<T>(t); return sprout::forward<Head>(head);
} }
}; };
} // namespace detail } // namespace detail