-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTracer.py
More file actions
62 lines (50 loc) · 2.21 KB
/
Tracer.py
File metadata and controls
62 lines (50 loc) · 2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
from Utility import Ray, Color
class Tracer:
def __init__(self, scene):
self.scene = scene
def trace_ray(self, ray_origin, ray_direction):
pass
class RayCast(Tracer):
def trace_ray(self, ray_origin, ray_direction, ray_depth):
shading_point = self.scene.hit_objects(ray_origin, ray_direction)
if(shading_point.hit_an_object):
ray = Ray(ray_origin, ray_direction)
shading_point.ray = ray
return shading_point.material.shade(shading_point)
else:
return self.scene.background_color
class AreaLighting(Tracer):
def trace_ray(self, ray_origin, ray_direction, ray_depth):
shading_point = self.scene.hit_objects(ray_origin, ray_direction)
if(shading_point.hit_an_object):
ray = Ray(ray_origin, ray_direction)
shading_point.ray = ray
return shading_point.material.area_light_shade(shading_point)
else:
return self.scene.background_color
class Whitted(Tracer):
def trace_ray(self, ray_origin, ray_direction, ray_depth):
if ray_depth > self.scene.view_plane.max_ray_depth:
return Color(0.0, 0.0, 0.0)
else:
shading_point = self.scene.hit_objects(ray_origin, ray_direction)
if(shading_point.hit_an_object):
ray = Ray(ray_origin, ray_direction)
shading_point.ray = ray
shading_point.ray_depth = ray_depth
return shading_point.material.shade(shading_point)
else:
return self.scene.background_color
class PathTracer(Tracer):
def trace_ray(self, ray_origin, ray_direction, ray_depth):
if ray_depth > self.scene.view_plane.max_ray_depth:
return Color(0.0, 0.0, 0.0)
else:
shading_point = self.scene.hit_objects(ray_origin, ray_direction)
if(shading_point.hit_an_object):
ray = Ray(ray_origin, ray_direction)
shading_point.ray = ray
shading_point.ray_depth = ray_depth
return shading_point.material.path_shade(shading_point)
else:
return self.scene.background_color