add darkroom light_list, parallel_light, ambient_light

fix darkroom whitted_style
This commit is contained in:
bolero-MURAKAMI 2012-08-14 18:17:48 +09:00
parent 6b1efc8a15
commit dc1e85923b
7 changed files with 285 additions and 33 deletions

View file

@ -99,6 +99,18 @@ namespace sprout {
); );
} }
// //
// negate
//
template<typename Vector>
inline SPROUT_CONSTEXPR Vector negate(Vector const& vec) {
return sprout::tuples::remake<Vector>(
vec,
-sprout::darkroom::coords::x(vec),
-sprout::darkroom::coords::y(vec),
-sprout::darkroom::coords::z(vec)
);
}
//
// dot // dot
// //
template<typename Vector> template<typename Vector>

View file

@ -2,6 +2,9 @@
#define SPROUT_DARKROOM_LIGHTS_HPP #define SPROUT_DARKROOM_LIGHTS_HPP
#include <sprout/config.hpp> #include <sprout/config.hpp>
#include <sprout/darkroom/lights/light_list.hpp>
#include <sprout/darkroom/lights/parallel_light.hpp>
#include <sprout/darkroom/lights/point_light.hpp> #include <sprout/darkroom/lights/point_light.hpp>
#include <sprout/darkroom/lights/ambient_light.hpp>
#endif // #ifndef SPROUT_DARKROOM_LIGHTS_HPP #endif // #ifndef SPROUT_DARKROOM_LIGHTS_HPP

View file

@ -0,0 +1,48 @@
#ifndef SPROUT_DARKROOM_LIGHTS_AMBIENT_LIGHT_HPP
#define SPROUT_DARKROOM_LIGHTS_AMBIENT_LIGHT_HPP
#include <limits>
#include <sprout/config.hpp>
#include <sprout/tuple/tuple.hpp>
#include <sprout/tuple/functions.hpp>
#include <sprout/darkroom/colors/rgb.hpp>
#include <sprout/darkroom/materials/material.hpp>
#include <sprout/darkroom/intersects/intersection.hpp>
namespace sprout {
namespace darkroom {
namespace lights {
//
// basic_ambient_light
//
template<typename Color = sprout::darkroom::colors::rgb_f>
class basic_ambient_light {
public:
typedef Color color_type;
private:
color_type col_;
public:
explicit SPROUT_CONSTEXPR basic_ambient_light(color_type const& col)
: col_(col)
{}
template<typename Intersection, typename Objects>
SPROUT_CONSTEXPR color_type operator()(Intersection const& inter, Objects const&) const {
return sprout::darkroom::colors::filter(
col_,
sprout::darkroom::materials::color(sprout::darkroom::intersects::material(inter))
);
}
};
//
// make_ambient_light
//
template<typename Color>
inline SPROUT_CONSTEXPR sprout::darkroom::lights::basic_ambient_light<Color>
make_ambient_light(Color const& col) {
return sprout::darkroom::lights::basic_ambient_light<Color>(col);
}
} // namespace lights
} // namespace darkroom
} // namespace sprout
#endif // #ifndef SPROUT_DARKROOM_LIGHTS_AMBIENT_LIGHT_HPP

View file

@ -0,0 +1,65 @@
#ifndef SPROUT_DARKROOM_LIGHTS_LIGHT_LIST_HPP
#define SPROUT_DARKROOM_LIGHTS_LIGHT_LIST_HPP
#include <limits>
#include <sprout/config.hpp>
#include <sprout/index_tuple.hpp>
#include <sprout/tuple/tuple.hpp>
#include <sprout/darkroom/access/access.hpp>
#include <sprout/darkroom/colors/rgb.hpp>
namespace sprout {
namespace darkroom {
namespace lights {
//
// light_list
//
template<typename... Lights>
class light_list {
public:
typedef sprout::tuples::tuple<Lights...> lights_type;
typedef typename sprout::darkroom::access::unit<lights_type>::type::color_type color_type;
private:
lights_type lights_;
private:
template<typename Color>
SPROUT_CONSTEXPR color_type shade_2(Color const& col) const {
return col;
}
template<typename Color1, typename Color2, typename... Tail>
SPROUT_CONSTEXPR color_type shade_2(Color1 const& col1, Color2 const& col2, Tail const&... tail) const {
return shade_2(
sprout::darkroom::colors::add(col1, col2),
tail...
);
}
template<typename Intersection, typename Objects, sprout::index_t... Indexes>
SPROUT_CONSTEXPR color_type shade_1(
Intersection const& inter, Objects const& objs,
sprout::index_tuple<Indexes...>
) const
{
return shade_2(sprout::darkroom::access::get<Indexes>(lights_).template operator()(inter, objs)...);
}
public:
explicit SPROUT_CONSTEXPR light_list(Lights const&... lights)
: lights_(lights...)
{}
template<typename Intersection, typename Objects>
SPROUT_CONSTEXPR color_type operator()(Intersection const& inter, Objects const& objs) const {
return shade_1(inter, objs, sprout::index_range<0, sizeof...(Lights)>::make());
}
};
//
// make_light_list
//
template<typename... Lights>
inline SPROUT_CONSTEXPR sprout::darkroom::lights::light_list<Lights...>
make_light_list(Lights const&... lights) {
return sprout::darkroom::lights::light_list<Lights...>(lights...);
}
} // namespace lights
} // namespace darkroom
} // namespace sprout
#endif // #ifndef SPROUT_DARKROOM_LIGHTS_LIGHT_LIST_HPP

