123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- #ifndef TEXTURE_HPP
- #define TEXTURE_HPP
- #include <Eigen/Core>
- #include <memory>
- #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<texture> tex;
- std::unique_ptr<bsdf> m_bsdf;
- material() : material(Color(1,1,1)){
- }
- material(const Color& c, std::unique_ptr<bsdf>&& bsdf) : tex(std::make_unique<uni_texture>(c)), m_bsdf(std::move(bsdf)){
-
- }
- material(const Color& c) : tex(std::make_unique<uni_texture>(c)), m_bsdf(std::make_unique<lambertian_bsdf>()){
-
- }
- };
- #endif
|