Clarify number of distortions, play with distorting bullets
This commit is contained in:
@@ -1,9 +1,10 @@
|
|||||||
#version 450 core
|
#version 450 core
|
||||||
in vec2 texPos;
|
in vec2 texPos;
|
||||||
in vec2 distmask[10];
|
const int n1 = 15;
|
||||||
in vec2 pinchr[10];
|
in vec2 distmask[n1];
|
||||||
in vec2 pinchg[10];
|
in vec2 pinchr[n1];
|
||||||
in vec2 pinchb[10];
|
in vec2 pinchg[n1];
|
||||||
|
in vec2 pinchb[n1];
|
||||||
out vec4 fColor;
|
out vec4 fColor;
|
||||||
layout (binding = 1) uniform sampler2D screenTexture;
|
layout (binding = 1) uniform sampler2D screenTexture;
|
||||||
layout (location = 0) uniform int n;
|
layout (location = 0) uniform int n;
|
||||||
@@ -34,8 +35,8 @@ void main()
|
|||||||
tposb += x * pinchb[i];
|
tposb += x * pinchb[i];
|
||||||
}
|
}
|
||||||
fColor.r = texture(screenTexture, tposr).r;
|
fColor.r = texture(screenTexture, tposr).r;
|
||||||
fColor.b = texture(screenTexture, tposb).b;
|
|
||||||
fColor.g = texture(screenTexture, tposg).g;
|
fColor.g = texture(screenTexture, tposg).g;
|
||||||
|
fColor.b = texture(screenTexture, tposb).b;
|
||||||
}
|
}
|
||||||
// fColor = vec4
|
// fColor = vec4
|
||||||
// ( toRGB(vec3( toYUV(texture(screenTexture, texPos).rgb).r
|
// ( toRGB(vec3( toYUV(texture(screenTexture, texPos).rgb).r
|
||||||
|
|||||||
+56
-51
@@ -7,11 +7,17 @@ struct DataS { vec2 pos; vec2 v1; vec2 v2;
|
|||||||
layout (std430, binding = 9) readonly buffer Data { DataS data[]; };
|
layout (std430, binding = 9) readonly buffer Data { DataS data[]; };
|
||||||
layout (std140, binding = 0) uniform TheMat { mat4 theMat; } ;
|
layout (std140, binding = 0) uniform TheMat { mat4 theMat; } ;
|
||||||
layout (location = 0) uniform int n;
|
layout (location = 0) uniform int n;
|
||||||
|
// setting n1 > 15 does not work on my current hardware
|
||||||
|
// on other hardware n = 15 might not work
|
||||||
|
// e.g. if GL_MAX_VERTEX_OUTPUT_COMPONENTS < 128
|
||||||
|
// note the vec2s might be treated as vec4s
|
||||||
|
// note also the limit on GL_MAX_VARYING_COMPONENTS
|
||||||
|
const int n1 = 15;
|
||||||
out vec2 texPos;
|
out vec2 texPos;
|
||||||
out vec2 distmask[10];
|
out vec2 distmask[n1];
|
||||||
out vec2 pinchr[10];
|
out vec2 pinchr[n1];
|
||||||
out vec2 pinchg[10];
|
out vec2 pinchg[n1];
|
||||||
out vec2 pinchb[10];
|
out vec2 pinchb[n1];
|
||||||
const int ks[6] =
|
const int ks[6] =
|
||||||
{0,1,2 // 2--3
|
{0,1,2 // 2--3
|
||||||
,2,1,3 // | |
|
,2,1,3 // | |
|
||||||
@@ -24,9 +30,8 @@ const vec2 cs[4] =
|
|||||||
};
|
};
|
||||||
vec2 f (vec2 p) // transforms a vector from "world" into "screen" space
|
vec2 f (vec2 p) // transforms a vector from "world" into "screen" space
|
||||||
{ return (theMat * vec4(p,0,1) - theMat * vec4(0,0,0,1)).xy; }
|
{ return (theMat * vec4(p,0,1) - theMat * vec4(0,0,0,1)).xy; }
|
||||||
vec2 g (vec2 p)
|
|
||||||
{ return normalize(p); }
|
|
||||||
vec2 ncToTex (vec2 p) {return 0.5 * (p + 1);}
|
vec2 ncToTex (vec2 p) {return 0.5 * (p + 1);}
|
||||||
|
// don't need mat4 here, could get away with mat3...
|
||||||
mat4 toTransMat (vec2 p)
|
mat4 toTransMat (vec2 p)
|
||||||
{ return mat4
|
{ return mat4
|
||||||
( 1, 0, 0 ,0
|
( 1, 0, 0 ,0
|
||||||
@@ -40,51 +45,51 @@ void main()
|
|||||||
int k = ks[gl_VertexID];
|
int k = ks[gl_VertexID];
|
||||||
for(int i = 0; i < n; ++i)
|
for(int i = 0; i < n; ++i)
|
||||||
{
|
{
|
||||||
vec4 off = theMat * vec4(data[i + gl_VertexID/6].pos, 0,1);
|
DataS thedata = data[i + gl_VertexID/6];
|
||||||
DataS thedata = data[i + gl_VertexID/6];
|
vec4 off = theMat * vec4(thedata.pos, 0,1);
|
||||||
vec2 r1 = f(thedata.v1);
|
vec2 r1 = f(thedata.v1);
|
||||||
vec2 r2 = f(thedata.v2);
|
vec2 r2 = f(thedata.v2);
|
||||||
mat2 distT = inverse (mat2(r1,r2));
|
mat2 distT = inverse (mat2(r1,r2));
|
||||||
distmask[i] = (distT * (cs[k] - off.xy));
|
distmask[i] = (distT * (cs[k] - off.xy));
|
||||||
vec4 pinchxr = theMat
|
vec4 pinchxr = theMat
|
||||||
* toTransMat(thedata.t3r)
|
* toTransMat(thedata.t3r)
|
||||||
* toTransMat(thedata.pos)
|
* toTransMat(thedata.pos)
|
||||||
* mat4
|
* mat4
|
||||||
(thedata.t1r , 0, 0
|
(thedata.t1r , 0, 0
|
||||||
,thedata.t2r , 0, 0
|
,thedata.t2r , 0, 0
|
||||||
, 0, 0 , 0, 0
|
, 0, 0 , 0, 0
|
||||||
, 0, 0 , 0, 1
|
, 0, 0 , 0, 1
|
||||||
)
|
)
|
||||||
* inverse(toTransMat(thedata.pos))
|
* inverse(toTransMat(thedata.pos))
|
||||||
* inverse(theMat)
|
* inverse(theMat)
|
||||||
* (vec4(cs[k],0,1));
|
* (vec4(cs[k],0,1));
|
||||||
pinchr[i] = ncToTex(pinchxr.xy) - ncToTex(cs[k]);
|
pinchr[i] = ncToTex(pinchxr.xy) - ncToTex(cs[k]);
|
||||||
vec4 pinchxg = theMat
|
vec4 pinchxg = theMat
|
||||||
* toTransMat(thedata.t3g)
|
* toTransMat(thedata.t3g)
|
||||||
* toTransMat(thedata.pos)
|
* toTransMat(thedata.pos)
|
||||||
* mat4
|
* mat4
|
||||||
(thedata.t1g , 0, 0
|
(thedata.t1g , 0, 0
|
||||||
,thedata.t2g , 0, 0
|
,thedata.t2g , 0, 0
|
||||||
, 0, 0 , 0, 0
|
, 0, 0 , 0, 0
|
||||||
, 0, 0 , 0, 1
|
, 0, 0 , 0, 1
|
||||||
)
|
)
|
||||||
* inverse(toTransMat(thedata.pos))
|
* inverse(toTransMat(thedata.pos))
|
||||||
* inverse(theMat)
|
* inverse(theMat)
|
||||||
* (vec4(cs[k],0,1));
|
* (vec4(cs[k],0,1));
|
||||||
pinchg[i] = ncToTex(pinchxg.xy) - ncToTex(cs[k]);
|
pinchg[i] = ncToTex(pinchxg.xy) - ncToTex(cs[k]);
|
||||||
vec4 pinchxb = theMat
|
vec4 pinchxb = theMat
|
||||||
* toTransMat(thedata.t3b)
|
* toTransMat(thedata.t3b)
|
||||||
* toTransMat(thedata.pos)
|
* toTransMat(thedata.pos)
|
||||||
* mat4
|
* mat4
|
||||||
(thedata.t1b , 0, 0
|
(thedata.t1b , 0, 0
|
||||||
,thedata.t2b , 0, 0
|
,thedata.t2b , 0, 0
|
||||||
, 0, 0 , 0, 0
|
, 0, 0 , 0, 0
|
||||||
, 0, 0 , 0, 1
|
, 0, 0 , 0, 1
|
||||||
)
|
)
|
||||||
* inverse(toTransMat(thedata.pos))
|
* inverse(toTransMat(thedata.pos))
|
||||||
* inverse(theMat)
|
* inverse(theMat)
|
||||||
* (vec4(cs[k],0,1));
|
* (vec4(cs[k],0,1));
|
||||||
pinchb[i] = ncToTex(pinchxb.xy) - ncToTex(cs[k]);
|
pinchb[i] = ncToTex(pinchxb.xy) - ncToTex(cs[k]);
|
||||||
}
|
}
|
||||||
texPos = ncToTex(cs[k]);
|
texPos = ncToTex(cs[k]);
|
||||||
gl_Position = vec4 (cs[k],0,1);
|
gl_Position = vec4 (cs[k],0,1);
|
||||||
|
|||||||
+11
-1
@@ -154,7 +154,17 @@ makeFlak bu _ w = w & cWorld . lWorld . bullets .++~ [f x | x <- xs]
|
|||||||
g x v = v +.+ x *.* normalizeV (vNormal v)
|
g x v = v +.+ x *.* normalizeV (vNormal v)
|
||||||
|
|
||||||
hitEffFromBul :: World -> Bullet -> (World, Bullet)
|
hitEffFromBul :: World -> Bullet -> (World, Bullet)
|
||||||
hitEffFromBul w bu = case _buEffect bu of
|
hitEffFromBul w bu = hitEffFromBul' w' bu
|
||||||
|
where
|
||||||
|
w' = w & cWorld . lWorld . distortions .:~ x
|
||||||
|
x = RadialDistortion (_buPos bu + _buVel bu) (V2 50 0) (V2 0 50)
|
||||||
|
(v3 & _3 .~ t) (v3 & _3 .~ negate t) v3 1
|
||||||
|
v3 = V3 (V2 1 0) (V2 0 1) 0
|
||||||
|
t = vNormal (_buVel bu)
|
||||||
|
-- (V2 1 0) (V2
|
||||||
|
|
||||||
|
hitEffFromBul' :: World -> Bullet -> (World, Bullet)
|
||||||
|
hitEffFromBul' w bu = case _buEffect bu of
|
||||||
PenetrateBullet -> movePenBullet bu hitstream w
|
PenetrateBullet -> movePenBullet bu hitstream w
|
||||||
BounceBullet -> fromMaybe (expireAndDamage bu hitstream w) $ do
|
BounceBullet -> fromMaybe (expireAndDamage bu hitstream w) $ do
|
||||||
(hp, crwl) <- hitstream ^? _head
|
(hp, crwl) <- hitstream ^? _head
|
||||||
|
|||||||
@@ -12,15 +12,18 @@ data Distortion = RadialDistortion
|
|||||||
{ _rdPos :: Point2
|
{ _rdPos :: Point2
|
||||||
, _rdDist1 :: Point2
|
, _rdDist1 :: Point2
|
||||||
, _rdDist2 :: Point2
|
, _rdDist2 :: Point2
|
||||||
, _rdT1R :: Point2
|
, _rdTR :: V3 Point2
|
||||||
, _rdT2R :: Point2
|
, _rdTB :: V3 Point2
|
||||||
, _rdT3R :: Point2
|
, _rdTG :: V3 Point2
|
||||||
, _rdT1G :: Point2
|
-- , _rdT1R :: Point2
|
||||||
, _rdT2G :: Point2
|
-- , _rdT2R :: Point2
|
||||||
, _rdT3G :: Point2
|
-- , _rdT3R :: Point2
|
||||||
, _rdT1B :: Point2
|
-- , _rdT1G :: Point2
|
||||||
, _rdT2B :: Point2
|
-- , _rdT2G :: Point2
|
||||||
, _rdT3B :: Point2
|
-- , _rdT3G :: Point2
|
||||||
|
-- , _rdT1B :: Point2
|
||||||
|
-- , _rdT2B :: Point2
|
||||||
|
-- , _rdT3B :: Point2
|
||||||
, _rdTime :: Int
|
, _rdTime :: Int
|
||||||
}
|
}
|
||||||
deriving (Eq, Ord, Show, Read) --Generic, Flat)
|
deriving (Eq, Ord, Show, Read) --Generic, Flat)
|
||||||
|
|||||||
@@ -7,5 +7,5 @@ import Control.Lens
|
|||||||
|
|
||||||
updateDistortion :: Distortion -> Maybe Distortion
|
updateDistortion :: Distortion -> Maybe Distortion
|
||||||
updateDistortion rd
|
updateDistortion rd
|
||||||
| rd ^. rdTime > 0 = Just $ rd & rdTime .~ 1
|
| rd ^. rdTime > 0 = Just $ rd & rdTime -~ 1
|
||||||
| otherwise = Nothing
|
| otherwise = Nothing
|
||||||
|
|||||||
@@ -14,14 +14,15 @@ testEvent w = fromMaybe w $ do
|
|||||||
t1 = (V2 1 (-1))
|
t1 = (V2 1 (-1))
|
||||||
t2 = (V2 1 1)
|
t2 = (V2 1 1)
|
||||||
t3 = (V2 distR 0)
|
t3 = (V2 distR 0)
|
||||||
|
v3 = V3 t1 t2 t3
|
||||||
distortionBulge =
|
distortionBulge =
|
||||||
RadialDistortion
|
RadialDistortion
|
||||||
cpos
|
cpos
|
||||||
(V2 distR 0)
|
(V2 distR 0)
|
||||||
(V2 0 distR)
|
(V2 0 distR)
|
||||||
t1 t2 t3 t1 t2 t3 t1 t2 t3
|
v3 v3 v3
|
||||||
20
|
20
|
||||||
return $ w & cWorld . lWorld . distortions .~ [distortionBulge
|
return $ w & cWorld . lWorld . distortions .~ [distortionBulge
|
||||||
, distortionBulge & rdPos +~ 50 & rdT1R +~ V2 (-1) 1
|
, distortionBulge & rdPos +~ 50 & rdTR . _1 +~ V2 (-1) 1
|
||||||
, distortionBulge & rdPos +~ (-50)
|
, distortionBulge & rdPos +~ (-50)
|
||||||
]
|
]
|
||||||
|
|||||||
+4
-3
@@ -359,7 +359,6 @@ doDrawing' win pdata u = do
|
|||||||
glDepthFunc GL_ALWAYS
|
glDepthFunc GL_ALWAYS
|
||||||
glBlendFunc GL_ONE GL_ZERO
|
glBlendFunc GL_ONE GL_ZERO
|
||||||
-- perform distortions
|
-- perform distortions
|
||||||
-- this is hideous
|
|
||||||
case getDistortions cfig w of
|
case getDistortions cfig w of
|
||||||
[] -> do
|
[] -> do
|
||||||
glBindTextureUnit 0 $ pdata ^. fboBase . _2 . _1 . unTO
|
glBindTextureUnit 0 $ pdata ^. fboBase . _2 . _1 . unTO
|
||||||
@@ -371,7 +370,7 @@ doDrawing' win pdata u = do
|
|||||||
glBindFramebuffer GL_FRAMEBUFFER (pdata ^. fbo2 . _1 . unFBO)
|
glBindFramebuffer GL_FRAMEBUFFER (pdata ^. fbo2 . _1 . unFBO)
|
||||||
withArray (concatMap rdToVec2s rs) $
|
withArray (concatMap rdToVec2s rs) $
|
||||||
glNamedBufferSubData (pdata ^. barrelShader . _2 . vboName) 0
|
glNamedBufferSubData (pdata ^. barrelShader . _2 . vboName) 0
|
||||||
(18 * fromIntegral (length rs * sizeOf (0 :: Float)))
|
(24 * fromIntegral (length rs * sizeOf (0 :: Float)))
|
||||||
glBindTextureUnit 1 $ pdata ^. fboBase . _2 . _1 . unTO
|
glBindTextureUnit 1 $ pdata ^. fboBase . _2 . _1 . unTO
|
||||||
glUseProgram (pdata ^. barrelShader . _1)
|
glUseProgram (pdata ^. barrelShader . _1)
|
||||||
glUniform1i 0 (fromIntegral (length rs))
|
glUniform1i 0 (fromIntegral (length rs))
|
||||||
@@ -399,7 +398,9 @@ doDrawing' win pdata u = do
|
|||||||
SDL.glSwapWindow win
|
SDL.glSwapWindow win
|
||||||
|
|
||||||
rdToVec2s :: Distortion -> [Point2]
|
rdToVec2s :: Distortion -> [Point2]
|
||||||
rdToVec2s (RadialDistortion a b c d e f g h i j k l _) = [a,b,c,d,e,f,g,h,i,j,k,l]
|
rdToVec2s (RadialDistortion a b c d e f _) = [a,b,c] <> t d <> t e <> t f
|
||||||
|
where
|
||||||
|
t (V3 x y z) = [x,y,z]
|
||||||
|
|
||||||
bufferPerspectiveMatrixUBO :: Config -> Camera -> GLuint -> IO ()
|
bufferPerspectiveMatrixUBO :: Config -> Camera -> GLuint -> IO ()
|
||||||
bufferPerspectiveMatrixUBO cfig cam uboid =
|
bufferPerspectiveMatrixUBO cfig cam uboid =
|
||||||
|
|||||||
Reference in New Issue
Block a user