View file

@ -0,0 +1,146 @@
#ifndef SPROUT_DARKROOM_LIGHTS_PARALLEL_LIGHT_HPP
#define SPROUT_DARKROOM_LIGHTS_PARALLEL_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
namespace sprout {
namespace darkroom {
namespace lights {
//
// basic_parallel_light
//
template<
typename Position = sprout::darkroom::coords::vector3d,
typename Color = sprout::darkroom::colors::rgb_f
>
class basic_parallel_light {
public:
typedef Position position_type;
typedef typename sprout::darkroom::access::unit<position_type>::type unit_type;
typedef Color color_type;
private:
position_type dir_;
color_type col_;
private:
template<typename Intersection>
SPROUT_CONSTEXPR color_type shade_4(
Intersection const& inter,
unit_type const& intensity
) const
{
return sprout::darkroom::colors::mul(
sprout::darkroom::colors::filter(
col_,
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::max(
std::numeric_limits<unit_type>::epsilon(),
sprout::darkroom::coords::dot(
direction,
sprout::darkroom::intersects::normal(inter)
)
)
: 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_parallel_light(
position_type const& dir,
color_type const& col
)
: dir_(dir)
, col_(col)
{}
template<typename Intersection, typename Objects>
SPROUT_CONSTEXPR color_type operator()(Intersection const& inter, Objects const& objs) const {
return shade_1(
inter,
objs,
dir_
);
}
};
//
// make_parallel_light
//
template<typename Position, typename Color>
inline SPROUT_CONSTEXPR sprout::darkroom::lights::basic_parallel_light<Position, Color>
make_parallel_light(Position const& pos, Color const& col) {
return sprout::darkroom::lights::basic_parallel_light<Position, Color>(pos, col);
}
} // namespace lights
} // namespace darkroom
} // namespace sprout
#endif // #ifndef SPROUT_DARKROOM_LIGHTS_PARALLEL_LIGHT_HPP

View file

@ -40,31 +40,12 @@ namespace sprout {
unit_type const& intensity unit_type const& intensity
) const ) const
{ {
return sprout::tuples::remake<color_type>( return sprout::darkroom::colors::mul(
col_, sprout::darkroom::colors::filter(
sprout::darkroom::colors::r(col_) col_,
* sprout::darkroom::colors::r( sprout::darkroom::materials::color(sprout::darkroom::intersects::material(inter))
sprout::darkroom::materials::color( ),
sprout::darkroom::intersects::material(inter) intensity
)
)
* 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> template<typename Intersection, typename LightRayIntersection>

View file

@ -140,10 +140,7 @@ namespace sprout {
1 - sprout::darkroom::materials::reflection(sprout::darkroom::intersects::material(inter)) 1 - sprout::darkroom::materials::reflection(sprout::darkroom::intersects::material(inter))
), ),
sprout::darkroom::colors::mul( sprout::darkroom::colors::mul(
sprout::darkroom::colors::filter( mirror_color,
sprout::darkroom::materials::color(sprout::darkroom::intersects::material(inter)),
mirror_color
),
sprout::darkroom::materials::reflection(sprout::darkroom::intersects::material(inter)) sprout::darkroom::materials::reflection(sprout::darkroom::intersects::material(inter))
) )
) )
@ -169,10 +166,10 @@ namespace sprout {
) const ) const
{ {
return color_3<Color>( return color_3<Color>(
ray, ray,
inter, inter,
diffuse_color, diffuse_color,
sprout::darkroom::renderers::whitted_mirror().template operator()<Color>( sprout::darkroom::renderers::whitted_mirror().template operator()<Color>(
camera, camera,
objs, objs,
lights, lights,