#ifndef TEXTURE_HPP #define TEXTURE_HPP #include #include #include "warping.hpp" using Color = Eigen::Vector3f; struct texture{ virtual Eigen::Vector3f eval(float u, float v)const{ return Eigen::Vector3f(1,1,1); } }; struct uni_texture : texture{ Color c; uni_texture(const Color& _c) : c(_c){} virtual Eigen::Vector3f eval(float u, float v)const override{ return c; } }; struct bsdf{ virtual Color eval(const Eigen::Vector3f& in, const Eigen::Vector3f& out, const Eigen::Vector3f& normal)const{ throw 5; return Eigen::Vector3f(1,1,1); } }; struct lambertian_bsdf : bsdf{ virtual Color eval(const Eigen::Vector3f& in, const Eigen::Vector3f& out, const Eigen::Vector3f& normal)const override{ float x = in.dot(-normal); return Eigen::Vector3f(x,x,x); } }; struct microfacet_bsdf : bsdf{ const float alpha; microfacet_bsdf() : alpha(0.1f){} microfacet_bsdf(float _alpha) : alpha(_alpha){} virtual Color eval(const Eigen::Vector3f& in, const Eigen::Vector3f& out, const Eigen::Vector3f& normal)const override{ //float x = in.dot(-normal); //return Eigen::Vector3f(x,x,x); Eigen::Vector3f mirror_ref = in + normal * (in.dot(normal)); //float x = beckmann_eval(mirror_ref, alpha); float x = 1.0f * std::exp(mirror_ref.dot(out) - 1); return Color(x,x,x); } }; struct material{ std::unique_ptr tex; std::unique_ptr m_bsdf; material() : material(Color(1,1,1)){ } material(const Color& c, std::unique_ptr&& bsdf) : tex(std::make_unique(c)), m_bsdf(std::move(bsdf)){ } material(const Color& c) : tex(std::make_unique(c)), m_bsdf(std::make_unique()){ } }; #endif