Skip to content

Commit

Permalink
shadows (#3)
Browse files Browse the repository at this point in the history
* shadows

* remove comment

* hit normals smoothing
  • Loading branch information
satelllte authored Mar 13, 2024
1 parent 8742618 commit 65d8146
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/components/Raytracer/shader.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,13 @@ fn trace_ray(
for (var i: i32 = 0; i < lights_count; i++) {
let light = lights[i];
let light_direction = normalize(light.position - hit.position);
let light_distance = distance(light.position, hit.position);
let shadow_origin = select(hit.position + hit.normal * 0.00001, hit.position - hit.normal * 0.00001, dot(light_direction, hit.normal) < 0);
let shadow_hit = hit_spheres(spheres, Ray(shadow_origin, light_direction));
if (shadow_hit.index >= 0 && distance(shadow_hit.hit.position, shadow_origin) < light_distance) {
continue;
}

diffuse_light_intensity += light.intensity * max(0.0, dot(light_direction, hit.normal));
specular_light_intensity += pow(max(0.0, dot(reflect(light_direction, hit.normal), ray.direction)), material.specular_exponent) * light.intensity;
}
Expand Down

0 comments on commit 65d8146

Please sign in to comment.