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