-
Notifications
You must be signed in to change notification settings - Fork 34
/
playground_raytracer
122 lines (122 loc) · 2.89 KB
/
playground_raytracer
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
classDiagram
class Vector {
+x: number
+y: number
+z: number
+times(k: number, v: Vector)$: Vector
+minus(v1: Vector, v2: Vector)$: Vector
+plus(v1: Vector, v2: Vector)$: Vector
+dot(v1: Vector, v2: Vector)$: number
+mag(v: Vector)$: number
+norm(v: Vector)$: Vector
+cross(v1: Vector, v2: Vector)$: Vector
}
class Ray {
+start: Vector
+dir: Vector
}
<<Interface>> Ray
class Intersection {
+thing: Thing
+ray: Ray
+dist: number
}
<<Interface>> Intersection
class Color {
+r: number
+g: number
+b: number
+scale(k: number, v: Color)$: Color
+plus(v1: Color, v2: Color)$: Color
+times(v1: Color, v2: Color)$: Color
+white$: Color
+grey$: Color
+black$: Color
+background$: Color
+defaultColor$: Color
+toDrawingColor(c: Color)$: Inline
}
class Surface {
+diffuse: (pos: Vector) => Color
+specular: (pos: Vector) => Color
+reflect: (pos: Vector) => number
+roughness: number
}
<<Interface>> Surface
class Thing {
+intersect: (ray: Ray) => Intersection
+normal: (pos: Vector) => Vector
+surface: Surface
+destroy(): void
+destroy(name: string): void
}
<<Interface>> Thing
class Light {
+pos: Vector
+color: Color
}
<<Interface>> Light
class Camera {
+forward: Vector
+right: Vector
+up: Vector
+pos: Vector
}
class Scene {
+things: Thing[]
+lights: Light[]
+camera: Camera
}
<<Interface>> Scene
Thing <|.. Plane
class Plane {
+normal: (pos: Vector) => Vector
+intersect: (ray: Ray) => Intersection
+surface: Surface
}
Thing <|.. Sphere
class Sphere {
+radius2: number
+center: Vector
+surface: Surface
+normal(pos: Vector): Vector
+intersect(ray: Ray): Inline
}
class RayTracer {
-maxDepth: number
-intersections(ray: Ray, scene: Scene): Intersection
-testRay(ray: Ray, scene: Scene): number
-traceRay(ray: Ray, scene: Scene, depth: number): Color
-shade(isect: Intersection, scene: Scene, depth: number): Color
-getReflectionColor(thing: Thing, pos: Vector, normal: Vector, rd: Vector, scene: Scene, depth: number): Color
-getNaturalColor(thing: Thing, pos: Vector, norm: Vector, rd: Vector, scene: Scene): any
+render(scene: any, ctx: any, screenWidth: any, screenHeight: any): void
}
Ray ..> "1" Vector
Intersection ..> "1" Thing
Intersection ..> "1" Ray
Surface ..> "1" Vector
Surface ..> "1" Color
Thing ..> "1" Ray
Thing ..> "1" Intersection
Thing ..> "1" Vector
Thing ..> "1" Surface
Light ..> "1" Vector
Light ..> "1" Color
Camera ..> "1" Vector
Scene ..> "*" Thing
Scene ..> "*" Light
Scene ..> "1" Camera
Plane ..> "1" Vector
Plane ..> "1" Ray
Plane ..> "1" Intersection
Plane ..> "1" Surface
Sphere ..> "1" Vector
Sphere ..> "1" Surface
Sphere ..> "1" Ray
RayTracer ..> "1" Ray
RayTracer ..> "1" Scene
RayTracer ..> "1" Intersection
RayTracer ..> "1" Color
RayTracer ..> "1" Thing
RayTracer ..> "1" Vector