Add material support
This commit is contained in:
parent
6d98c22890
commit
58ffcff459
7 changed files with 112 additions and 36 deletions
25
main.cpp
25
main.cpp
|
|
@ -21,8 +21,16 @@ color ray_color(const ray& r, const hittable& world, int32_t depth)
|
|||
hit_record rec;
|
||||
if (world.hit(r, 0.001, INFINITY, rec))
|
||||
{
|
||||
point3 target = rec.p + rec.normal + random_in_hemisphere(rec.normal);
|
||||
return 0.5 * ray_color(ray(rec.p, target - rec.p), world, depth-1);
|
||||
ray scattered;
|
||||
color attenuation;
|
||||
if (rec.mat_ptr->scatter(r, rec, attenuation, scattered))
|
||||
{
|
||||
return attenuation * ray_color(scattered, world, depth-1);
|
||||
}
|
||||
else
|
||||
{
|
||||
return color(0,0,0);
|
||||
}
|
||||
}
|
||||
vec3 unit_direction = normalize(r.direction);
|
||||
double t = 0.5 * (unit_direction.y + 1.0);
|
||||
|
|
@ -64,8 +72,17 @@ int main()
|
|||
|
||||
// World
|
||||
hittable_list world;
|
||||
world.add(std::make_shared<sphere>(point3(0,0,-1), 0.5));
|
||||
world.add(std::make_shared<sphere>(point3(0,-100.5,-1), 100));
|
||||
|
||||
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));
|
||||
|
||||
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));
|
||||
world.add(make_shared<sphere>(point3(-1.0, 0.0, -1.0), 0.5, material_left));
|
||||
world.add(make_shared<sphere>(point3( 1.0, 0.0, -1.0), 0.5, material_right));
|
||||
|
||||
|
||||
// Camera
|
||||
camera cam;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue