Allow independent distortion of rgb channels

This commit is contained in:
2025-11-19 10:38:30 +00:00
parent 8759431fec
commit 610936a5fa
6 changed files with 72 additions and 31 deletions
+12 -10
View File
@@ -1,12 +1,12 @@
#version 450 core
in vec2 texPos;
in vec2 distmask[10];
in vec2 pinch[10];
in vec2 pinchr[10];
in vec2 pinchg[10];
in vec2 pinchb[10];
out vec4 fColor;
layout (binding = 1) uniform sampler2D screenTexture;
layout (location = 0) uniform int n;
//float x = 1 - min(1, sqrt(distance(distmask[0],vec2(0,0))));
//float x = 1 - min(1, dot(distmask,distmask));
vec3 toYUV (vec3 rgb)
{ return rgb * mat3
( 0.299 , 0.587 , 0.114
@@ -23,17 +23,19 @@ vec3 toRGB (vec3 yuv)
}
void main()
{
vec2 tpos = texPos;
vec2 tposr = texPos;
vec2 tposb = texPos;
vec2 tposg = texPos;
for(int i = 0; i < n; ++i)
{
float x = 1 - min(1, sqrt(distance(distmask[i],vec2(0,0))));
tpos += x * pinch[i];
tposr += x * pinchr[i];
tposg += x * pinchg[i];
tposb += x * pinchb[i];
}
fColor = texture(screenTexture, tpos);
//fColor = texture(screenTexture
// , (texPos + x * pinch[0]
// + y * pinch[1]
// ));
fColor.r = texture(screenTexture, tposr).r;
fColor.b = texture(screenTexture, tposb).b;
fColor.g = texture(screenTexture, tposg).g;
}
// fColor = vec4
// ( toRGB(vec3( toYUV(texture(screenTexture, texPos).rgb).r
+39 -7
View File
@@ -1,11 +1,17 @@
#version 450 core
struct DataS { vec2 pos; vec2 v1; vec2 v2; vec2 t1; vec2 t2; vec2 t3; };
struct DataS { vec2 pos; vec2 v1; vec2 v2;
vec2 t1r; vec2 t2r; vec2 t3r;
vec2 t1g; vec2 t2g; vec2 t3g;
vec2 t1b; vec2 t2b; vec2 t3b;
};
layout (std430, binding = 9) readonly buffer Data { DataS data[]; };
layout (std140, binding = 0) uniform TheMat { mat4 theMat; } ;
layout (location = 0) uniform int n;
out vec2 texPos;
out vec2 distmask[10];
out vec2 pinch[10];
out vec2 pinchr[10];
out vec2 pinchg[10];
out vec2 pinchb[10];
const int ks[6] =
{0,1,2 // 2--3
,2,1,3 // | |
@@ -40,19 +46,45 @@ void main()
vec2 r2 = f(thedata.v2);
mat2 distT = inverse (mat2(r1,r2));
distmask[i] = (distT * (cs[k] - off.xy));
vec4 pinchx = theMat
* toTransMat(thedata.t3)
vec4 pinchxr = theMat
* toTransMat(thedata.t3r)
* toTransMat(thedata.pos)
* mat4
(thedata.t1 , 0, 0
,thedata.t2 , 0, 0
(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));
pinch[i] = ncToTex(pinchx.xy) - ncToTex(cs[k]);
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);
+9 -3
View File
@@ -12,9 +12,15 @@ data Distortion = RadialDistortion
{ _rdPos :: Point2
, _rdDist1 :: Point2
, _rdDist2 :: Point2
, _rdT1 :: Point2
, _rdT2 :: Point2
, _rdT3 :: 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)
+5 -4
View File
@@ -1,10 +1,11 @@
{-# LANGUAGE LambdaCase #-}
module Dodge.Distortion (updateDistortion) where
import Dodge.Data.Distortion
import Control.Lens
updateDistortion :: Distortion -> Maybe Distortion
updateDistortion = \case
RadialDistortion a b c d e f t
| t > 0 -> Just $ RadialDistortion a b c d e f $ t-1
| otherwise -> Nothing
updateDistortion rd
| rd ^. rdTime > 0 = Just $ rd & rdTime .~ 1
| otherwise = Nothing
+5 -4
View File
@@ -11,16 +11,17 @@ testEvent :: World -> World
testEvent w = fromMaybe w $ do
cpos <- w ^? cWorld . lWorld . creatures . ix 0 . crPos . _xy
let distR = 50
t1 = (V2 1 (-1))
t2 = (V2 1 1)
t3 = (V2 distR 0)
distortionBulge =
RadialDistortion
cpos
(V2 distR 0)
(V2 0 distR)
(V2 1 (-1))
(V2 1 1)
(V2 distR 0)
t1 t2 t3 t1 t2 t3 t1 t2 t3
20
return $ w & cWorld . lWorld . distortions .~ [distortionBulge
, distortionBulge & rdPos +~ 50
, distortionBulge & rdPos +~ 50 & rdT1R +~ V2 (-1) 1
, distortionBulge & rdPos +~ (-50)
]
+2 -3
View File
@@ -366,13 +366,12 @@ doDrawing' win pdata u = do
glBindFramebuffer GL_FRAMEBUFFER 0
glUseProgram (pdata ^. fullscreenShader)
glDrawArrays GL_TRIANGLES 0 6
--(RadialDistortion (V2 a b) (V2 c d) (V2 e f) (V2 g h) _:_) -> do
rs' -> do
let rs = take 10 rs'
glBindFramebuffer GL_FRAMEBUFFER (pdata ^. fbo2 . _1 . unFBO)
withArray (concatMap rdToVec2s rs) $
glNamedBufferSubData (pdata ^. barrelShader . _2 . vboName) 0
(12 * fromIntegral (length rs * sizeOf (0 :: Float)))
(18 * fromIntegral (length rs * sizeOf (0 :: Float)))
glBindTextureUnit 1 $ pdata ^. fboBase . _2 . _1 . unTO
glUseProgram (pdata ^. barrelShader . _1)
glUniform1i 0 (fromIntegral (length rs))
@@ -400,7 +399,7 @@ doDrawing' win pdata u = do
SDL.glSwapWindow win
rdToVec2s :: Distortion -> [Point2]
rdToVec2s (RadialDistortion a b c d e f _) = [a,b,c,d,e,f]
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]
bufferPerspectiveMatrixUBO :: Config -> Camera -> GLuint -> IO ()
bufferPerspectiveMatrixUBO cfig cam uboid =