mirror of
https://github.com/ssloy/tinyraytracer.git
synced 2025-01-16 21:58:13 +01:00
checkerboard
This commit is contained in:
parent
b69793bf6e
commit
5e0da1f09f
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
# Ignore content built with CMake
|
||||
build/
|
||||
|
BIN
out.jpg
BIN
out.jpg
Binary file not shown.
Before Width: | Height: | Size: 46 KiB After Width: | Height: | Size: 104 KiB |
@ -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) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user