Add fuzziness to metal materials
This commit is contained in:
parent
58ffcff459
commit
9870dc128e
3 changed files with 10 additions and 5 deletions
2
Makefile
2
Makefile
|
|
@ -1,4 +1,4 @@
|
|||
raytracer: main.cpp vec3.hpp color.hpp ray.hpp hittable.hpp sphere.hpp hittable_list.hpp rtweekend.hpp
|
||||
raytracer: camera.hpp color.hpp hittable.hpp hittable_list.hpp material.hpp ray.hpp rtweekend.hpp sphere.hpp vec3.hpp
|
||||
@g++ -g -O2 -Wall -Wextra -Wpedantic main.cpp -o raytracer
|
||||
|
||||
image: raytracer
|
||||
|
|
|
|||
4
main.cpp
4
main.cpp
|
|
@ -75,8 +75,8 @@ int main()
|
|||
|
||||
std::shared_ptr<lambertian> material_ground = make_shared<lambertian>(color(0.8, 0.8, 0.0));
|
||||
std::shared_ptr<lambertian> material_center = make_shared<lambertian>(color(0.7, 0.3, 0.3));
|
||||
std::shared_ptr<metal> material_left = make_shared<metal>(color(0.8, 0.8, 0.8));
|
||||
std::shared_ptr<metal> material_right = make_shared<metal>(color(0.8, 0.6, 0.2));
|
||||
std::shared_ptr<metal> material_left = make_shared<metal>(color(0.8, 0.8, 0.8), 0.3);
|
||||
std::shared_ptr<metal> material_right = make_shared<metal>(color(0.8, 0.6, 0.2), 1.0);
|
||||
|
||||
world.add(make_shared<sphere>(point3( 0.0, -100.5, -1.0), 100.0, material_ground));
|
||||
world.add(make_shared<sphere>(point3( 0.0, 0.0, -1.0), 0.5, material_center));
|
||||
|
|
|
|||
|
|
@ -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