diff --git a/sprout/darkroom/coords/vector.hpp b/sprout/darkroom/coords/vector.hpp index a6952b19..16edd2dd 100644 --- a/sprout/darkroom/coords/vector.hpp +++ b/sprout/darkroom/coords/vector.hpp @@ -99,6 +99,18 @@ namespace sprout { ); } // + // negate + // + template + inline SPROUT_CONSTEXPR Vector negate(Vector const& vec) { + return sprout::tuples::remake( + vec, + -sprout::darkroom::coords::x(vec), + -sprout::darkroom::coords::y(vec), + -sprout::darkroom::coords::z(vec) + ); + } + // // dot // template diff --git a/sprout/darkroom/lights.hpp b/sprout/darkroom/lights.hpp index aee6dc02..e06b18bb 100644 --- a/sprout/darkroom/lights.hpp +++ b/sprout/darkroom/lights.hpp @@ -2,6 +2,9 @@ #define SPROUT_DARKROOM_LIGHTS_HPP #include +#include +#include #include +#include #endif // #ifndef SPROUT_DARKROOM_LIGHTS_HPP diff --git a/sprout/darkroom/lights/ambient_light.hpp b/sprout/darkroom/lights/ambient_light.hpp new file mode 100644 index 00000000..df0df8d5 --- /dev/null +++ b/sprout/darkroom/lights/ambient_light.hpp @@ -0,0 +1,48 @@ +#ifndef SPROUT_DARKROOM_LIGHTS_AMBIENT_LIGHT_HPP +#define SPROUT_DARKROOM_LIGHTS_AMBIENT_LIGHT_HPP + +#include +#include +#include +#include +#include +#include +#include + +namespace sprout { + namespace darkroom { + namespace lights { + // + // basic_ambient_light + // + template + 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 + 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 + inline SPROUT_CONSTEXPR sprout::darkroom::lights::basic_ambient_light + make_ambient_light(Color const& col) { + return sprout::darkroom::lights::basic_ambient_light(col); + } + } // namespace lights + } // namespace darkroom +} // namespace sprout + +#endif // #ifndef SPROUT_DARKROOM_LIGHTS_AMBIENT_LIGHT_HPP diff --git a/sprout/darkroom/lights/light_list.hpp b/sprout/darkroom/lights/light_list.hpp new file mode 100644 index 00000000..126a8a2a --- /dev/null +++ b/sprout/darkroom/lights/light_list.hpp @@ -0,0 +1,65 @@ +#ifndef SPROUT_DARKROOM_LIGHTS_LIGHT_LIST_HPP +#define SPROUT_DARKROOM_LIGHTS_LIGHT_LIST_HPP + +#include +#include +#include +#include +#include +#include + +namespace sprout { + namespace darkroom { + namespace lights { + // + // light_list + // + template + class light_list { + public: + typedef sprout::tuples::tuple lights_type; + typedef typename sprout::darkroom::access::unit::type::color_type color_type; + private: + lights_type lights_; + private: + template + SPROUT_CONSTEXPR color_type shade_2(Color const& col) const { + return col; + } + template + 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 + SPROUT_CONSTEXPR color_type shade_1( + Intersection const& inter, Objects const& objs, + sprout::index_tuple + ) const + { + return shade_2(sprout::darkroom::access::get(lights_).template operator()(inter, objs)...); + } + public: + explicit SPROUT_CONSTEXPR light_list(Lights const&... lights) + : lights_(lights...) + {} + template + 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 + inline SPROUT_CONSTEXPR sprout::darkroom::lights::light_list + make_light_list(Lights const&... lights) { + return sprout::darkroom::lights::light_list(lights...); + } + } // namespace lights + } // namespace darkroom +} // namespace sprout + +#endif // #ifndef SPROUT_DARKROOM_LIGHTS_LIGHT_LIST_HPP diff --git a/sprout/darkroom/lights/parallel_light.hpp b/sprout/darkroom/lights/parallel_light.hpp new file mode 100644 index 00000000..810ceae1 --- /dev/null +++ b/sprout/darkroom/lights/parallel_light.hpp @@ -0,0 +1,146 @@ +#ifndef SPROUT_DARKROOM_LIGHTS_PARALLEL_LIGHT_HPP +#define SPROUT_DARKROOM_LIGHTS_PARALLEL_LIGHT_HPP + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#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::type unit_type; + typedef Color color_type; + private: + position_type dir_; + color_type col_; + private: + template + 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 + 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::epsilon() + ? NS_SSCRISK_CEL_OR_SPROUT::max( + std::numeric_limits::epsilon(), + sprout::darkroom::coords::dot( + direction, + sprout::darkroom::intersects::normal(inter) + ) + ) + : 0 + ); + } + template + 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::epsilon() * 256 + ), + sprout::darkroom::intersects::point_of_intersection(inter) + ), + direction + ) + ) + ); + } + template + 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 + SPROUT_CONSTEXPR color_type operator()(Intersection const& inter, Objects const& objs) const { + return shade_1( + inter, + objs, + dir_ + ); + } + }; + // + // make_parallel_light + // + template + inline SPROUT_CONSTEXPR sprout::darkroom::lights::basic_parallel_light + make_parallel_light(Position const& pos, Color const& col) { + return sprout::darkroom::lights::basic_parallel_light(pos, col); + } + } // namespace lights + } // namespace darkroom +} // namespace sprout + +#endif // #ifndef SPROUT_DARKROOM_LIGHTS_PARALLEL_LIGHT_HPP diff --git a/sprout/darkroom/lights/point_light.hpp b/sprout/darkroom/lights/point_light.hpp index 655aaa5a..2a06b3d0 100644 --- a/sprout/darkroom/lights/point_light.hpp +++ b/sprout/darkroom/lights/point_light.hpp @@ -40,31 +40,12 @@ namespace sprout { unit_type const& intensity ) const { - return sprout::tuples::remake( - 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 + return sprout::darkroom::colors::mul( + sprout::darkroom::colors::filter( + col_, + sprout::darkroom::materials::color(sprout::darkroom::intersects::material(inter)) + ), + intensity ); } template diff --git a/sprout/darkroom/renderers/whitted_style.hpp b/sprout/darkroom/renderers/whitted_style.hpp index 407843b4..5c0b2836 100644 --- a/sprout/darkroom/renderers/whitted_style.hpp +++ b/sprout/darkroom/renderers/whitted_style.hpp @@ -140,10 +140,7 @@ namespace sprout { 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 - ), + mirror_color, sprout::darkroom::materials::reflection(sprout::darkroom::intersects::material(inter)) ) ) @@ -169,10 +166,10 @@ namespace sprout { ) const { return color_3( - ray, - inter, - diffuse_color, - sprout::darkroom::renderers::whitted_mirror().template operator()( + ray, + inter, + diffuse_color, + sprout::darkroom::renderers::whitted_mirror().template operator()( camera, objs, lights,