Skip to content
Permalink
Browse files

checkerboard

  • Loading branch information
ssloy committed Jan 20, 2019
1 parent b69793b commit 5e0da1f09fdbc585caa16df4c7b2f527d61536ef
Showing with 17 additions and 1 deletion.
  1. +3 −0 .gitignore
  2. BIN out.jpg
  3. +14 −1 tinyraytracer.cpp
@@ -0,0 +1,3 @@
# Ignore content built with CMake
build/

BIN +58.2 KB (230%) out.jpg
Binary file not shown.
@@ -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) {

1 comment on commit 5e0da1f

@acgetchell

This comment has been minimized.

Copy link

acgetchell commented on 5e0da1f Feb 11, 2019

Great tutorial, thank you!

Line 82 shouldn't be there and line 81 should read:

material.diffuse_color = (int(.5*hit.x+1000) + int(.5*hit.z)) & 1 ? Vec3f(.3,.3,.3) : Vec3f(.3, .2, .1);

https://github.com/ssloy/tinyraytracer/blob/master/tinyraytracer.cpp#L78

Please sign in to comment.
You can’t perform that action at this time.