Make light position uniform 3d

This commit is contained in:
jgk
2021-06-25 01:19:20 +02:00
parent b451953b99
commit b6feccd934
10 changed files with 40 additions and 71 deletions
+3 -4
View File
@@ -2,11 +2,10 @@
layout (points) in;
layout (triangle_strip, max_vertices = 11) out;
layout (std140, binding = 0) uniform TheMat { mat4 theMat; } ;
uniform vec2 lightPos;
vec2 lightPosa = ( theMat * vec4(lightPos,0.1,1) ).xy;
uniform vec3 lightPos;
vec4 shift (vec4 p)
{ return vec4 (p.xy + (200 * (p.xy-lightPos)), 0.1 , 1);
{ return vec4 (p.xy + (200 * (p.xy-lightPos.xy)), 0.1 , 1);
}
float isLHS (vec2 startV, vec2 testV)
{
@@ -17,7 +16,7 @@ void main()
{
vec4 p1 = vec4 (gl_in[0].gl_Position.xy,0.1,1);
vec4 p2 = vec4 (gl_in[0].gl_Position.zw,0.1,1);
if (isLHS (p1.xy - lightPos, p2.xy - lightPos) < 0)
if (isLHS (p1.xy - lightPos.xy, p2.xy - lightPos.xy) < 0)
{
vec4 p3 = vec4 (p1.xy,-0.5,1);
vec4 p4 = vec4 (p2.xy,-0.5,1);
+5 -38
View File
@@ -2,22 +2,21 @@
layout (points) in;
layout (triangle_strip, max_vertices = 4) out;
layout (std140, binding = 0) uniform TheMat { mat4 theMat; } ;
uniform vec3 lightPos;
uniform vec2 radLum;
out vec3 dField;
out float lum;
uniform vec2 lightPos;
uniform vec2 radLum;
float isLHS (vec2 startV, vec2 testV)
{
return sign( -startV.x * testV.y + startV.y * testV.x);
}
vec4 shiftCloser (vec4 v)
{ return vec4 (v.xy , v.z-0.0001 , v.w) ; }
void main()
{
vec4 p1 = vec4 (gl_in[0].gl_Position.xy,0.1,1);
vec4 p2 = vec4 (gl_in[0].gl_Position.zw,0.1,1);
if (isLHS (p1.xy - lightPos, p2.xy - lightPos) < 0)
if (isLHS (p1.xy - lightPos.xy, p2.xy - lightPos.xy) < 0)
{
lum = radLum.y;
float rad = radLum.x;
@@ -25,8 +24,8 @@ if (isLHS (p1.xy - lightPos, p2.xy - lightPos) < 0)
vec4 p3 = vec4 (p1.xy,-0.3,1);
vec4 p4 = vec4 (p2.xy,-0.3,1);
vec2 d1 = p1.xy - lightPos;
vec2 d2 = p2.xy - lightPos;
vec2 d1 = p1.xy - lightPos.xy;
vec2 d2 = p2.xy - lightPos.xy;
vec4 a1 = shiftCloser( theMat * p1 );
vec4 a2 = shiftCloser( theMat * p2 );
@@ -49,35 +48,3 @@ if (isLHS (p1.xy - lightPos, p2.xy - lightPos) < 0)
EndPrimitive();
} else {}
}
// // void main()
// // {
// // vec4 frontL4 = worldMat * vec4(gl_in[0].gl_Position.xy, 0 ,1);
// // vec4 frontR4 = worldMat * vec4(gl_in[0].gl_Position.zw, 0 ,1);
// // vec2 frontL = frontL4.xy;
// // vec2 frontR = frontR4.xy;
// //
// // emitLine (frontR);
// // emitLine (frontL);
// // EndPrimitive();
// // }
// gl_Position = perspective * worldMat * p4; EmitVertex();
// gl_Position = perspective * worldMat * p3; EmitVertex();
// gl_Position = perspective * worldMat * p7; EmitVertex();
// gl_Position = perspective * worldMat * p8; EmitVertex();
// gl_Position = perspective * worldMat * p5; EmitVertex();
// gl_Position = perspective * worldMat * p3; EmitVertex();
// gl_Position = perspective * worldMat * p1; EmitVertex();
// gl_Position = perspective * worldMat * p4; EmitVertex();
// gl_Position = perspective * worldMat * p2; EmitVertex();
// gl_Position = perspective * worldMat * p7; EmitVertex();
// gl_Position = perspective * worldMat * p6; EmitVertex();
// gl_Position = perspective * worldMat * p5; EmitVertex();
//void emitLine (vec2 pa)
//{
// gl_Position = vec4 (pa, 0, 1);
// EmitVertex();
// gl_Position = shift (vec4 (pa,0,1)); //vec4 (pa + (200 * (pa - lightPosa)), 0 , 1);
// EmitVertex();
//}
+2 -1
View File
@@ -55,9 +55,10 @@ updateLamp i = unrandUpdate handleLS internalUpdate
handleLS cr w
| _crHP cr < 0 = explosionFlashAt cPos
$ mkSoundBreakGlass cPos w & lightSources %~ IM.delete i
| otherwise = w & lightSources . ix i . lsPos .~ cPos
| otherwise = w & lightSources . ix i . lsPos .~ f cPos
where
cPos = _crPos cr
f (x,y) = (x,y,0)
internalUpdate cr
| _crHP cr < 0 = Nothing
| otherwise = Just $ doDamage cr
+2 -2
View File
@@ -130,13 +130,13 @@ data Cloud = Cloud
}
data LightSource = LS
{ _lsID :: !Int
, _lsPos :: !Point2
, _lsPos :: !Point3
, _lsDir :: !Float
, _lsRad :: !Float
, _lsIntensity :: !Float
}
data TempLightSource = TLS
{ _tlsPos :: !Point2
{ _tlsPos :: !Point3
, _tlsRad :: !Float
, _tlsIntensity :: !Float
, _tlsUpdate :: World -> TempLightSource -> (World, Maybe TempLightSource)
+4 -2
View File
@@ -86,8 +86,10 @@ defaultDebugFlags = DebugFlags
}
youLight :: TempLightSource
youLight =
TLS { _tlsPos = (0,0)
TLS { _tlsPos = (0,0,0)
,_tlsRad = 300
,_tlsIntensity = 0.1
,_tlsUpdate = \w _ -> (w, Just (youLight {_tlsPos = _crPos (you w)}))
,_tlsUpdate = \w _ -> (w, Just (youLight {_tlsPos = f $ _crPos (you w)}))
}
where
f (x,y) = (x,y,0)
+2 -2
View File
@@ -189,11 +189,11 @@ placeCr crF p rot = over creatures addCr
crs
placeLS :: LightSource -> Picture -> Point2 -> Float -> World -> World
placeLS ls dec p rot w = over lightSources addLS $ over decorations addDec w
placeLS ls dec p@(x,y) rot w = over lightSources addLS $ over decorations addDec w
where
addLS lss = IM.insert
(IM.newKey lss)
(ls {_lsPos = p,_lsDir = rot,_lsID = IM.newKey lss})
(ls {_lsPos = (x,y,0),_lsDir = rot,_lsID = IM.newKey lss})
lss
addDec decs = IM.insert
(IM.newKey decs)
+10 -10
View File
@@ -9,9 +9,9 @@ import Picture
--import qualified Data.IntMap.Strict as IM
lightAt :: Point2 -> Int -> LightSource
lightAt p i =
lightAt (x,y) i =
LS {_lsID = i
,_lsPos = p
,_lsPos = (x,y,0)
,_lsDir = 0
,_lsRad = 600
,_lsIntensity = 0.75
@@ -23,14 +23,14 @@ basicLS = PutLS ls dec
dec = onLayer PtLayer $ color white $ circleSolid 8
tLightFade :: Int -> Float -> (Int -> Float) -> Point2 -> TempLightSource
tLightFade 0 rmax intensityF p = TLS
{ _tlsPos = p
tLightFade 0 rmax intensityF (x,y) = TLS
{ _tlsPos = (x,y,0)
, _tlsRad = rmax
, _tlsIntensity = intensityF 0
, _tlsUpdate = \w _ -> (w, Nothing)
}
tLightFade i rmax intensityF p = TLS
{ _tlsPos = p
tLightFade i rmax intensityF p@(x,y) = TLS
{ _tlsPos = (x,y,0)
, _tlsRad = rmax
, _tlsIntensity = intensityF i
, _tlsUpdate = \w _ -> (w, Just $ tLightFade (i-1) rmax intensityF p)
@@ -42,14 +42,14 @@ tLightRad
-> Float -- ^ minimal radius (unused)
-> Point2
-> TempLightSource
tLightRad 0 rmax _ p = TLS
{ _tlsPos = p
tLightRad 0 rmax _ (x,y) = TLS
{ _tlsPos = (x,y,0)
, _tlsRad = rmax
, _tlsIntensity = 0.5
, _tlsUpdate = \w _ -> (w, Nothing)
}
tLightRad i rmax rmin p = TLS
{ _tlsPos = p
tLightRad i rmax rmin p@(x,y) = TLS
{ _tlsPos = (x,y,0)
, _tlsRad = rmax
, _tlsIntensity = 0.5
, _tlsUpdate = \w _ -> (w, Just $ tLightRad (i-1) rmax rmin p)
+3 -3
View File
@@ -217,8 +217,8 @@ wallsForShadows w = map _wlLine
. filter (not . _wlIsSeeThrough)
. IM.elems $ wallsNearZones (zoneOfDoubleScreen w) w
lightsForGloom :: World -> [Point4]
lightsForGloom :: World -> [(Point3,Float,Float)]
lightsForGloom w = map getLS (IM.elems $ _lightSources w) ++ map getTLS (_tempLightSources w)
where
getLS ls = ( fst $ _lsPos ls, snd $ _lsPos ls, _lsRad ls , _lsIntensity ls)
getTLS ls = ( fst $ _tlsPos ls,snd $ _tlsPos ls, _tlsRad ls, _tlsIntensity ls)
getLS ls = ( _lsPos ls, _lsRad ls , _lsIntensity ls)
getTLS ls = ( _tlsPos ls, _tlsRad ls, _tlsIntensity ls)
+5 -4
View File
@@ -86,10 +86,11 @@ flashFlareAt col alphax (x,y) = Particle
explosionFlashAt :: Point2 -> World -> World
explosionFlashAt p = over tempLightSources ((:) $ tLightFade 20 150 intensityFunc p)
. glareAt 20 10 5 (withAlpha 0.3 white) 75 150 p
where intensityFunc x
| x < 10 = 1 / (10 - fromIntegral x)
| otherwise = 1
. glareAt 20 10 5 (withAlpha 0.3 white) 75 150 p
where
intensityFunc x
| x < 10 = 1 / (10 - fromIntegral x)
| otherwise = 1
flameGlareAt :: Point2 -> World -> World
flameGlareAt = glareAt 1 10 5 (withAlpha 0.05 orange) 8 40
+4 -5
View File
@@ -55,12 +55,11 @@ createLightMap
:: RenderData
-> Int -- Resolution division
-> [(Point2,Point2)] -- Wall pairs
-> [Point4] -- Lights
-> [(Point3,Float,Float)] -- Lights
-> (Float,Float) -- View from position
-> Picture -- foreground pictures
-> IO ()
createLightMap pdata resDiv wallPoints lightPoints (viewFromx,viewFromy) _ = do
-- get viewport size so we can reset it later
(vppos,vpsize) <- get viewport
-- set the viewport size to that of the render buffer
@@ -97,7 +96,7 @@ createLightMap pdata resDiv wallPoints lightPoints (viewFromx,viewFromy) _ = do
depthMask $= Disabled
blendFunc $= (Zero, OneMinusSrcAlpha)
stencilTest $= Enabled
forM_ lightPoints $ \(x,y,r,lum) -> do
forM_ lightPoints $ \((x,y,z),r,lum) -> do
-- bind buffer for floor light circle
let lightPtr = _vboPointer $ _vaoVBO $ _shaderVAO $ _lightingFloorShader pdata
pokeFourOff lightPtr 0 (x,y,r,lum)
@@ -109,7 +108,7 @@ createLightMap pdata resDiv wallPoints lightPoints (viewFromx,viewFromy) _ = do
stencilFunc $= (Always, 0, 255)
currentProgram $= Just (_shaderProgram $ _lightingOccludeShader pdata)
uniform (head $ _shaderCustomUnis $ _lightingOccludeShader pdata)
$= Vector2 x y
$= Vector3 x y z
drawShader (_lightingOccludeShader pdata) nWalls
cullFace $= Just Front
stencilOp $= (OpKeep,OpKeep,OpDecr)
@@ -123,7 +122,7 @@ createLightMap pdata resDiv wallPoints lightPoints (viewFromx,viewFromy) _ = do
-- draw wall light "circles"
currentProgram $= Just (_shaderProgram $ _lightingWallShader pdata)
uniform (head $ _shaderCustomUnis $ _lightingWallShader pdata)
$= Vector2 x y
$= Vector3 x y z
uniform (_shaderCustomUnis (_lightingWallShader pdata) !! 1)
$= Vector2 r lum
drawShader (_lightingWallShader pdata) nWallLights