Skip to content
Permalink
Browse files

shadows

  • Loading branch information
ssloy committed Jan 20, 2019
1 parent f5ec45c commit ef70d1356169dacb3183ad4fcb4c23f1d7003e1b
Showing with 7 additions and 0 deletions.
  1. BIN out.jpg
  2. +7 −0 tinyraytracer.cpp
BIN +519 Bytes (100%) out.jpg
Binary file not shown.
@@ -69,6 +69,13 @@ Vec3f cast_ray(const Vec3f &orig, const Vec3f &dir, const std::vector<Sphere> &s
float diffuse_light_intensity = 0, specular_light_intensity = 0;
for (size_t i=0; i<lights.size(); i++) {
Vec3f light_dir = (lights[i].position - point).normalize();
float light_distance = (lights[i].position - point).norm();

Vec3f shadow_orig = light_dir*N < 0 ? point - N*1e-3 : point + N*1e-3; // checking if the point lies in the shadow of the lights[i]
Vec3f shadow_pt, shadow_N;
Material tmpmaterial;
if (scene_intersect(shadow_orig, light_dir, spheres, shadow_pt, shadow_N, tmpmaterial) && (shadow_pt-shadow_orig).norm() < light_distance)
continue;

diffuse_light_intensity += lights[i].intensity * std::max(0.f, light_dir*N);
specular_light_intensity += powf(std::max(0.f, -reflect(-light_dir, N)*dir), material.specular_exponent)*lights[i].intensity;

0 comments on commit ef70d13

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