fix darkroom whitted_style

fix cbind
This commit is contained in:
bolero-MURAKAMI 2012-08-13 23:55:30 +09:00
parent 744146ae38
commit 6b1efc8a15
8 changed files with 128 additions and 22 deletions

View file

@ -171,18 +171,6 @@ namespace sprout {
sprout::darkroom::coords::scale(nor, sprout::darkroom::coords::dot(incid, nor) * 2)
);
}
//
// normal_to_color
//
template<typename Color, typename Normal>
inline SPROUT_CONSTEXPR Color normal_to_color(Normal const& nor) {
return sprout::tuples::make<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

View file

@ -32,17 +32,17 @@ namespace sprout {
return sprout::darkroom::colors::add(
sprout::darkroom::colors::mul(
sprout::darkroom::colors::add(
sprout::darkroom::colors::mul(c00, u),
sprout::darkroom::colors::mul(c01, 1 - u)
sprout::darkroom::colors::mul(c00, 1 - u),
sprout::darkroom::colors::mul(c01, u)
),
v
1 - v
),
sprout::darkroom::colors::mul(
sprout::darkroom::colors::add(
sprout::darkroom::colors::mul(c10, u),
sprout::darkroom::colors::mul(c11, 1 - u)
sprout::darkroom::colors::mul(c10, 1 - u),
sprout::darkroom::colors::mul(c11, u)
),
1 - v
v
)
);
}

View file

@ -90,7 +90,7 @@ namespace sprout {
return sprout::darkroom::materials::bilinear_interpolate(
get_color(x0, y0), get_color(x0 + 1, y0),
get_color(x0, y0 + 1), get_color(x0 + 1, y0 + 1),
1 - (x - x0), 1 - (y - y0)
x - x0, y - y0
);
}
template<typename Unit>

View file

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

View file

@ -0,0 +1,80 @@
#ifndef SPROUT_DARKROOM_RENDERERS_INFINITY_HPP
#define SPROUT_DARKROOM_RENDERERS_INFINITY_HPP
#include <sprout/config.hpp>
#include <sprout/tuple/functions.hpp>
#include <sprout/darkroom/colors/rgb.hpp>
#include <sprout/darkroom/coords/vector.hpp>
namespace sprout {
namespace darkroom {
namespace renderers {
//
// normal_to_color
//
template<typename Color, typename Normal>
inline SPROUT_CONSTEXPR Color normal_to_color(Normal const& nor) {
return sprout::tuples::make<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
);
}
//
// direction_gradation
//
class direction_gradation {
public:
template<typename TargetColor, typename Vector>
SPROUT_CONSTEXPR TargetColor operator()(Vector const& dir) const {
return sprout::darkroom::renderers::normal_to_color<TargetColor>(dir);
}
};
//
// make_direction_gradation
//
inline SPROUT_CONSTEXPR sprout::darkroom::renderers::direction_gradation
make_direction_gradation() {
return sprout::darkroom::renderers::direction_gradation();
}
//
// uniform_color
//
template<typename Color = sprout::darkroom::colors::rgb_f>
class uniform_color {
public:
typedef Color color_type;
private:
color_type color_;
public:
SPROUT_CONSTEXPR uniform_color()
: color_()
{}
SPROUT_CONSTEXPR uniform_color(uniform_color const&) = default;
explicit SPROUT_CONSTEXPR uniform_color(color_type const& color)
: color_(color)
{}
template<typename TargetColor, typename Vector>
SPROUT_CONSTEXPR TargetColor operator()(Vector const&) const {
return color_;
}
};
//
// make_uniform_color
//
inline SPROUT_CONSTEXPR sprout::darkroom::renderers::uniform_color<>
make_uniform_color() {
return sprout::darkroom::renderers::uniform_color<>();
}
template<typename Color>
inline SPROUT_CONSTEXPR sprout::darkroom::renderers::uniform_color<Color>
make_uniform_color(Color const& color) {
return sprout::darkroom::renderers::uniform_color<Color>(color);
}
} // namespace renderers
} // namespace darkroom
} // namespace sprout
#endif // #ifndef SPROUT_DARKROOM_RENDERERS_INFINITY_HPP

