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
+3 -3
View File
@@ -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);
}
+4 -4
View File
@@ -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);
}
+3 -3
View File
@@ -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);
}
+4 -4
View File
@@ -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;
+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