-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathLights.hs
33 lines (24 loc) · 1.11 KB
/
Lights.hs
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
module Lights where
import Data.Vect.Float.Base
import Types
data Light
= PointLight Vec3 Color Attenuation
| DirectionalLight Vec3 Color
deriving Show
colorOf :: Light -> Color
colorOf (PointLight _ color _) = color
colorOf (DirectionalLight _ color) = color
buildPointLight :: Vec3 -> Color -> Attenuation -> Light
buildPointLight pos color attenuation = PointLight pos color attenuation
buildDirectionalLight :: Vec3 -> Color -> Light
buildDirectionalLight dir color = DirectionalLight (normalize dir) color
getDirectionFrom :: Light -> Vec3 -> Vec3
getDirectionFrom (PointLight pos _ _) point = normalize $ pos &- point
getDirectionFrom (DirectionalLight direction _) _ = direction -- TODO: why negate?
getSqrDistanceFrom :: Light -> Vec3 -> Float
getSqrDistanceFrom (PointLight pos _ _) point = normsqr $ pos &- point
getSqrDistanceFrom (DirectionalLight _ _) _ = 1.0 / 0
getAttenuationAtDistance :: Light -> Float -> Float
getAttenuationAtDistance (PointLight _ _ (Attenuation const lin quad)) distance =
const + lin * distance + quad * distance * distance
getAttenuationAtDistance (DirectionalLight _ _) _ = 1.0