Clarify number of distortions, play with distorting bullets

This commit is contained in:
2025-11-19 21:49:20 +00:00
parent 610936a5fa
commit 10dbb238c8
7 changed files with 93 additions and 72 deletions
+6 -5
View File
@@ -1,9 +1,10 @@
#version 450 core
in vec2 texPos;
in vec2 distmask[10];
in vec2 pinchr[10];
in vec2 pinchg[10];
in vec2 pinchb[10];
const int n1 = 15;
in vec2 distmask[n1];
in vec2 pinchr[n1];
in vec2 pinchg[n1];
in vec2 pinchb[n1];
out vec4 fColor;
layout (binding = 1) uniform sampler2D screenTexture;
layout (location = 0) uniform int n;
@@ -34,8 +35,8 @@ void main()
tposb += x * pinchb[i];
}
fColor.r = texture(screenTexture, tposr).r;
fColor.b = texture(screenTexture, tposb).b;
fColor.g = texture(screenTexture, tposg).g;
fColor.b = texture(screenTexture, tposb).b;
}
// fColor = vec4
// ( toRGB(vec3( toYUV(texture(screenTexture, texPos).rgb).r
+56 -51
View File
@@ -7,11 +7,17 @@ struct DataS { vec2 pos; vec2 v1; vec2 v2;
layout (std430, binding = 9) readonly buffer Data { DataS data[]; };
layout (std140, binding = 0) uniform TheMat { mat4 theMat; } ;
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 distmask[10];
out vec2 pinchr[10];
out vec2 pinchg[10];
out vec2 pinchb[10];
out vec2 distmask[n1];
out vec2 pinchr[n1];
out vec2 pinchg[n1];
out vec2 pinchb[n1];
const int ks[6] =
{0,1,2 // 2--3
,2,1,3 // | |
@@ -24,9 +30,8 @@ const vec2 cs[4] =
};
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; }
vec2 g (vec2 p)
{ return normalize(p); }
vec2 ncToTex (vec2 p) {return 0.5 * (p + 1);}
// don't need mat4 here, could get away with mat3...
mat4 toTransMat (vec2 p)
{ return mat4
( 1, 0, 0 ,0
@@ -40,51 +45,51 @@ void main()
int k = ks[gl_VertexID];
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];
vec2 r1 = f(thedata.v1);
vec2 r2 = f(thedata.v2);
mat2 distT = inverse (mat2(r1,r2));
distmask[i] = (distT * (cs[k] - off.xy));
vec4 pinchxr = theMat
* toTransMat(thedata.t3r)
* toTransMat(thedata.pos)
* mat4
(thedata.t1r , 0, 0
,thedata.t2r , 0, 0
, 0, 0 , 0, 0
, 0, 0 , 0, 1
)
* inverse(toTransMat(thedata.pos))
* inverse(theMat)
* (vec4(cs[k],0,1));
pinchr[i] = ncToTex(pinchxr.xy) - ncToTex(cs[k]);
vec4 pinchxg = theMat
* toTransMat(thedata.t3g)
* toTransMat(thedata.pos)
* mat4
(thedata.t1g , 0, 0
,thedata.t2g , 0, 0
, 0, 0 , 0, 0
, 0, 0 , 0, 1
)
* inverse(toTransMat(thedata.pos))
* inverse(theMat)
* (vec4(cs[k],0,1));
pinchg[i] = ncToTex(pinchxg.xy) - ncToTex(cs[k]);
vec4 pinchxb = theMat
* toTransMat(thedata.t3b)
* toTransMat(thedata.pos)
* mat4
(thedata.t1b , 0, 0
,thedata.t2b , 0, 0
, 0, 0 , 0, 0
, 0, 0 , 0, 1
)
* inverse(toTransMat(thedata.pos))
* inverse(theMat)
* (vec4(cs[k],0,1));
pinchb[i] = ncToTex(pinchxb.xy) - ncToTex(cs[k]);
DataS thedata = data[i + gl_VertexID/6];
vec4 off = theMat * vec4(thedata.pos, 0,1);
vec2 r1 = f(thedata.v1);
vec2 r2 = f(thedata.v2);
mat2 distT = inverse (mat2(r1,r2));
distmask[i] = (distT * (cs[k] - off.xy));
vec4 pinchxr = theMat
* toTransMat(thedata.t3r)
* toTransMat(thedata.pos)
* mat4
(thedata.t1r , 0, 0
,thedata.t2r , 0, 0
, 0, 0 , 0, 0
, 0, 0 , 0, 1
)
* inverse(toTransMat(thedata.pos))
* inverse(theMat)
* (vec4(cs[k],0,1));
pinchr[i] = ncToTex(pinchxr.xy) - ncToTex(cs[k]);
vec4 pinchxg = theMat
* toTransMat(thedata.t3g)
* toTransMat(thedata.pos)
* mat4
(thedata.t1g , 0, 0
,thedata.t2g , 0, 0
, 0, 0 , 0, 0
, 0, 0 , 0, 1
)
* inverse(toTransMat(thedata.pos))
* inverse(theMat)
* (vec4(cs[k],0,1));
pinchg[i] = ncToTex(pinchxg.xy) - ncToTex(cs[k]);
vec4 pinchxb = theMat
* toTransMat(thedata.t3b)
* toTransMat(thedata.pos)
* mat4
(thedata.t1b , 0, 0
,thedata.t2b , 0, 0
, 0, 0 , 0, 0
, 0, 0 , 0, 1
)
* inverse(toTransMat(thedata.pos))
* inverse(theMat)
* (vec4(cs[k],0,1));
pinchb[i] = ncToTex(pinchxb.xy) - ncToTex(cs[k]);
}
texPos = ncToTex(cs[k]);
gl_Position = vec4 (cs[k],0,1);
+11 -1
View File
@@ -154,7 +154,17 @@ makeFlak bu _ w = w & cWorld . lWorld . bullets .++~ [f x | x <- xs]
g x v = v +.+ x *.* normalizeV (vNormal v)
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
BounceBullet -> fromMaybe (expireAndDamage bu hitstream w) $ do
(hp, crwl) <- hitstream ^? _head
+12 -9
View File
@@ -12,15 +12,18 @@ data Distortion = RadialDistortion
{ _rdPos :: Point2
, _rdDist1 :: Point2
, _rdDist2 :: Point2
, _rdT1R :: Point2
, _rdT2R :: Point2
, _rdT3R :: Point2
, _rdT1G :: Point2
, _rdT2G :: Point2
, _rdT3G :: Point2
, _rdT1B :: Point2
, _rdT2B :: Point2
, _rdT3B :: Point2
, _rdTR :: V3 Point2
, _rdTB :: V3 Point2
, _rdTG :: V3 Point2
-- , _rdT1R :: Point2
-- , _rdT2R :: Point2
-- , _rdT3R :: Point2
-- , _rdT1G :: Point2
-- , _rdT2G :: Point2
-- , _rdT3G :: Point2
-- , _rdT1B :: Point2
-- , _rdT2B :: Point2
-- , _rdT3B :: Point2
, _rdTime :: Int
}
deriving (Eq, Ord, Show, Read) --Generic, Flat)
+1 -1
View File
@@ -7,5 +7,5 @@ import Control.Lens
updateDistortion :: Distortion -> Maybe Distortion
updateDistortion rd
| rd ^. rdTime > 0 = Just $ rd & rdTime .~ 1
| rd ^. rdTime > 0 = Just $ rd & rdTime -~ 1
| otherwise = Nothing
+3 -2
View File
@@ -14,14 +14,15 @@ testEvent w = fromMaybe w $ do
t1 = (V2 1 (-1))
t2 = (V2 1 1)
t3 = (V2 distR 0)
v3 = V3 t1 t2 t3
distortionBulge =
RadialDistortion
cpos
(V2 distR 0)
(V2 0 distR)
t1 t2 t3 t1 t2 t3 t1 t2 t3
v3 v3 v3
20
return $ w & cWorld . lWorld . distortions .~ [distortionBulge
, distortionBulge & rdPos +~ 50 & rdT1R +~ V2 (-1) 1
, distortionBulge & rdPos +~ 50 & rdTR . _1 +~ V2 (-1) 1
, distortionBulge & rdPos +~ (-50)
]
+4 -3
View File
@@ -359,7 +359,6 @@ doDrawing' win pdata u = do
glDepthFunc GL_ALWAYS
glBlendFunc GL_ONE GL_ZERO
-- perform distortions
-- this is hideous
case getDistortions cfig w of
[] -> do
glBindTextureUnit 0 $ pdata ^. fboBase . _2 . _1 . unTO
@@ -371,7 +370,7 @@ doDrawing' win pdata u = do
glBindFramebuffer GL_FRAMEBUFFER (pdata ^. fbo2 . _1 . unFBO)
withArray (concatMap rdToVec2s rs) $
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
glUseProgram (pdata ^. barrelShader . _1)
glUniform1i 0 (fromIntegral (length rs))
@@ -399,7 +398,9 @@ doDrawing' win pdata u = do
SDL.glSwapWindow win
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 cfig cam uboid =