View file

@ -13,6 +13,7 @@
#include <sprout/darkroom/materials/material.hpp>
#include <sprout/darkroom/intersects/intersection.hpp>
#include <sprout/darkroom/objects/intersect.hpp>
#include <sprout/darkroom/renderers/infinity.hpp>
namespace sprout {
namespace darkroom {
@ -113,7 +114,12 @@ namespace sprout {
//
// whitted_style
//
template<typename InfinityColor = sprout::darkroom::renderers::direction_gradation>
class whitted_style {
public:
typedef InfinityColor infinity_color_type;
private:
infinity_color_type infinity_color_;
private:
template<
typename Color,
@ -141,7 +147,7 @@ namespace sprout {
sprout::darkroom::materials::reflection(sprout::darkroom::intersects::material(inter))
)
)
: sprout::darkroom::coords::normal_to_color<Color>(sprout::darkroom::rays::direction(ray))
: infinity_color_.template operator()<Color>(sprout::darkroom::rays::direction(ray))
;
}
template<
@ -205,6 +211,13 @@ namespace sprout {
);
}
public:
SPROUT_CONSTEXPR whitted_style()
: infinity_color_()
{}
SPROUT_CONSTEXPR whitted_style(whitted_style const&) = default;
explicit SPROUT_CONSTEXPR whitted_style(infinity_color_type const& infinity_color)
: infinity_color_(infinity_color)
{}
template<
typename Color,
typename Camera,
@ -230,6 +243,18 @@ namespace sprout {
);
}
};
//
// make_whitted_style
//
inline SPROUT_CONSTEXPR sprout::darkroom::renderers::whitted_style<>
make_whitted_style() {
return sprout::darkroom::renderers::whitted_style<>();
}
template<typename InfinityColor>
inline SPROUT_CONSTEXPR sprout::darkroom::renderers::whitted_style<InfinityColor>
make_whitted_style(InfinityColor const& infinity_color) {
return sprout::darkroom::renderers::whitted_style<InfinityColor>(infinity_color);
}
} // namespace renderers
} // namespace darkroom
} // namespace sprout

View file

@ -44,6 +44,18 @@ namespace sprout {
);
}
};
//
// make_raytracer
//
inline SPROUT_CONSTEXPR sprout::darkroom::tracers::raytracer<>
make_raytracer() {
return sprout::darkroom::tracers::raytracer<>();
}
template<typename Color>
inline SPROUT_CONSTEXPR sprout::darkroom::tracers::raytracer<Color>
make_raytracer() {
return sprout::darkroom::tracers::raytracer<Color>();
}
} // namespace tracers
} // namespace darkroom
} // namespace sprout

View file

@ -560,12 +560,12 @@ namespace sprout {
template<typename F, typename... BoundArgs>
inline SPROUT_CONSTEXPR typename sprout::detail::bind_helper<F, BoundArgs...>::type const
cbind(F&& f, BoundArgs&&... args) {
sprout::bind(sprout::forward<F>(f), sprout::forward<BoundArgs>(args)...);
return sprout::bind(sprout::forward<F>(f), sprout::forward<BoundArgs>(args)...);
}
template<typename R, typename F, typename... BoundArgs>
inline SPROUT_CONSTEXPR typename sprout::detail::bindres_helper<R, F, BoundArgs...>::type const
cbind(F&& f, BoundArgs&&... args) {
sprout::bind<R>(sprout::forward<F>(f), sprout::forward<BoundArgs>(args)...);
return sprout::bind<R>(sprout::forward<F>(f), sprout::forward<BoundArgs>(args)...);
}
} // namespace sprout