# T1 Add an abstract class material

### T1.1 Add material.h and define class material

```cpp
#ifndef MATERIAL_H
#define MATERIAL_H

#include "hittable.h"

class material {
  public:
    virtual ~material() = default;

    virtual bool scatter(
        const ray& r_in, const hit_record& rec, color& attenuation, ray& scattered
    ) const {
        return false;
    }
};

#endif
```

### T1.2 Adding material in hit\_record

In hittable.h, make the following revisions to add material information to hit\_record

```cpp
#include "ray.h"

class material;  // <<<<<<<<<<<<<<<<<<<<<<<<<

class hit_record {
  public:
    point3 p;
    vec3 normal;
    shared_ptr<material> mat; // <<<<<<<<<<<<<<<<<<<<<<<<<

    double t;
    // ...
};

```

### T 1.3 Adding material in class sphere (sphere.h)

In class sphere add a private memember of the material pointer.

Add init of the mat pointer in the sphre construtor.

```cpp
class sphere : public hittable {
  private:
    point3 center;
    double radius;
    shared_ptr<material> mat; // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    
  public:
    // sphere(const point3& center, double radius) : center(center), radius(std::fmax(0,radius)) { }
    // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    sphere(const point3& center, double radius, shared_ptr<material> mat)
      : center(center), radius(std::fmax(0,radius)), mat(mat) {}
    // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    //...
};
```

In its hit() method, add one line to set the material for the hit point

```cpp
bool hit(const ray& r, interval ray_t, hit_record& rec) const override {
        // ...
        rec.t = root;
        rec.p = r.at(rec.t);
        rec.normal = (rec.p - center) / radius;
        vec3 outward_normal = (rec.p - center) / radius;
        rec.set_face_normal(r, outward_normal);
        rec.mat = mat; // <<<<<<<<<<<<<<<<<<<<<<<<<<<

        return true;
    }
```
