sprout/darkroom/* 追加

This commit is contained in:
bolero-MURAKAMI 2011-11-26 15:20:35 +09:00
parent 1c898f8b93
commit 212e9ea652
27 changed files with 1692 additions and 4 deletions

18
sprout/darkroom.hpp Normal file
View file

@ -0,0 +1,18 @@
#ifndef SPROUT_DARKROOM_HPP
#define SPROUT_DARKROOM_HPP
#include <sprout/config.hpp>
#include <sprout/darkroom/access.hpp>
#include <sprout/darkroom/colors.hpp>
#include <sprout/darkroom/coords.hpp>
#include <sprout/darkroom/rays.hpp>
#include <sprout/darkroom/materials.hpp>
#include <sprout/darkroom/intersects.hpp>
#include <sprout/darkroom/objects.hpp>
#include <sprout/darkroom/lights.hpp>
#include <sprout/darkroom/cameras.hpp>
#include <sprout/darkroom/renderers.hpp>
#include <sprout/darkroom/tracers.hpp>
#include <sprout/darkroom/pixels.hpp>
#endif // #ifndef SPROUT_DARKROOM_HPP

View file

@ -0,0 +1,7 @@
#ifndef SPROUT_DARKROOM_ACCESS_HPP
#define SPROUT_DARKROOM_ACCESS_HPP
#include <sprout/config.hpp>
#include <sprout/darkroom/access/access.hpp>
#endif // #ifndef SPROUT_DARKROOM_ACCESS_HPP

View file

@ -0,0 +1,48 @@
#ifndef SPROUT_DARKROOM_ACCESS_ACCESS_HPP
#define SPROUT_DARKROOM_ACCESS_ACCESS_HPP
#include <cstddef>
#include <sprout/config.hpp>
#include <sprout/tuple/tuple.hpp>
#include <sprout/utility/forward.hpp>
namespace sprout {
namespace darkroom {
namespace access {
//
// element
//
template<std::size_t I, typename T>
struct element
: public sprout::tuples::tuple_element<I, T>
{};
//
// size
//
template<typename T>
struct size
: public sprout::tuples::tuple_size<T>
{};
//
// unit
//
template<typename T>
struct unit
: public sprout::darkroom::access::element<0, T>
{};
//
// get
//
template<std::size_t I, typename T>
SPROUT_CONSTEXPR auto get(
T&& t
) SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::tuples::get<I>(sprout::forward<T>(t))))
-> decltype(sprout::tuples::get<I>(sprout::forward<T>(t)))
{
return sprout::tuples::get<I>(sprout::forward<T>(t));
}
} // namespace access
} // namespace darkroom
} // namespace sprout
#endif // #ifndef SPROUT_DARKROOM_ACCESS_ACCESS_HPP

View file

@ -0,0 +1,7 @@
#ifndef SPROUT_DARKROOM_CAMERAS_HPP
#define SPROUT_DARKROOM_CAMERAS_HPP
#include <sprout/config.hpp>
#include <sprout/darkroom/cameras/simple_camera.hpp>
#endif // #ifndef SPROUT_DARKROOM_CAMERAS_HPP

View file

@ -0,0 +1,44 @@
#ifndef SPROUT_DARKROOM_CAMERAS_SIMPLE_CAMERA_HPP
#define SPROUT_DARKROOM_CAMERAS_SIMPLE_CAMERA_HPP
#include <sprout/config.hpp>
#include <sprout/tuple/tuple.hpp>
#include <sprout/darkroom/coords/vector.hpp>
namespace sprout {
namespace darkroom {
namespace cameras {
template<typename Unit = double>
class basic_simple_camera {
public:
typedef Unit unit_type;
typedef sprout::tuples::tuple<unit_type, unit_type, unit_type> position_type;
typedef sprout::tuples::tuple<position_type, position_type> ray_type;
private:
unit_type far_plane_;
public:
SPROUT_CONSTEXPR explicit basic_simple_camera(
unit_type const& far_plane
)
: far_plane_(far_plane)
{}
SPROUT_CONSTEXPR ray_type operator()(unit_type const& u, unit_type const& v) const {
return ray_type(
position_type(0, 0, 0),
sprout::darkroom::coords::normalize(position_type(u, v, far_plane_))
);
}
};
//
// make_simple_camera
//
template<typename Unit>
SPROUT_CONSTEXPR inline sprout::darkroom::cameras::basic_simple_camera<Unit>
make_simple_camera(Unit const& far_plane) {
return sprout::darkroom::cameras::basic_simple_camera<Unit>(far_plane);
}
} // namespace cameras
} // namespace darkroom
} // namespace sprout
#endif // #ifndef SPROUT_DARKROOM_CAMERAS_SIMPLE_CAMERA_HPP

View file

@ -0,0 +1,7 @@
#ifndef SPROUT_DARKROOM_COLORS_HPP
#define SPROUT_DARKROOM_COLORS_HPP
#include <sprout/config.hpp>
#include <sprout/darkroom/colors/rgb.hpp>
#endif // #ifndef SPROUT_DARKROOM_COLORS_HPP

View file

@ -0,0 +1,122 @@
#ifndef SPROUT_DARKROOM_COLORS_RGB_HPP
#define SPROUT_DARKROOM_COLORS_RGB_HPP
#include <cstdint>
#include <limits>
#include <sprout/config.hpp>
#include <sprout/tuple/tuple.hpp>
#include <sprout/tuple/functions.hpp>
#include <sprout/utility/forward.hpp>
#include <sprout/darkroom/access/access.hpp>
namespace sprout {
namespace darkroom {
namespace colors {
//
// r
// g
// b
// a
//
template<typename T>
SPROUT_CONSTEXPR auto r(
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)))
{
return sprout::darkroom::access::get<0>(sprout::forward<T>(t));
}
template<typename T>
SPROUT_CONSTEXPR auto g(
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)))
{
return sprout::darkroom::access::get<1>(sprout::forward<T>(t));
}
template<typename T>
SPROUT_CONSTEXPR auto b(
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>
SPROUT_CONSTEXPR auto a(
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));
}
//
// rgb
// rgb_f
//
typedef sprout::tuples::tuple<std::uint8_t, std::uint8_t, std::uint8_t> rgb;
typedef sprout::tuples::tuple<double, double, double> rgb_f;
//
// mul
//
template<typename Color, typename Fac>
SPROUT_CONSTEXPR inline Color mul(Color const& lhs, Fac const& rhs) {
return sprout::tuples::remake_clone<Color>(
lhs,
sprout::darkroom::colors::r(lhs) * rhs,
sprout::darkroom::colors::g(lhs) * rhs,
sprout::darkroom::colors::b(lhs) * rhs
);
}
//
// add
//
template<typename Color1, typename Color2>
SPROUT_CONSTEXPR inline Color1 add(Color1 const& lhs, Color2 const& rhs) {
return sprout::tuples::remake_clone<Color1>(
lhs,
sprout::darkroom::colors::r(lhs) + sprout::darkroom::colors::r(rhs),
sprout::darkroom::colors::g(lhs) + sprout::darkroom::colors::g(rhs),
sprout::darkroom::colors::b(lhs) + sprout::darkroom::colors::b(rhs)
);
}
//
// filter
//
template<typename Color1, typename Color2>
SPROUT_CONSTEXPR inline Color1 filter(Color1 const& lhs, Color2 const& rhs) {
return sprout::tuples::remake_clone<Color1>(
lhs,
sprout::darkroom::colors::r(lhs) * sprout::darkroom::colors::r(rhs),
sprout::darkroom::colors::g(lhs) * sprout::darkroom::colors::g(rhs),
sprout::darkroom::colors::b(lhs) * sprout::darkroom::colors::b(rhs)
);
}
//
// rgb_f_to_rgb
//
template<typename RGB, typename RGB_F>
SPROUT_CONSTEXPR inline RGB rgb_f_to_rgb(RGB_F const& col) {
typedef typename sprout::darkroom::access::unit<RGB>::type unit_type;
return sprout::tuples::make_clone<RGB>(
sprout::darkroom::colors::r(col) < 0 ? std::numeric_limits<unit_type>::min()
: sprout::darkroom::colors::r(col) > 1 ? std::numeric_limits<unit_type>::max()
: sprout::darkroom::colors::r(col) * std::numeric_limits<unit_type>::max()
,
sprout::darkroom::colors::g(col) < 0 ? std::numeric_limits<unit_type>::min()
: sprout::darkroom::colors::g(col) > 1 ? std::numeric_limits<unit_type>::max()
: sprout::darkroom::colors::g(col) * std::numeric_limits<unit_type>::max()
,
sprout::darkroom::colors::b(col) < 0 ? std::numeric_limits<unit_type>::min()
: sprout::darkroom::colors::b(col) > 1 ? std::numeric_limits<unit_type>::max()
: sprout::darkroom::colors::b(col) * std::numeric_limits<unit_type>::max()
);
}
} // namespace colors
} // namespace darkroom
} // namespace sprout
#endif // #ifndef SPROUT_DARKROOM_COLORS_RGB_HPP

View file

@ -0,0 +1,7 @@
#ifndef SPROUT_DARKROOM_COORDS_HPP
#define SPROUT_DARKROOM_COORDS_HPP
#include <sprout/config.hpp>
#include <sprout/darkroom/coords/vector.hpp>
#endif // #ifndef SPROUT_DARKROOM_COORDS_HPP

View file

@ -0,0 +1,167 @@
#ifndef SPROUT_DARKROOM_COORDS_VECTOR_HPP
#define SPROUT_DARKROOM_COORDS_VECTOR_HPP
#include <cmath>
#include <sprout/config.hpp>
#include <sprout/tuple/tuple.hpp>
#include <sprout/tuple/functions.hpp>
#include <sprout/utility/forward.hpp>
#include <sprout/darkroom/access/access.hpp>
namespace sprout {
namespace darkroom {
namespace coords {
//
// x
// y
// z
//
template<typename T>
SPROUT_CONSTEXPR auto x(
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)))
{
return sprout::darkroom::access::get<0>(sprout::forward<T>(t));
}
template<typename T>
SPROUT_CONSTEXPR auto y(
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)))
{
return sprout::darkroom::access::get<1>(sprout::forward<T>(t));
}
template<typename T>
SPROUT_CONSTEXPR auto z(
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));
}
//
// vector3d
//
typedef sprout::tuples::tuple<double, double, double> vector3d;
//
// length_sq
//
template<typename Vector>
SPROUT_CONSTEXPR inline typename sprout::darkroom::access::unit<Vector>::type
length_sq(Vector const& vec) {
return sprout::darkroom::coords::x(vec) * sprout::darkroom::coords::x(vec)
+ sprout::darkroom::coords::y(vec) * sprout::darkroom::coords::y(vec)
+ sprout::darkroom::coords::z(vec) * sprout::darkroom::coords::z(vec)
;
}
//
// length
//
template<typename Vector>
SPROUT_CONSTEXPR inline typename sprout::darkroom::access::unit<Vector>::type
length(Vector const& vec) {
using std::sqrt;
return sqrt(sprout::darkroom::coords::length_sq(vec));
}
//
// add
//
template<typename Vector1, typename Vector2>
SPROUT_CONSTEXPR inline Vector1 add(Vector1 const& lhs, Vector2 const& rhs) {
return sprout::tuples::remake_clone<Vector1>(
lhs,
sprout::darkroom::coords::x(lhs) + sprout::darkroom::coords::x(rhs),
sprout::darkroom::coords::y(lhs) + sprout::darkroom::coords::y(rhs),
sprout::darkroom::coords::z(lhs) + sprout::darkroom::coords::z(rhs)
);
}
//
// sub
//
template<typename Vector1, typename Vector2>
SPROUT_CONSTEXPR inline Vector1 sub(Vector1 const& lhs, Vector2 const& rhs) {
return sprout::tuples::remake_clone<Vector1>(
lhs,
sprout::darkroom::coords::x(lhs) - sprout::darkroom::coords::x(rhs),
sprout::darkroom::coords::y(lhs) - sprout::darkroom::coords::y(rhs),
sprout::darkroom::coords::z(lhs) - sprout::darkroom::coords::z(rhs)
);
}
//
// scale
//
template<typename Vector, typename Fac>
SPROUT_CONSTEXPR inline Vector scale(Vector const& lhs, Fac const& rhs) {
return sprout::tuples::remake_clone<Vector>(
lhs,
sprout::darkroom::coords::x(lhs) * rhs,
sprout::darkroom::coords::y(lhs) * rhs,
sprout::darkroom::coords::z(lhs) * rhs
);
}
//
// dot
//
template<typename Vector>
SPROUT_CONSTEXPR inline typename sprout::darkroom::access::unit<Vector>::type
dot(Vector const& lhs, Vector const& rhs) {
return sprout::darkroom::coords::x(lhs) * sprout::darkroom::coords::x(rhs)
+ sprout::darkroom::coords::y(lhs) * sprout::darkroom::coords::y(rhs)
+ sprout::darkroom::coords::z(lhs) * sprout::darkroom::coords::z(rhs)
;
}
//
// normalize
//
namespace detail {
template<typename Vector>
SPROUT_CONSTEXPR inline Vector normalize_impl(
Vector const& vec,
typename sprout::darkroom::access::unit<Vector>::type const& len
)
{
return sprout::tuples::remake_clone<Vector>(
vec,
sprout::darkroom::coords::x(vec) / len,
sprout::darkroom::coords::y(vec) / len,
sprout::darkroom::coords::z(vec) / len
);
}
} // namespace detail
template<typename Vector>
SPROUT_CONSTEXPR inline Vector normalize(Vector const& vec) {
return sprout::darkroom::coords::detail::normalize_impl(
vec,
sprout::darkroom::coords::length(vec)
);
}
//
// reflect
//
template<typename Incident, typename Normal>
SPROUT_CONSTEXPR inline Incident reflect(Incident const& incid, Normal const& nor) {
return sprout::darkroom::coords::sub(
incid,
sprout::darkroom::coords::scale(nor, sprout::darkroom::coords::dot(incid, nor) * 2)
);
}
//
// normal_to_color
//
template<typename Color, typename Normal>
SPROUT_CONSTEXPR Color normal_to_color(Normal const& nor) {
return sprout::tuples::make_clone<Color>(
0.5 + sprout::darkroom::coords::x(nor) * 0.5,
0.5 + sprout::darkroom::coords::y(nor) * 0.5,
0.5 + sprout::darkroom::coords::z(nor) * 0.5
);
}
} // namespace coords
} // namespace darkroom
} // namespace sprout
#endif // #ifndef SPROUT_DARKROOM_COORDS_VECTOR_HPP

View file

@ -0,0 +1,7 @@
#ifndef SPROUT_DARKROOM_INTERSECTS_HPP
#define SPROUT_DARKROOM_INTERSECTS_HPP
#include <sprout/config.hpp>
#include <sprout/darkroom/intersects/intersection.hpp>
#endif // #ifndef SPROUT_DARKROOM_INTERSECTS_HPP

View file

@ -0,0 +1,85 @@
#ifndef SPROUT_DARKROOM_INTERSECTS_INTERSECTION_HPP
#define SPROUT_DARKROOM_INTERSECTS_INTERSECTION_HPP
#include <sprout/config.hpp>
#include <sprout/tuple/tuple.hpp>
#include <sprout/utility/forward.hpp>
#include <sprout/darkroom/access/access.hpp>
#include <sprout/darkroom/coords/vector.hpp>
#include <sprout/darkroom/materials/material.hpp>
namespace sprout {
namespace darkroom {
namespace intersects {
//
// does_intersect
// distance
// point_of_intersection
// normal
// material
//
template<typename T>
SPROUT_CONSTEXPR auto does_intersect(
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)))
{
return sprout::darkroom::access::get<0>(sprout::forward<T>(t));
}
template<typename T>
SPROUT_CONSTEXPR auto distance(
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)))
{
return sprout::darkroom::access::get<1>(sprout::forward<T>(t));
}
template<typename T>
SPROUT_CONSTEXPR auto point_of_intersection(
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>
SPROUT_CONSTEXPR auto normal(
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>
SPROUT_CONSTEXPR auto material(
T&& t
) SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::darkroom::access::get<4>(sprout::forward<T>(t))))
-> decltype(sprout::darkroom::access::get<4>(sprout::forward<T>(t)))
{
return sprout::darkroom::access::get<4>(sprout::forward<T>(t));
}
//
// make_intersection
//
template<typename Distance, typename Point, typename Normal, typename Material>
SPROUT_CONSTEXPR sprout::tuples::tuple<bool, Distance, Point, Normal, Material>
make_intersection(bool b, Distance const& dist, Point const& p, Normal const& nor, Material const& mat) {
return sprout::tuples::make_tuple(b, dist, p, nor, mat);
}
//
// intersection
//
typedef sprout::tuples::tuple<
bool,
double,
sprout::darkroom::coords::vector3d,
sprout::darkroom::coords::vector3d,
sprout::darkroom::materials::material
> intersection;
} // namespace intersects
} // namespace darkroom
} // namespace sprout
#endif // #ifndef SPROUT_DARKROOM_INTERSECTS_INTERSECTION_HPP

View file

@ -0,0 +1,7 @@
#ifndef SPROUT_DARKROOM_LIGHTS_HPP
#define SPROUT_DARKROOM_LIGHTS_HPP
#include <sprout/config.hpp>
#include <sprout/darkroom/lights/point_light.hpp>
#endif // #ifndef SPROUT_DARKROOM_LIGHTS_HPP

View file

@ -0,0 +1,169 @@
#ifndef SPROUT_DARKROOM_LIGHTS_POINT_LIGHT_HPP
#define SPROUT_DARKROOM_LIGHTS_POINT_LIGHT_HPP
#include <limits>
#include <sprout/config.hpp>
#include <sprout/tuple/tuple.hpp>
#include <sprout/tuple/functions.hpp>
#include <sprout/utility/forward.hpp>
#include <sprout/darkroom/access/access.hpp>
#include <sprout/darkroom/colors/rgb.hpp>
#include <sprout/darkroom/coords/vector.hpp>
#include <sprout/darkroom/rays/ray.hpp>
#include <sprout/darkroom/materials/material.hpp>
#include <sprout/darkroom/intersects/intersection.hpp>
#include <sprout/darkroom/objects/intersect.hpp>
#include HDR_ALGORITHM_SSCRISK_CEL_OR_SPROUT_DETAIL
namespace sprout {
namespace darkroom {
namespace lights {
//
// basic_point_light
//
template<
typename Position = sprout::darkroom::coords::vector3d,
typename Color = sprout::darkroom::colors::rgb_f
>
class basic_point_light {
public:
typedef Position position_type;
typedef typename sprout::darkroom::access::unit<position_type>::type unit_type;
typedef Color color_type;
private:
position_type pos_;
color_type col_;
private:
template<typename Intersection>
SPROUT_CONSTEXPR color_type shade_4(
Intersection const& inter,
unit_type const& intensity
) const
{
return sprout::tuples::remake_clone<color_type>(
col_,
sprout::darkroom::colors::r(col_)
* sprout::darkroom::colors::r(
sprout::darkroom::materials::color(
sprout::darkroom::intersects::material(inter)
)
)
* intensity
,
sprout::darkroom::colors::g(col_)
* sprout::darkroom::colors::g(
sprout::darkroom::materials::color(
sprout::darkroom::intersects::material(inter)
)
)
* intensity
,
sprout::darkroom::colors::b(col_)
* sprout::darkroom::colors::b(
sprout::darkroom::materials::color(
sprout::darkroom::intersects::material(inter)
)
)
* intensity
);
}
template<typename Intersection, typename LightRayIntersection>
SPROUT_CONSTEXPR color_type shade_3(
Intersection const& inter,
position_type const& diff,
position_type const& direction,
LightRayIntersection const& light_ray_inter
) const
{
return shade_4(
inter,
!sprout::darkroom::intersects::does_intersect(light_ray_inter)
|| sprout::darkroom::intersects::distance(light_ray_inter)
> sprout::darkroom::coords::length(diff)
|| sprout::darkroom::intersects::distance(light_ray_inter)
< std::numeric_limits<unit_type>::epsilon()
? NS_SSCRISK_CEL_OR_SPROUT_DETAIL::max(
std::numeric_limits<unit_type>::epsilon(),
sprout::darkroom::coords::dot(
direction,
sprout::darkroom::intersects::normal(inter)
)
/ (sprout::darkroom::coords::length(diff) + 1)
)
: 0
);
}
template<typename Intersection, typename Objects>
SPROUT_CONSTEXPR color_type shade_2(
Intersection const& inter,
Objects const& objs,
position_type const& diff,
position_type const& direction
) const
{
return shade_3(
inter,
diff,
direction,
sprout::darkroom::objects::intersect_list(
objs,
sprout::darkroom::rays::make_ray(
sprout::darkroom::coords::add(
sprout::darkroom::coords::scale(
direction,
std::numeric_limits<unit_type>::epsilon() * 256
),
sprout::darkroom::intersects::point_of_intersection(inter)
),
direction
)
)
);
}
template<typename Intersection, typename Objects>
SPROUT_CONSTEXPR color_type shade_1(
Intersection const& inter,
Objects const& objs,
position_type const& diff
) const
{
return shade_2(
inter,
objs,
diff,
sprout::darkroom::coords::normalize(diff)
);
}
public:
SPROUT_CONSTEXPR basic_point_light(
position_type const& pos,
color_type const& col
)
: pos_(pos)
, col_(col)
{}
template<typename Intersection, typename Objects>
SPROUT_CONSTEXPR color_type operator()(Intersection const& inter, Objects const& objs) const {
return shade_1(
inter,
objs,
sprout::darkroom::coords::sub(
pos_,
sprout::darkroom::intersects::point_of_intersection(inter)
)
);
}
};
//
// make_point_light
//
template<typename Position, typename Color>
SPROUT_CONSTEXPR inline sprout::darkroom::lights::basic_point_light<Position, Color>
make_point_light(Position const& pos, Color const& col) {
return sprout::darkroom::lights::basic_point_light<Position, Color>(pos, col);
}
} // namespace lights
} // namespace darkroom
} // namespace sprout
#endif // #ifndef SPROUT_DARKROOM_LIGHTS_POINT_LIGHT_HPP

View file

@ -0,0 +1,7 @@
#ifndef SPROUT_DARKROOM_MATERIALS_HPP
#define SPROUT_DARKROOM_MATERIALS_HPP
#include <sprout/config.hpp>
#include <sprout/darkroom/materials/material.hpp>
#endif // #ifndef SPROUT_DARKROOM_MATERIALS_HPP

View file

@ -0,0 +1,84 @@
#ifndef SPROUT_DARKROOM_MATERIALS_MATERIAL_HPP
#define SPROUT_DARKROOM_MATERIALS_MATERIAL_HPP
#include <sprout/config.hpp>
#include <sprout/tuple/tuple.hpp>
#include <sprout/utility/forward.hpp>
#include <sprout/darkroom/access/access.hpp>
#include <sprout/darkroom/colors/rgb.hpp>
namespace sprout {
namespace darkroom {
namespace materials {
//
// color
// reflection
//
template<typename T>
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)))
{
return sprout::darkroom::access::get<0>(sprout::forward<T>(t));
}
template<typename T>
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)))
{
return sprout::darkroom::access::get<1>(sprout::forward<T>(t));
}
//
// calc_color
// calc_reflection
//
template<typename Image, typename Position, typename Normal>
SPROUT_CONSTEXPR auto calc_color(Image&& t, Position const&, Normal const&) SPROUT_NOEXCEPT
-> decltype(t)
{
return t;
}
template<typename Image, typename Position, typename Normal>
SPROUT_CONSTEXPR auto calc_reflection(Image&& t, Position const&, Normal const&) SPROUT_NOEXCEPT
-> decltype(t)
{
return t;
}
//
// calc_material
//
template<typename Material, typename Position, typename Normal>
SPROUT_CONSTEXPR auto calc_material(Material const& mat, Position const& pos, Normal const& nor)
-> 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)
))
{
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)
);
}
//
// make_material_image
//
template<typename ColorImage, typename ReflectionImage>
SPROUT_CONSTEXPR sprout::tuples::tuple<ColorImage, ReflectionImage>
make_material_image(ColorImage const& col, ReflectionImage const& ref) {
return sprout::tuples::make_tuple(col, ref);
}
//
// material
//
typedef sprout::tuples::tuple<sprout::darkroom::colors::rgb_f, double> material;
} // namespace materials
} // namespace darkroom
} // namespace sprout
#endif // #ifndef SPROUT_DARKROOM_MATERIALS_MATERIAL_HPP

View file

@ -0,0 +1,8 @@
#ifndef SPROUT_DARKROOM_OBJECTS_HPP
#define SPROUT_DARKROOM_OBJECTS_HPP
#include <sprout/config.hpp>
#include <sprout/darkroom/objects/intersect.hpp>
#include <sprout/darkroom/objects/sphere.hpp>
#endif // #ifndef SPROUT_DARKROOM_OBJECTS_HPP

View file

@ -0,0 +1,76 @@
#ifndef SPROUT_DARKROOM_OBJECTS_INTERSECT_HPP
#define SPROUT_DARKROOM_OBJECTS_INTERSECT_HPP
#include <cstddef>
#include <sprout/config.hpp>
#include <sprout/darkroom/access/access.hpp>
#include <sprout/darkroom/intersects/intersection.hpp>
namespace sprout {
namespace darkroom {
namespace objects {
//
// intersect
//
template<typename Object, typename Ray>
SPROUT_CONSTEXPR inline typename Object::template intersection<Ray>::type
intersect(Object const& obj, Ray const& ray) {
return obj.intersect(ray);
}
//
// intersect_list
//
namespace detail {
template<std::size_t N>
struct intersect_list_impl {
private:
template<typename Objects, typename Ray, typename A, typename B>
SPROUT_CONSTEXPR typename sprout::darkroom::access::unit<Objects>::type
::template intersection<Ray>::type
comp(A const& a, B const& b) const {
return sprout::darkroom::intersects::does_intersect(a)
&& sprout::darkroom::intersects::does_intersect(b)
? sprout::darkroom::intersects::distance(a) < sprout::darkroom::intersects::distance(b)
? a
: b
: sprout::darkroom::intersects::does_intersect(a)
? a
: b
;
}
public:
template<typename Objects, typename Ray>
SPROUT_CONSTEXPR typename sprout::darkroom::access::unit<Objects>::type
::template intersection<Ray>::type
operator()(Objects const& objs, Ray const& ray) const {
return comp<Objects, Ray>(
sprout::darkroom::objects::intersect(sprout::darkroom::access::get<N>(objs), ray),
intersect_list_impl<N - 1>()(objs, ray)
);
}
};
template<>
struct intersect_list_impl<0> {
public:
template<typename Objects, typename Ray>
SPROUT_CONSTEXPR typename sprout::darkroom::access::unit<Objects>::type
::template intersection<Ray>::type
operator()(Objects const& objs, Ray const& ray) const {
return sprout::darkroom::objects::intersect(sprout::darkroom::access::get<0>(objs), ray);
}
};
} // namespace detail
template<typename Objects, typename Ray>
SPROUT_CONSTEXPR inline typename sprout::darkroom::access::unit<Objects>::type
::template intersection<Ray>::type
intersect_list(Objects const& objs, Ray const& ray) {
return sprout::darkroom::objects::detail::intersect_list_impl<
sprout::darkroom::access::size<Objects>::value - 1
>()(objs, ray);
}
} // namespace objects
} // namespace darkroom
} // namespace sprout
#endif // #ifndef SPROUT_DARKROOM_OBJECTS_INTERSECT_HPP

View file

@ -0,0 +1,244 @@
#ifndef SPROUT_DARKROOM_OBJECTS_SPHERE_HPP
#define SPROUT_DARKROOM_OBJECTS_SPHERE_HPP
#include <cstddef>
#include <cmath>
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/tuple/tuple.hpp>
#include <sprout/tuple/functions.hpp>
#include <sprout/darkroom/access/access.hpp>
#include <sprout/darkroom/coords/vector.hpp>
#include <sprout/darkroom/rays/ray.hpp>
#include <sprout/darkroom/materials/material.hpp>
namespace sprout {
namespace darkroom {
namespace objects {
//
// basic_sphere
//
template<typename Material, typename Position = sprout::darkroom::coords::vector3d>
class basic_sphere {
public:
typedef Material material_type;
typedef Position position_type;
typedef typename sprout::darkroom::access::unit<position_type>::type unit_type;
typedef unit_type radius_type;
public:
template<typename Ray>
struct intersection {
typedef sprout::tuples::tuple<
bool,
unit_type,
position_type,
position_type,
decltype(sprout::darkroom::materials::calc_material(
std::declval<material_type const&>(),
std::declval<position_type const&>(),
std::declval<position_type const&>()
))
> type;
};
private:
typedef sprout::tuples::tuple<int, bool, unit_type> zwo_type;
typedef sprout::tuples::tuple<position_type, position_type> drei_type;
struct zw {
SPROUT_STATIC_CONSTEXPR std::size_t hit_side = 0;
SPROUT_STATIC_CONSTEXPR std::size_t does_intersect = 1;
SPROUT_STATIC_CONSTEXPR std::size_t distance = 2;
};
struct dr {
SPROUT_STATIC_CONSTEXPR std::size_t point_of_intersection = 0;
SPROUT_STATIC_CONSTEXPR std::size_t normal = 1;
};
private:
position_type pos_;
radius_type rad_;
material_type mat_;
private:
template<typename Ray>
SPROUT_CONSTEXPR zwo_type zweitens_2(
Ray const& ray,
unit_type const& i1,
unit_type const& i2,
int hit_side,
bool does_intersect
) const
{
return zwo_type(
hit_side,
does_intersect,
hit_side < 0 ? i2
: hit_side > 0 ? i1
: -1
);
}
template<typename Ray>
SPROUT_CONSTEXPR zwo_type zweitens_1(
Ray const& ray,
unit_type const& i1,
unit_type const& i2
) const
{
return zweitens_2(
ray,
i1,
i2,
i2 > 0
? i1 < 0 ? -1 : 1
: 0
,
i2 > 0
);
}
template<typename Ray>
SPROUT_CONSTEXPR zwo_type zweitens(
Ray const& ray,
bool neg,
unit_type const& b,
unit_type const& det
) const
{
return neg
? zweitens_1(ray, b - det, b + det)
: zwo_type(0, false, -1)
;
}
template<typename Ray>
SPROUT_CONSTEXPR drei_type drittens_1(
Ray const& ray,
typename sprout::darkroom::access::unit<Ray>::type point_of_intersection
) const
{
return drei_type(
point_of_intersection,
sprout::darkroom::coords::normalize(
sprout::darkroom::coords::sub(point_of_intersection, pos_)
)
);
}
template<typename Ray>
SPROUT_CONSTEXPR drei_type drittens(
Ray const& ray,
bool neg,
unit_type const& distance
) const
{
return neg
? drittens_1(ray, sprout::darkroom::rays::point_of_intersection(ray, distance))
: drei_type(
sprout::tuples::make_clone<position_type>(0, 0, 0),
sprout::tuples::make_clone<position_type>(1, 1, 1)
)
;
}
template<typename Ray>
SPROUT_CONSTEXPR typename intersection<Ray>::type intersect_5(
Ray const& ray,
zwo_type const& zwo,
drei_type const& drei
) const
{
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(
mat_,
sprout::tuples::get<dr::point_of_intersection>(drei),
sprout::tuples::get<dr::normal>(drei)
)
);
}
template<typename Ray>
SPROUT_CONSTEXPR typename intersection<Ray>::type intersect_4(
Ray const& ray,
zwo_type const& zwo
) const
{
return intersect_5(
ray,
zwo,
drittens(
ray,
sprout::tuples::get<zw::does_intersect>(zwo),
sprout::tuples::get<zw::distance>(zwo)
)
);
}
template<typename Ray>
SPROUT_CONSTEXPR typename intersection<Ray>::type intersect_3(
Ray const& ray,
unit_type const& b,
unit_type const& det_sq
) const
{
using std::sqrt;
return intersect_4(
ray,
zweitens(
ray,
det_sq > 0,
b,
sqrt(det_sq)
)
);
}
template<typename Ray>
SPROUT_CONSTEXPR typename intersection<Ray>::type intersect_2(
Ray const& ray,
position_type const& v,
unit_type const& b
) const
{
return intersect_3(
ray,
b,
b * b - sprout::darkroom::coords::length_sq(v) + rad_ * rad_
);
}
template<typename Ray>
SPROUT_CONSTEXPR typename intersection<Ray>::type intersect_1(
Ray const& ray,
position_type const& v
) const
{
return intersect_2(
ray,
v,
-sprout::darkroom::coords::dot(v, sprout::darkroom::rays::direction(ray))
);
}
public:
SPROUT_CONSTEXPR basic_sphere(
position_type const& pos,
radius_type rad,
material_type const& mat
)
: pos_(pos)
, rad_(rad)
, mat_(mat)
{};
template<typename Ray>
SPROUT_CONSTEXPR typename intersection<Ray>::type intersect(Ray const& ray) const {
return intersect_1(
ray,
sprout::darkroom::coords::sub(sprout::darkroom::rays::position(ray), pos_)
);
}
};
//
// make_sphere
//
template<typename Material, typename Position, typename Radius>
SPROUT_CONSTEXPR inline sprout::darkroom::objects::basic_sphere<Material, Position>
make_sphere(Position const& pos, Radius const& rad, Material const& mat) {
return sprout::darkroom::objects::basic_sphere<Material, Position>(pos, rad, mat);
}
} // namespace objects
} // namespace darkroom
} // namespace sprout
#endif // #ifndef SPROUT_DARKROOM_OBJECTS_SPHERE_HPP

View file

@ -0,0 +1,7 @@
#ifndef SPROUT_DARKROOM_PIXELS_HPP
#define SPROUT_DARKROOM_PIXELS_HPP
#include <sprout/config.hpp>
#include <sprout/darkroom/pixels/generate.hpp>
#endif // #ifndef SPROUT_DARKROOM_PIXELS_HPP

View file

@ -0,0 +1,187 @@
#ifndef SPROUT_DARKROOM_PIXELS_GENERATE_HPP
#define SPROUT_DARKROOM_PIXELS_GENERATE_HPP
#include <cstddef>
#include <sprout/config.hpp>
#include <sprout/index_tuple.hpp>
#include <sprout/array.hpp>
#include <sprout/fixed_container/traits.hpp>
#include <sprout/fixed_container/functions.hpp>
#include <sprout/darkroom/colors/rgb.hpp>
namespace sprout {
namespace darkroom {
namespace pixels {
//
// generate
//
namespace detail {
template<
typename Pixels,
typename RayTracer,
typename Renderer,
typename Camera,
typename Objects,
typename Lights,
std::ptrdiff_t... XIndexes
>
SPROUT_CONSTEXPR inline typename sprout::fixed_container_traits<Pixels>::value_type
generate_impl_line(
RayTracer const& raytracer,
Renderer const& renderer,
Camera const& camera,
Objects const& objs,
Lights const& lights,
typename sprout::fixed_container_traits<
typename sprout::fixed_container_traits<Pixels>::value_type
>::size_type x
,
typename sprout::fixed_container_traits<Pixels>::size_type y,
typename sprout::fixed_container_traits<
typename sprout::fixed_container_traits<Pixels>::value_type
>::size_type width
,
typename sprout::fixed_container_traits<Pixels>::size_type height,
std::size_t depth_max,
sprout::index_tuple<XIndexes...>
)
{
typedef typename sprout::fixed_container_traits<Pixels>::value_type pixel_line_type;
typedef typename sprout::fixed_container_traits<pixel_line_type>::value_type pixel_type;
return sprout::make_clone<pixel_line_type>(
sprout::darkroom::colors::rgb_f_to_rgb<pixel_type>(
raytracer.template operator()(
renderer,
camera,
objs,
lights,
x + XIndexes,
y,
width,
height,
depth_max
)
)...
);
}
template<
typename Pixels,
typename RayTracer,
typename Renderer,
typename Camera,
typename Objects,
typename Lights,
std::ptrdiff_t... YIndexes
>
SPROUT_CONSTEXPR inline Pixels
generate_impl(
RayTracer const& raytracer,
Renderer const& renderer,
Camera const& camera,
Objects const& objs,
Lights const& lights,
typename sprout::fixed_container_traits<
typename sprout::fixed_container_traits<Pixels>::value_type
>::size_type x
,
typename sprout::fixed_container_traits<Pixels>::size_type y,
typename sprout::fixed_container_traits<
typename sprout::fixed_container_traits<Pixels>::value_type
>::size_type width
,
typename sprout::fixed_container_traits<Pixels>::size_type height,
std::size_t depth_max,
sprout::index_tuple<YIndexes...>
)
{
return sprout::make_clone<Pixels>(
sprout::darkroom::pixels::detail::generate_impl_line<Pixels>(
raytracer,
renderer,
camera,
objs,
lights,
x,
y + YIndexes,
width,
height,
depth_max,
typename sprout::index_range<
0,
sprout::fixed_container_traits<
typename sprout::fixed_container_traits<Pixels>::value_type
>::fixed_size
>::type()
)...
);
}
} // namespace detail
template<
typename Pixels,
typename RayTracer,
typename Renderer,
typename Camera,
typename Objects,
typename Lights
>
SPROUT_CONSTEXPR inline Pixels generate(
RayTracer const& raytracer,
Renderer const& renderer,
Camera const& camera,
Objects const& objs,
Lights const& lights,
typename sprout::fixed_container_traits<
typename sprout::fixed_container_traits<Pixels>::value_type
>::size_type x
= 0
,
typename sprout::fixed_container_traits<Pixels>::size_type y
= 0
,
typename sprout::fixed_container_traits<
typename sprout::fixed_container_traits<Pixels>::value_type
>::size_type width
= sprout::fixed_container_traits<
typename sprout::fixed_container_traits<Pixels>::value_type
>::fixed_size
,
typename sprout::fixed_container_traits<Pixels>::size_type height
= sprout::fixed_container_traits<Pixels>::fixed_size
,
std::size_t depth_max = 8
)
{
return sprout::darkroom::pixels::detail::generate_impl<Pixels>(
raytracer,
renderer,
camera,
objs,
lights,
x,
y,
width,
height,
depth_max,
typename sprout::index_range<
0,
sprout::fixed_container_traits<Pixels>::fixed_size
>::type()
);
}
//
// color_pixels
//
template<std::size_t Width, std::size_t Height, typename Color = sprout::darkroom::colors::rgb>
struct color_pixels {
public:
typedef sprout::array<
sprout::array<Color, Width>,
Height
> type;
};
} // namespace pixels
} // namespace darkroom
} // namespace sprout
#endif // #ifndef SPROUT_DARKROOM_PIXELS_GENERATE_HPP

7
sprout/darkroom/rays.hpp Normal file
View file

@ -0,0 +1,7 @@
#ifndef SPROUT_DARKROOM_RAYS_HPP
#define SPROUT_DARKROOM_RAYS_HPP
#include <sprout/config.hpp>
#include <sprout/darkroom/rays/ray.hpp>
#endif // #ifndef SPROUT_DARKROOM_RAYS_HPP

View file

@ -0,0 +1,63 @@
#ifndef SPROUT_DARKROOM_RAYS_RAY_HPP
#define SPROUT_DARKROOM_RAYS_RAY_HPP
#include <sprout/config.hpp>
#include <sprout/tuple/tuple.hpp>
#include <sprout/utility/forward.hpp>
#include <sprout/darkroom/access/access.hpp>
#include <sprout/darkroom/coords/vector.hpp>
namespace sprout {
namespace darkroom {
namespace rays {
//
// position
// direction
//
template<typename T>
SPROUT_CONSTEXPR auto position(
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)))
{
return sprout::darkroom::access::get<0>(sprout::forward<T>(t));
}
template<typename T>
SPROUT_CONSTEXPR auto direction(
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)))
{
return sprout::darkroom::access::get<1>(sprout::forward<T>(t));
}
//
// make_ray
//
template<typename Position, typename Direction>
SPROUT_CONSTEXPR sprout::tuples::tuple<Position, Direction>
make_ray(Position const& pos, Direction const& dir) {
return sprout::tuples::make_tuple(pos, dir);
}
//
// ray
//
typedef sprout::tuples::tuple<sprout::darkroom::coords::vector3d, sprout::darkroom::coords::vector3d> ray;
//
// point_of_intersection
//
template<typename Ray, typename Distance>
SPROUT_CONSTEXPR inline typename sprout::darkroom::access::unit<Ray>::type
point_of_intersection(Ray const& ray, Distance const& dist) {
return sprout::darkroom::coords::add(
sprout::darkroom::rays::position(ray),
sprout::darkroom::coords::scale(sprout::darkroom::rays::direction(ray), dist)
);
}
} // namespace ray
} // namespace darkroom
} // namespace sprout
#endif // #ifndef SPROUT_DARKROOM_RAYS_RAY_HPP

View file

@ -0,0 +1,7 @@
#ifndef SPROUT_DARKROOM_RENDERERS_HPP
#define SPROUT_DARKROOM_RENDERERS_HPP
#include <sprout/config.hpp>
#include <sprout/darkroom/renderers/whitted_style.hpp>
#endif // #ifndef SPROUT_DARKROOM_RENDERERS_HPP

View file

@ -0,0 +1,237 @@
#ifndef SPROUT_DARKROOM_RENDERERS_WHITTED_STYLE_HPP
#define SPROUT_DARKROOM_RENDERERS_WHITTED_STYLE_HPP
#include <cstddef>
#include <limits>
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/tuple/functions.hpp>
#include <sprout/darkroom/access/access.hpp>
#include <sprout/darkroom/colors/rgb.hpp>
#include <sprout/darkroom/coords/vector.hpp>
#include <sprout/darkroom/rays/ray.hpp>
#include <sprout/darkroom/materials/material.hpp>
#include <sprout/darkroom/intersects/intersection.hpp>
#include <sprout/darkroom/objects/intersect.hpp>
namespace sprout {
namespace darkroom {
namespace renderers {
//
// whitted_mirror
//
class whitted_mirror {
private:
template<
typename Color,
typename Camera,
typename Objects,
typename Lights,
typename Ray,
typename Intersection,
typename Tracer,
typename Direction
>
SPROUT_CONSTEXPR Color color_1(
Camera const& camera,
Objects const& objs,
Lights const& lights,
Ray const& ray,
Intersection const& inter,
Tracer const& tracer,
std::size_t depth_max,
Direction const& reflect_dir
) const
{
return tracer.template operator()<Color>(
camera,
objs,
lights,
sprout::tuples::remake_clone<Ray>(
ray,
sprout::darkroom::coords::add(
sprout::darkroom::intersects::point_of_intersection(inter),
sprout::darkroom::coords::scale(
reflect_dir,
std::numeric_limits<typename sprout::darkroom::access::unit<Direction>::type>::epsilon() * 256
)
// !!!
// sprout::darkroom::coords::scale(
// sprout::darkroom::intersects::normal(inter),
// std::numeric_limits<typename sprout::darkroom::access::unit<Direction>::type>::epsilon() * 256
// )
),
reflect_dir
),
depth_max - 1
);
}
public:
template<
typename Color,
typename Camera,
typename Objects,
typename Lights,
typename Ray,
typename Intersection,
typename Tracer
>
SPROUT_CONSTEXPR Color operator()(
Camera const& camera,
Objects const& objs,
Lights const& lights,
Ray const& ray,
Intersection const& inter,
Tracer const& tracer,
std::size_t depth_max
) const
{
typedef typename std::decay<
decltype(sprout::darkroom::materials::reflection(sprout::darkroom::intersects::material(inter)))
>::type reflection_type;
return depth_max > 0
&& sprout::darkroom::intersects::does_intersect(inter)
&& sprout::darkroom::materials::reflection(sprout::darkroom::intersects::material(inter))
> std::numeric_limits<reflection_type>::epsilon()
? color_1<Color>(
camera,
objs,
lights,
ray,
inter,
tracer,
depth_max,
sprout::darkroom::coords::reflect(
sprout::darkroom::rays::direction(ray),
sprout::darkroom::intersects::normal(inter)
)
)
: sprout::tuples::make_clone<Color>(0, 0, 0)
;
}
};
//
// whitted_style
//
class whitted_style {
private:
template<
typename Color,
typename Ray,
typename Intersection
>
SPROUT_CONSTEXPR Color color_3(
Ray const& ray,
Intersection const& inter,
Color const& diffuse_color,
Color const& mirror_color
) const
{
return sprout::darkroom::intersects::does_intersect(inter)
? sprout::darkroom::colors::add(
sprout::darkroom::colors::mul(
diffuse_color,
1 - sprout::darkroom::materials::reflection(sprout::darkroom::intersects::material(inter))
),
sprout::darkroom::colors::mul(
sprout::darkroom::colors::filter(
sprout::darkroom::materials::color(sprout::darkroom::intersects::material(inter)),
mirror_color
),
sprout::darkroom::materials::reflection(sprout::darkroom::intersects::material(inter))
)
)
: sprout::darkroom::coords::normal_to_color<Color>(sprout::darkroom::rays::direction(ray))
;
}
template<
typename Color,
typename Camera,
typename Objects,
typename Lights,
typename Ray,
typename Intersection
>
SPROUT_CONSTEXPR Color color_2(
Camera const& camera,
Objects const& objs,
Lights const& lights,
Ray const& ray,
std::size_t depth_max,
Intersection const& inter,
Color const& diffuse_color
) const
{
return color_3<Color>(
ray,
inter,
diffuse_color,
sprout::darkroom::renderers::whitted_mirror().template operator()<Color>(
camera,
objs,
lights,
ray,
inter,
*this,
depth_max
)
);
}
template<
typename Color,
typename Camera,
typename Objects,
typename Lights,
typename Ray,
typename Intersection
>
SPROUT_CONSTEXPR Color color_1(
Camera const& camera,
Objects const& objs,
Lights const& lights,
Ray const& ray,
std::size_t depth_max,
Intersection const& inter
) const
{
return color_2<Color>(
camera,
objs,
lights,
ray,
depth_max,
inter,
lights.template operator()(inter, objs)
);
}
public:
template<
typename Color,
typename Camera,
typename Objects,
typename Lights,
typename Ray
>
SPROUT_CONSTEXPR Color operator()(
Camera const& camera,
Objects const& objs,
Lights const& lights,
Ray const& ray,
std::size_t depth_max
) const
{
return color_1<Color>(
camera,
objs,
lights,
ray,
depth_max,
sprout::darkroom::objects::intersect_list(objs, ray)
);
}
};
} // namespace renderers
} // namespace darkroom
} // namespace sprout
#endif // #ifndef SPROUT_DARKROOM_RENDERERS_WHITTED_STYLE_HPP

View file

@ -0,0 +1,7 @@
#ifndef SPROUT_DARKROOM_TRACERS_HPP
#define SPROUT_DARKROOM_TRACERS_HPP
#include <sprout/config.hpp>
#include <sprout/darkroom/tracers/raytracer.hpp>
#endif // #ifndef SPROUT_DARKROOM_TRACERS_HPP

View file

@ -0,0 +1,54 @@
#ifndef SPROUT_DARKROOM_TRACERS_RAYTRACER_HPP
#define SPROUT_DARKROOM_TRACERS_RAYTRACER_HPP
#include <cstddef>
#include <sprout/config.hpp>
#include <sprout/darkroom/colors/rgb.hpp>
namespace sprout {
namespace darkroom {
namespace tracers {
//
// raytracer
//
template<typename Color = sprout::darkroom::colors::rgb_f>
class raytracer {
public:
typedef Color color_type;
public:
template<
typename Renderer,
typename Camera,
typename Objects,
typename Lights,
typename Unit
>
SPROUT_CONSTEXPR color_type operator()(
Renderer const& renderer,
Camera const& camera,
Objects const& objs,
Lights const& lights,
Unit const& x,
Unit const& y,
Unit const& width,
Unit const& height,
std::size_t depth_max = 8
) const
{
return renderer.template operator()<color_type>(
camera,
objs,
lights,
camera.template operator()(
static_cast<typename Camera::unit_type>(x) / width - 0.5,
static_cast<typename Camera::unit_type>(y) / height - 0.5
),
depth_max
);
}
};
} // namespace tracers
} // namespace darkroom
} // namespace sprout
#endif // #ifndef SPROUT_DARKROOM_TRACERS_RAYTRACER_HPP

View file

@ -129,7 +129,7 @@ namespace sprout {
: inherited_type()
, base_type()
{}
SPROUT_CONSTEXPR explicit tuple_impl(const Head& h, Tail const&... tail)
SPROUT_CONSTEXPR explicit tuple_impl(Head const& h, Tail const&... tail)
: inherited_type(tail...)
, base_type(h)
{}
@ -215,10 +215,15 @@ namespace sprout {
: inherited_type(elements...)
{}
template<typename... UTypes>
SPROUT_CONSTEXPR explicit tuple(UTypes&&... elements)
: inherited_type(sprout::forward<UTypes>(elements)...)
SPROUT_CONSTEXPR explicit tuple(UTypes const&... elements)
: inherited_type(elements...)
{}
SPROUT_CONSTEXPR tuple(tuple const &) = default;
// !!!
// template<typename... UTypes>
// SPROUT_CONSTEXPR explicit tuple(UTypes&&... elements)
// : inherited_type(sprout::forward<UTypes>(elements)...)
// {}
SPROUT_CONSTEXPR tuple(tuple const&) = default;
SPROUT_CONSTEXPR tuple(tuple&&) = default;
template<typename... UTypes>
SPROUT_CONSTEXPR tuple(sprout::tuples::tuple<UTypes...> const& t)