45 lines
1018 B
C++
45 lines
1018 B
C++
#ifndef MATERIAL_H
|
|
#define MATERIAL_H
|
|
|
|
#include "hittable.h"
|
|
#include "vec3.h"
|
|
|
|
struct hit_record;
|
|
|
|
class Material {
|
|
public:
|
|
virtual bool scatter(const Ray& r_in, const hit_record& rec, Color& attenuation, Ray& scattered) const = 0;
|
|
};
|
|
|
|
class Lambertian : public Material {
|
|
public:
|
|
Lambertian(const Color& a) : albedo(a) {}
|
|
|
|
virtual bool scatter(const Ray& r_in, const hit_record& rec, Color& attenuation, Ray& scattered) const;
|
|
|
|
private:
|
|
Color 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;
|
|
};
|
|
|
|
#endif // MATERIAL_H
|