1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- #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{
- 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 xd = 3.0f * std::exp(-mirror_ref.dot(out));
- 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
|