Basic diffuse mapping and gamma correction
This commit is contained in:
parent
2756d676f1
commit
4497cc7f68
4 changed files with 41 additions and 10 deletions
15
main.cpp
15
main.cpp
|
|
@ -8,15 +8,21 @@
|
|||
#include "sphere.hpp"
|
||||
#include "camera.hpp"
|
||||
|
||||
color ray_color(const ray& r, const hittable& world);
|
||||
color ray_color(const ray& r, const hittable& world, int32_t depth);
|
||||
double hit_sphere(const point3& center, double radius, const ray& r);
|
||||
|
||||
color ray_color(const ray& r, const hittable& world)
|
||||
color ray_color(const ray& r, const hittable& world, int32_t depth)
|
||||
{
|
||||
if (depth <= 0)
|
||||
{
|
||||
return color(0,0,0);
|
||||
}
|
||||
|
||||
hit_record rec;
|
||||
if (world.hit(r, 0, INFINITY, rec))
|
||||
{
|
||||
return 0.5 * (rec.normal + color(1,1,1));
|
||||
point3 target = rec.p + rec.normal + random_in_unit_sphere();
|
||||
return 0.5 * ray_color(ray(rec.p, target - rec.p), world, depth-1);
|
||||
}
|
||||
vec3 unit_direction = normalize(r.direction);
|
||||
double t = 0.5 * (unit_direction.y + 1.0);
|
||||
|
|
@ -47,6 +53,7 @@ int main()
|
|||
const int32_t image_width = 400;
|
||||
const int32_t image_height = (int32_t) (image_width / aspect_ratio);
|
||||
int32_t samples_per_pixel = 100;
|
||||
int32_t max_depth = 50;
|
||||
|
||||
if (getenv("SPP"))
|
||||
{
|
||||
|
|
@ -79,7 +86,7 @@ int main()
|
|||
double u = ((i + random_double()) / (image_width-1));
|
||||
double v = ((j + random_double()) / (image_height-1));
|
||||
ray r = cam.get_ray(u,v);
|
||||
pixel_color += ray_color(r, world);
|
||||
pixel_color += ray_color(r, world, max_depth);
|
||||
}
|
||||
|
||||
write_color(stdout, pixel_color, samples_per_pixel);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue