Add fuzziness to metal materials
This commit is contained in:
parent
58ffcff459
commit
9870dc128e
3 changed files with 10 additions and 5 deletions
|
|
@ -37,13 +37,18 @@ struct lambertian : material {
|
|||
struct metal : material {
|
||||
/* Attributes */
|
||||
color albedo;
|
||||
double fuzz;
|
||||
// Constructor
|
||||
metal(const color& c) { albedo = c; };
|
||||
metal(const color& c, double f)
|
||||
{
|
||||
albedo = c;
|
||||
fuzz = f;
|
||||
};
|
||||
|
||||
virtual bool scatter(const ray& r_in, const hit_record& rec, color& attenuation, ray& scattered) const override
|
||||
{
|
||||
vec3 reflected = reflect(normalize(r_in.direction), rec.normal);
|
||||
scattered = ray(rec.p, reflected);
|
||||
scattered = ray(rec.p, reflected + fuzz*random_in_unit_sphere());
|
||||
attenuation = albedo;
|
||||
return (dot(scattered.direction, rec.normal) > 0);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue