From b396d6c85766a248527df363fa3d427d655295ba Mon Sep 17 00:00:00 2001 From: jgk Date: Sat, 21 Aug 2021 12:34:49 +0200 Subject: [PATCH] Provisional working coloured lights --- shader/lighting/surface.frag | 6 +++--- shader/lighting/surface.vert | 8 ++++---- shader/lighting/wall.frag | 6 +++--- shader/lighting/wall.geom | 8 ++++---- src/Dodge/Data.hs | 4 ++-- src/Dodge/LightSources.hs | 8 ++++++-- src/Dodge/Render/Picture.hs | 2 +- src/Preload/Render.hs | 4 ++-- src/Render.hs | 10 +++++----- 9 files changed, 30 insertions(+), 26 deletions(-) diff --git a/shader/lighting/surface.frag b/shader/lighting/surface.frag index de48e1bad..b31c4efa9 100644 --- a/shader/lighting/surface.frag +++ b/shader/lighting/surface.frag @@ -1,9 +1,9 @@ #version 430 core -in float lum; +in vec3 lum; in vec3 dField; out vec4 fColor; void main() { - float c = pow (1 - min(1, dot(dField,dField)) , 2) * lum ; - fColor = vec4(c,c,c,c); + vec3 c = pow (1 - min(1, dot(dField,dField)) , 2) * lum ; + fColor = vec4(c,0); } diff --git a/shader/lighting/surface.vert b/shader/lighting/surface.vert index a32ec8815..734d8eb58 100644 --- a/shader/lighting/surface.vert +++ b/shader/lighting/surface.vert @@ -2,12 +2,12 @@ layout (location = 0) in vec3 position; layout (std140, binding = 0) uniform TheMat { mat4 theMat; } ; uniform vec3 lightPos; -uniform vec2 radLum; +uniform vec4 lumRad; out vec3 dField; -out float lum; +out vec3 lum; void main() { - dField = (position - lightPos) / radLum.x; - lum = radLum.y; + dField = (position - lightPos) / lumRad.a; + lum = lumRad.rgb; gl_Position = theMat * vec4(position,1); } diff --git a/shader/lighting/wall.frag b/shader/lighting/wall.frag index de48e1bad..b31c4efa9 100644 --- a/shader/lighting/wall.frag +++ b/shader/lighting/wall.frag @@ -1,9 +1,9 @@ #version 430 core -in float lum; +in vec3 lum; in vec3 dField; out vec4 fColor; void main() { - float c = pow (1 - min(1, dot(dField,dField)) , 2) * lum ; - fColor = vec4(c,c,c,c); + vec3 c = pow (1 - min(1, dot(dField,dField)) , 2) * lum ; + fColor = vec4(c,0); } diff --git a/shader/lighting/wall.geom b/shader/lighting/wall.geom index ff622cd32..36311331c 100644 --- a/shader/lighting/wall.geom +++ b/shader/lighting/wall.geom @@ -3,9 +3,9 @@ layout (points) in; layout (triangle_strip, max_vertices = 4) out; layout (std140, binding = 0) uniform TheMat { mat4 theMat; } ; uniform vec3 lightPos; -uniform vec2 radLum; +uniform vec4 lumRad; out vec3 dField; -out float lum; +out vec3 lum; float isLHS (vec2 startV, vec2 testV) { return sign( -startV.x * testV.y + startV.y * testV.x); } void main() @@ -13,8 +13,8 @@ void main() vec4 p1 = vec4 (gl_in[0].gl_Position.xy,0,1); vec4 p2 = vec4 (gl_in[0].gl_Position.zw,0,1); if (isLHS (p1.xy - lightPos.xy, p2.xy - lightPos.xy) < 0) -{ lum = radLum.y; - float rad = radLum.x; +{ lum = lumRad.rgb; + float rad = lumRad.a; vec4 p3 = vec4 (p1.xy,100,1); vec4 p4 = vec4 (p2.xy,100,1); vec2 d1 = p1.xy - lightPos.xy; diff --git a/src/Dodge/Data.hs b/src/Dodge/Data.hs index 973bf336e..070e9469b 100644 --- a/src/Dodge/Data.hs +++ b/src/Dodge/Data.hs @@ -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 diff --git a/src/Dodge/LightSources.hs b/src/Dodge/LightSources.hs index ac19c31ed..e8303e5dd 100644 --- a/src/Dodge/LightSources.hs +++ b/src/Dodge/LightSources.hs @@ -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 diff --git a/src/Dodge/Render/Picture.hs b/src/Dodge/Render/Picture.hs index 24aee294d..dcbc20157 100644 --- a/src/Dodge/Render/Picture.hs +++ b/src/Dodge/Render/Picture.hs @@ -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) diff --git a/src/Preload/Render.hs b/src/Preload/Render.hs index 4cbbc87c2..da6198574 100644 --- a/src/Preload/Render.hs +++ b/src/Preload/Render.hs @@ -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"] diff --git a/src/Render.hs b/src/Render.hs index 948bf3c6e..28fc63473 100644 --- a/src/Render.hs +++ b/src/Render.hs @@ -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