Provisional working coloured lights

This commit is contained in:
jgk
2021-08-21 12:34:49 +02:00
parent e35b95bf36
commit b396d6c857
9 changed files with 30 additions and 26 deletions
+2 -2
View File
@@ -142,12 +142,12 @@ data LightSource = LS
, _lsPos :: !Point3
, _lsDir :: !Float
, _lsRad :: !Float
, _lsIntensity :: !Float
, _lsIntensity :: !Point3
}
data TempLightSource = TLS
{ _tlsPos :: !Point3
, _tlsRad :: !Float
, _tlsIntensity :: !Float
, _tlsIntensity :: !Point3
, _tlsUpdate :: World -> TempLightSource -> (World, Maybe TempLightSource)
}
data Creature = Creature
+6 -2
View File
@@ -25,15 +25,19 @@ tLightFade :: Int -> Float -> (Int -> Float) -> Point2 -> TempLightSource
tLightFade 0 rmax intensityF (V2 x y) = TLS
{ _tlsPos = V3 x y 0
, _tlsRad = rmax
, _tlsIntensity = intensityF 0
, _tlsIntensity = f $ intensityF 0
, _tlsUpdate = \w _ -> (w, Nothing)
}
where
f x' = V3 x' x' x'
tLightFade i rmax intensityF p@(V2 x y) = TLS
{ _tlsPos = V3 x y 0
, _tlsRad = rmax
, _tlsIntensity = intensityF i
, _tlsIntensity = f $ intensityF i
, _tlsUpdate = \w _ -> (w, Just $ tLightFade (i-1) rmax intensityF p)
}
where
f x' = V3 x' x' x'
tLightRad
:: Int
+1 -1
View File
@@ -220,7 +220,7 @@ wallsToList :: [((Point2,Point2),Point4)] -> [Float]
wallsToList = concatMap (\((V2 a b,V2 c d),V4 e f g h) -> [a,b,c,d,e,f,g,h])
lightsForGloom :: World -> [(Point3,Float,Float)]
lightsForGloom :: World -> [(Point3,Float,Point3)]
lightsForGloom w = map getLS (IM.elems $ _lightSources w) ++ map getTLS (_tempLightSources w)
where
getLS ls = ( _lsPos ls, _lsRad ls , _lsIntensity ls)
+2 -2
View File
@@ -57,10 +57,10 @@ preloadRender = do
>>= addUniforms ["lightPos"]
wlLightShad
<- makeShaderUsingShaderVAO "lighting/wall" [vert,geom,frag] EPoints wsShad
>>= addUniforms ["lightPos","radLum"]
>>= addUniforms ["lightPos","lumRad"]
lightingSurfaceShad
<- makeShader "lighting/surface" [vert,frag] [3] ETriangles
>>= addUniforms ["lightPos","radLum"]
>>= addUniforms ["lightPos","lumRad"]
lightingLineShadowShad
<- makeShader "lighting/lineShadow" [vert,geom,frag] [3] ELinesAdjacency
>>= addUniforms ["lightPos"]
+5 -5
View File
@@ -25,7 +25,7 @@ sizeToTexSize (Size x y) = TextureSize2D x y
{- | Determine where light is shining in the world. -}
createLightMap
:: RenderData
-> [(Point3,Float,Float)] -- Lights
-> [(Point3,Float,Point3)] -- Lights
-> Int -- ^ number of walls
-> Int -- ^ number of silhoutte lines to draw
-> Int -- ^ number of surface triangles to draw
@@ -53,10 +53,10 @@ createLightMap pdata lightPoints nWalls nSils nsurfVs = do
-- draw fading lightmap circles on the floor
-- draw fading lightmaps on the walls
depthMask $= Disabled
blendFunc $= (Zero, OneMinusSrcAlpha)
blendFunc $= (Zero, OneMinusSrcColor)
stencilTest $= Enabled
depthFunc $= Just Lequal
flip VS.mapM_ (VS.fromList lightPoints) $ \(V3 x y z,r,lum) -> do
flip VS.mapM_ (VS.fromList lightPoints) $ \(V3 x y z,rad,V3 r g b) -> do
--forM_ lightPoints $ \(V3 x y z,r,lum) -> do
-- stencil out shadows
colorMask $= Color4 Disabled Disabled Disabled Disabled
@@ -89,14 +89,14 @@ createLightMap pdata lightPoints nWalls nSils nsurfVs = do
uniform (head $ _shaderCustomUnis $ _lightingSurfaceShader pdata)
$= Vector3 x y z
uniform (_shaderCustomUnis (_lightingSurfaceShader pdata) !! 1)
$= Vector2 r lum
$= Vector4 r g b rad
drawShader (_lightingSurfaceShader pdata) nsurfVs
-- draw wall light "circles"
currentProgram $= Just (_shaderProgram $ _lightingWallShader pdata)
uniform (head $ _shaderCustomUnis $ _lightingWallShader pdata)
$= Vector3 x y z
uniform (_shaderCustomUnis (_lightingWallShader pdata) !! 1)
$= Vector2 r lum
$= Vector4 r g b rad
drawShader (_lightingWallShader pdata) nWalls
cullFace $= Nothing
stencilTest $= Disabled