mirror of
https://github.com/kuhyx/WUT_Computer_Science.git
synced 2026-07-04 14:03:08 +02:00
git-subtree-dir: Programming/TRAK git-subtree-mainline:e11d703c3egit-subtree-split:777937fb9e
49 lines
1.1 KiB
Python
49 lines
1.1 KiB
Python
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 |