module Dodge.Render.Lights ( lightsToRender, ) where import Data.List (sortOn) import Data.Maybe import Dodge.Data.LWorld import Dodge.Data.Camera import Dodge.Data.Config import Geometry import qualified IntMapHelp as IM import Control.Lens lightsToRender :: Configuration -> Camera -> LWorld -> [(Point3, Float, Point3)] {-# INLINE lightsToRender #-} lightsToRender cfig campos w = take (fromEnum $ cfig ^. graphics_num_shadow_casters) $ sortOn (\(_,x,_) -> negate x) $ mapMaybe getLS (IM.elems $ w ^. lightSources) ++ mapMaybe getTLS (w ^. tempLightSources) where getLS = getlsparam . _lsParam getTLS = getlsparam . _tlsParam cbox = campos ^. camBoundBox cpos = campos ^. camCenter getlsparam ls | not (pointInPolygon lpos cbox) && extraculltest = Nothing | otherwise = Just (_lsPos ls, rad ^ (2 :: Int), _lsCol ls) where lpos = xyV3 $ _lsPos ls rad = _lsRad ls extraculltest | debugOn Cull_more_lights cfig = True | otherwise = isNothing (intersectSegPolyFirst lpos (lpos +.+ rad *.* normalizeV (cpos -.- lpos)) cbox)