61 lines
1.5 KiB
C++
61 lines
1.5 KiB
C++
#ifndef MATERIAL_H
|
|
#define MATERIAL_H
|
|
|
|
#include "hittable.h"
|
|
#include "vec3.h"
|
|
#include "texture.h"
|
|
|
|
struct hit_record;
|
|
|
|
class Material {
|
|
public:
|
|
virtual bool scatter(const Ray& r_in, const hit_record& rec, Color& attenuation, Ray& scattered) const = 0;
|
|
virtual Color emitted(double u, double v, const Point3& p) const { return Color(0, 0, 0); }
|
|
};
|
|
|
|
class Lambertian : public Material {
|
|
public:
|
|
Lambertian(std::shared_ptr<Texture> a) : albedo(a) {}
|
|
|
|
virtual bool scatter(const Ray& r_in, const hit_record& rec, Color& attenuation, Ray& scattered) const;
|
|
|
|
private:
|
|
std::shared_ptr<Texture> albedo;
|
|
};
|
|
|
|
class Metal : public Material {
|
|
public:
|
|
Metal(const Color& a, double f) : albedo(a), fuzz(f < 1 ? f : 1) {}
|
|
|
|
virtual bool scatter(const Ray& r_in, const hit_record& rec, Color& attenuation, Ray& scattered) const;
|
|
private:
|
|
Color albedo;
|
|
double fuzz;
|
|
};
|
|
|
|
double schlick(double cosine, double ref_idx);
|
|
|
|
class Dielectric : public Material {
|
|
public:
|
|
Dielectric(double ri) : ref_idx(ri) {}
|
|
virtual bool scatter(const Ray& r_in, const hit_record& rec, Color& attenuation, Ray& scattered) const;
|
|
private:
|
|
double ref_idx;
|
|
};
|
|
|
|
class Diffuse_light : public Material {
|
|
public:
|
|
Diffuse_light(std::shared_ptr<Texture> a) : emit(a) {}
|
|
|
|
virtual bool scatter(const Ray& r_in, const hit_record& rec, Color& attenuation, Ray& scattered) const {
|
|
return false;
|
|
}
|
|
|
|
virtual Color emitted(double u, double v, const Point3& p) const { return emit->value(u, v, p); }
|
|
|
|
private:
|
|
std::shared_ptr<Texture> emit;
|
|
};
|
|
|
|
#endif // MATERIAL_H
|