Skip to content
Snippets Groups Projects
Commit 1d96cb1f authored by Benjamin Koltes's avatar Benjamin Koltes
Browse files

avec les shadow

parent cc0404f8
No related branches found
No related tags found
No related merge requests found
No preview for this file type
No preview for this file type
...@@ -22,7 +22,8 @@ def trace_ray(ray, scene, camera): ...@@ -22,7 +22,8 @@ def trace_ray(ray, scene, camera):
return Vector([0,0,0]) return Vector([0,0,0])
color = ambiant_illuminate(class_intersect.position, class_intersect.object) color = ambiant_illuminate(class_intersect.position, class_intersect.object)
for light in scene.light_list: for light in scene.light_list:
color += phong_illuminate(light, class_intersect.position, class_intersect.normal, class_intersect.object, Vector([0,0,0])) # color += phong_illuminate(light, class_intersect.position, class_intersect.normal, class_intersect.object, Vector([0,0,0]))
color += compute_light(light, scene, class_intersect, Vector([0,0,0]))
color_object = class_intersect.object.material.color color_object = class_intersect.object.material.color
c_x, c_y, c_z = color.coord() c_x, c_y, c_z = color.coord()
return Vector([max(min(c_x, 1), 0), max(0, min(c_y, 1)), max(0, min(c_z,1))]) return Vector([max(min(c_x, 1), 0), max(0, min(c_y, 1)), max(0, min(c_z,1))])
...@@ -37,3 +38,15 @@ def raytracer_render(camera, scene): ...@@ -37,3 +38,15 @@ def raytracer_render(camera, scene):
color = trace_ray(ray, scene, camera) color = trace_ray(ray, scene, camera)
affiche[i,j,:] = color.coord() affiche[i,j,:] = color.coord()
return affiche return affiche
def compute_light(light, scene, intersection, viewer):
ray = Ray(light.position, (intersection.position - light.position).normalized())
distance = (intersection.position - light.position).norm()
distance_limit = distance*.99
for o in scene.object_list:
resultat = intersect(o, ray)
if resultat != None:
d = (resultat.position - ray.starting_point).norm()
if d < distance_limit: # si un objet est dans la trajectoire du rayon
return Vector([0, 0, 0])
return phong_illuminate(light, intersection.position, intersection.normal, intersection.object, viewer)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment