checkerboard

pull/1/head
Dmitry V. Sokolov 2019-01-20 12:27:10 +01:00
parent b69793bf6e
commit 5e0da1f09f
3 changed files with 17 additions and 1 deletions

3
.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
# Ignore content built with CMake
build/

BIN
out.jpg

Binary file not shown.

Before

Width:  |  Height:  |  Size: 46 KiB

After

Width:  |  Height:  |  Size: 104 KiB

View File

@ -69,7 +69,20 @@ bool scene_intersect(const Vec3f &orig, const Vec3f &dir, const std::vector<Sphe
material = spheres[i].material;
}
}
return spheres_dist<1000;
float checkerboard_dist = std::numeric_limits<float>::max();
if (fabs(dir.y)>1e-3) {
float d = -(orig.y+4)/dir.y; // the checkerboard plane has equation y = -4
Vec3f pt = orig + dir*d;
if (d>0 && fabs(pt.x)<10 && pt.z<-10 && pt.z>-30 && d<spheres_dist) {
checkerboard_dist = d;
hit = pt;
N = Vec3f(0,1,0);
material.diffuse_color = (int(.5*hit.x+1000) + int(.5*hit.z)) & 1 ? Vec3f(1,1,1) : Vec3f(1, .7, .3);
material.diffuse_color = material.diffuse_color*.3;
}
}
return std::min(spheres_dist, checkerboard_dist)<1000;
}
Vec3f cast_ray(const Vec3f &orig, const Vec3f &dir, const std::vector<Sphere> &spheres, const std::vector<Light> &lights, size_t depth=0) {