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

reflexions

parent 990e902e
No related branches found
No related tags found
No related merge requests found
No preview for this file type
...@@ -8,7 +8,7 @@ class Ray: ...@@ -8,7 +8,7 @@ class Ray:
self.starting_point = starting_point self.starting_point = starting_point
self.direction = direction self.direction = direction
def trace_ray(ray, scene, camera): def trace_ray(ray, scene, camera, number_iterations = 20):
intersect_list = [] intersect_list = []
distance = float('inf') distance = float('inf')
for o in scene.object_list: for o in scene.object_list:
...@@ -24,7 +24,16 @@ def trace_ray(ray, scene, camera): ...@@ -24,7 +24,16 @@ def trace_ray(ray, scene, camera):
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 += compute_light(light, scene, class_intersect, Vector([0,0,0]))
color_object = class_intersect.object.material.color c_x, c_y, c_z = color.coord()
color = Vector([max(min(c_x, 1), 0), max(0, min(c_y, 1)), max(0, min(c_z,1))])
if number_iterations > 0:
D, N = ray.direction.normalized(), class_intersect.normal
reflected_direction = D - 2*(D*N)*N
new_ray = Ray(class_intersect.position + 1e-2 * reflected_direction, reflected_direction)
r = class_intersect.object.material.reflection
trace_ray_color = trace_ray(new_ray, scene, camera, number_iterations - 1)
#if trace_ray_color != Vector([0,0,0]):
color = (1 - r)*color + r*trace_ray_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))])
......
# Show to python where to find the modules
import sys
sys.path.append('..')
from scene import *
from light import Spotlight
from camera import Camera
from raytracer import raytracer_render
from matplotlib.image import imsave
import sys
camera = Camera(200,200,1)
materiau_sphere_bleue = Material(Vector((0,0,1)), .7, .7, .7, 100, .7)
materiau_sphere_rouge = Material(Vector((1,0,0)), .7, .7, .7, 100, .7)
sphere_bleue = Sphere(Vector([0,0,3]), .8, materiau_sphere_bleue)
sphere_rouge = Sphere(Vector([0.5,0.5,2]), .5, materiau_sphere_rouge)
lumiere = Spotlight(Vector((1,1,0)), Vector((1,1,1)))
scene = Scene()
scene.add_object(sphere_bleue)
scene.add_object(sphere_rouge)
scene.add_light(lumiere)
affiche = raytracer_render(camera, scene)
imsave('two_spheres_reflection.png',affiche)
scenes/two_spheres.png

7.14 KiB | W: | H:

scenes/two_spheres.png

2.91 KiB | W: | H:

scenes/two_spheres.png
scenes/two_spheres.png
scenes/two_spheres.png
scenes/two_spheres.png
  • 2-up
  • Swipe
  • Onion skin
scenes/two_spheres_reflection.png

2.12 KiB

0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment