mirror of
https://github.com/ssloy/tinyraytracer.git
synced 2025-09-02 10:32:39 +02:00
shadows
This commit is contained in:
BIN
out.jpg
BIN
out.jpg
Binary file not shown.
Before Width: | Height: | Size: 49 KiB After Width: | Height: | Size: 50 KiB |
@@ -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;
|
||||
|
Reference in New Issue
Block a user