2013-08-08 09:54:33 +00:00
|
|
|
/*=============================================================================
|
2016-02-25 09:48:28 +00:00
|
|
|
Copyright (c) 2011-2016 Bolero MURAKAMI
|
2013-08-08 09:54:33 +00:00
|
|
|
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)
|
|
|
|
=============================================================================*/
|
2012-08-14 09:17:48 +00:00
|
|
|
#ifndef SPROUT_DARKROOM_LIGHTS_PARALLEL_LIGHT_HPP
|
|
|
|
#define SPROUT_DARKROOM_LIGHTS_PARALLEL_LIGHT_HPP
|
|
|
|
|
|
|
|
#include <sprout/config.hpp>
|
2013-08-06 15:15:09 +00:00
|
|
|
#include <sprout/limits.hpp>
|
2012-08-14 09:17:48 +00:00
|
|
|
#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>
|
2013-02-19 16:12:56 +00:00
|
|
|
#include HDR_ALGORITHM_MIN_MAX_SSCRISK_CEL_OR_SPROUT
|
2012-08-14 09:17:48 +00:00
|
|
|
|
|
|
|
namespace sprout {
|
|
|
|
namespace darkroom {
|
|
|
|
namespace lights {
|
|
|
|
//
|
|
|
|
// basic_parallel_light
|
|
|
|
//
|
|
|
|
template<
|
2013-03-26 17:02:16 +00:00
|
|
|
typename Position = sprout::darkroom::coords::vector3d_t,
|
|
|
|
typename Color = sprout::darkroom::colors::rgb_f_t
|
2012-08-14 09:17:48 +00:00
|
|
|
>
|
|
|
|
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>
|
2012-10-05 15:58:56 +00:00
|
|
|
SPROUT_CONSTEXPR color_type
|
|
|
|
shade_2(Intersection const& inter, unit_type const& intensity) const {
|
2012-08-14 09:17:48 +00:00
|
|
|
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>
|
2012-10-05 15:58:56 +00:00
|
|
|
SPROUT_CONSTEXPR color_type
|
|
|
|
shade_1(Intersection const& inter, LightRayIntersection const& light_ray_inter) const {
|
2012-08-14 18:32:43 +00:00
|
|
|
return shade_2(
|
2012-08-14 09:17:48 +00:00
|
|
|
inter,
|
|
|
|
!sprout::darkroom::intersects::does_intersect(light_ray_inter)
|
|
|
|
|| sprout::darkroom::intersects::distance(light_ray_inter)
|
2013-08-06 15:15:09 +00:00
|
|
|
< sprout::numeric_limits<unit_type>::epsilon()
|
2012-08-14 09:17:48 +00:00
|
|
|
? NS_SSCRISK_CEL_OR_SPROUT::max(
|
2013-08-06 15:15:09 +00:00
|
|
|
sprout::numeric_limits<unit_type>::epsilon(),
|
2012-08-14 09:17:48 +00:00
|
|
|
sprout::darkroom::coords::dot(
|
2012-08-14 18:32:43 +00:00
|
|
|
dir_,
|
2012-08-14 09:17:48 +00:00
|
|
|
sprout::darkroom::intersects::normal(inter)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
: 0
|
|
|
|
);
|
|
|
|
}
|
2012-08-14 18:32:43 +00:00
|
|
|
public:
|
2012-10-05 15:58:56 +00:00
|
|
|
SPROUT_CONSTEXPR basic_parallel_light(position_type const& dir, color_type const& col)
|
2012-08-14 18:32:43 +00:00
|
|
|
: dir_(sprout::darkroom::coords::normalize(dir))
|
|
|
|
, col_(col)
|
|
|
|
{}
|
2012-08-14 09:17:48 +00:00
|
|
|
template<typename Intersection, typename Objects>
|
2012-10-05 15:58:56 +00:00
|
|
|
SPROUT_CONSTEXPR color_type
|
|
|
|
operator()(Intersection const& inter, Objects const& objs) const {
|
2012-08-14 18:32:43 +00:00
|
|
|
return shade_1(
|
2012-08-14 09:17:48 +00:00
|
|
|
inter,
|
2013-09-24 01:05:47 +00:00
|
|
|
sprout::darkroom::objects::intersect(
|
2012-08-14 09:17:48 +00:00
|
|
|
objs,
|
2013-12-05 16:57:31 +00:00
|
|
|
sprout::darkroom::rays::make_detached_ray(
|
|
|
|
sprout::darkroom::intersects::point_of_intersection(inter),
|
2012-08-14 18:32:43 +00:00
|
|
|
dir_
|
2012-08-14 09:17:48 +00:00
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
//
|
|
|
|
// 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
|