Implement texture

This commit is contained in:
CJSatnarine
2024-07-08 19:02:29 -04:00
parent e1e2d4ac2a
commit 18b2acb1fe
22 changed files with 360386 additions and 90076 deletions

View File

@@ -2,6 +2,7 @@
#define MATERIAL_H
#include "rayTracer.h"
#include "texture.h"
class hitRecord;
@@ -16,20 +17,20 @@ class material {
class lambertian : public material {
private:
colour albedo;
shared_ptr<texture> tex;
public:
lambertian(const colour& albedo) : albedo(albedo) {}
lambertian(const colour& albedo) : tex(make_shared<solidColour>(albedo)) {}
lambertian(shared_ptr<texture> tex) : tex(tex) {}
bool scatter(const ray& rIn, const hitRecord& rec, colour& attenuation, ray& scattered)
const override {
bool scatter(const ray& rIn, const hitRecord& rec, colour& attenuation, ray& scattered) const override {
auto scatterDirection = rec.normal + randomUnitVector();
// Catch degenerate scatter direction.
if (scatterDirection.nearZero()) scatterDirection = rec.normal;
scattered = ray(rec.p, scatterDirection, rIn.time());
attenuation = albedo;
attenuation = tex->value(rec.u, rec.v, rec.p);
return true;
}
};