-
Notifications
You must be signed in to change notification settings - Fork 45
/
Copy pathlights.py
49 lines (37 loc) · 1.18 KB
/
lights.py
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
from .utils.constants import SKYBOX_DISTANCE
import numpy as np
from abc import abstractmethod
# lights only have effect on Glossy materials
class Light:
def __init__(self, pos, color):
self.pos = pos
self.color = color
@abstractmethod
def get_L(self):
pass
@abstractmethod
def get_irradiance(self, dist_light, NdotL):
pass
@abstractmethod
def get_distance(self, M):
pass
class PointLight(Light):
def __init__(self, pos, color):
self.pos = pos
self.color = color
def get_L(self):
return (self.pos - M)*(1./(dist_light))
def get_distance(self, M):
return np.sqrt((self.pos - M).dot(self.pos - M))
def get_irradiance(self,dist_light, NdotL):
return self.color * NdotL/(dist_light**2.) * 100
class DirectionalLight(Light):
def __init__(self, Ldir, color):
self.Ldir = Ldir
self.color = color
def get_L(self):
return self.Ldir
def get_distance(self, M):
return SKYBOX_DISTANCE
def get_irradiance(self, dist_light, NdotL):
return self.color * NdotL