Allow for multiple distortions at once
This commit is contained in:
+10
-14
@@ -1,12 +1,11 @@
|
|||||||
#version 450 core
|
#version 450 core
|
||||||
in vec2 texPos;
|
in vec2 texPos;
|
||||||
in vec2 distmask;
|
in vec2 distmask[2];
|
||||||
in vec2 pinch;
|
in vec2 pinch[2];
|
||||||
out vec4 fColor;
|
out vec4 fColor;
|
||||||
layout (binding = 1) uniform sampler2D screenTexture;
|
layout (binding = 1) uniform sampler2D screenTexture;
|
||||||
float x = 1 - min(1, sqrt(distance(distmask,vec2(0,0))));
|
float x = 1 - min(1, sqrt(distance(distmask[0],vec2(0,0))));
|
||||||
float xab = abs(distmask.x);
|
//float x = 1 - min(1, dot(distmask,distmask));
|
||||||
float yab = abs(distmask.y);
|
|
||||||
vec3 toYUV (vec3 rgb)
|
vec3 toYUV (vec3 rgb)
|
||||||
{ return rgb * mat3
|
{ return rgb * mat3
|
||||||
( 0.299 , 0.587 , 0.114
|
( 0.299 , 0.587 , 0.114
|
||||||
@@ -23,14 +22,12 @@ vec3 toRGB (vec3 yuv)
|
|||||||
}
|
}
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
fColor = texture(screenTexture, (texPos + x * pinch));
|
float y = 1 - min(1, sqrt(distance(distmask[1],vec2(0,0))));
|
||||||
//fColor = texture(screenTexture, (texPos + x*pinch));
|
fColor = texture(screenTexture
|
||||||
//fColor = texture(screenTexture, (texPos + x*pinch));
|
, (texPos + x * pinch[0]
|
||||||
// fColor = vec4
|
+ y * pinch[1]
|
||||||
// ( texture(screenTexture, (texPos + x*pinch)).r
|
));
|
||||||
// , texture(screenTexture, (texPos + x*(-pinch))).g
|
}
|
||||||
// , texture(screenTexture, texPos).ba
|
|
||||||
// ) ;
|
|
||||||
// fColor = vec4
|
// fColor = vec4
|
||||||
// ( toRGB(vec3( toYUV(texture(screenTexture, texPos).rgb).r
|
// ( toRGB(vec3( toYUV(texture(screenTexture, texPos).rgb).r
|
||||||
// , toYUV(texture(screenTexture, (texPos + x*pinch)).rgb).g
|
// , toYUV(texture(screenTexture, (texPos + x*pinch)).rgb).g
|
||||||
@@ -38,4 +35,3 @@ void main()
|
|||||||
// ) )
|
// ) )
|
||||||
// , 1
|
// , 1
|
||||||
// ) ;
|
// ) ;
|
||||||
}
|
|
||||||
|
|||||||
@@ -3,8 +3,8 @@ struct DataS { vec2 pos; vec2 v1; vec2 v2; vec2 t1; vec2 t2; vec2 t3; };
|
|||||||
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; } ;
|
||||||
out vec2 texPos;
|
out vec2 texPos;
|
||||||
out vec2 distmask;
|
out vec2 distmask[2];
|
||||||
out vec2 pinch;
|
out vec2 pinch[2];
|
||||||
const int ks[6] =
|
const int ks[6] =
|
||||||
{0,1,2 // 2--3
|
{0,1,2 // 2--3
|
||||||
,2,1,3 // | |
|
,2,1,3 // | |
|
||||||
@@ -31,12 +31,14 @@ mat4 toTransMat (vec2 p)
|
|||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
int k = ks[gl_VertexID];
|
int k = ks[gl_VertexID];
|
||||||
DataS thedata = data[gl_VertexID/6];
|
for(int i = 0; i < 2; ++i)
|
||||||
vec4 off = theMat * vec4(data[gl_VertexID/6].pos, 0,1);
|
{
|
||||||
|
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 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 = distT * (cs[k] - off.xy);
|
distmask[i] = (distT * (cs[k] - off.xy));
|
||||||
vec4 pinchx = theMat
|
vec4 pinchx = theMat
|
||||||
* toTransMat(thedata.t3)
|
* toTransMat(thedata.t3)
|
||||||
* toTransMat(thedata.pos)
|
* toTransMat(thedata.pos)
|
||||||
@@ -49,7 +51,8 @@ void main()
|
|||||||
* inverse(toTransMat(thedata.pos))
|
* inverse(toTransMat(thedata.pos))
|
||||||
* inverse(theMat)
|
* inverse(theMat)
|
||||||
* (vec4(cs[k],0,1));
|
* (vec4(cs[k],0,1));
|
||||||
pinch = ncToTex(pinchx.xy) - ncToTex(cs[k]);
|
pinch[i] = ncToTex(pinchx.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);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,14 +3,21 @@
|
|||||||
|
|
||||||
module Dodge.Data.Distortion where
|
module Dodge.Data.Distortion where
|
||||||
|
|
||||||
|
import Control.Lens
|
||||||
import Geometry
|
import Geometry
|
||||||
import Data.Aeson
|
import Data.Aeson
|
||||||
import Data.Aeson.TH
|
import Data.Aeson.TH
|
||||||
|
|
||||||
data Distortion = RadialDistortion
|
data Distortion = RadialDistortion
|
||||||
Point2 Point2 Point2
|
{ _rdPos :: Point2
|
||||||
Point2 Point2 Point2
|
, _rdDist1 :: Point2
|
||||||
Int
|
, _rdDist2 :: Point2
|
||||||
|
, _rdT1 :: Point2
|
||||||
|
, _rdT2 :: Point2
|
||||||
|
, _rdT3 :: Point2
|
||||||
|
, _rdTime :: Int
|
||||||
|
}
|
||||||
deriving (Eq, Ord, Show, Read) --Generic, Flat)
|
deriving (Eq, Ord, Show, Read) --Generic, Flat)
|
||||||
|
|
||||||
|
makeLenses ''Distortion
|
||||||
deriveJSON defaultOptions ''Distortion
|
deriveJSON defaultOptions ''Distortion
|
||||||
|
|||||||
@@ -16,8 +16,10 @@ testEvent w = fromMaybe w $ do
|
|||||||
cpos
|
cpos
|
||||||
(V2 distR 0)
|
(V2 distR 0)
|
||||||
(V2 0 distR)
|
(V2 0 distR)
|
||||||
(V2 2 0)
|
(V2 1 (-1))
|
||||||
(V2 0 0.5)
|
(V2 1 1)
|
||||||
(V2 0 0)
|
(V2 distR 0)
|
||||||
20
|
20
|
||||||
return $ w & cWorld . lWorld . distortions .~ [distortionBulge]
|
return $ w & cWorld . lWorld . distortions .~ [distortionBulge
|
||||||
|
, distortionBulge & rdPos +~ 50
|
||||||
|
]
|
||||||
|
|||||||
+6
-4
@@ -367,12 +367,11 @@ doDrawing' win pdata u = do
|
|||||||
glUseProgram (pdata ^. fullscreenShader)
|
glUseProgram (pdata ^. fullscreenShader)
|
||||||
glDrawArrays GL_TRIANGLES 0 6
|
glDrawArrays GL_TRIANGLES 0 6
|
||||||
--(RadialDistortion (V2 a b) (V2 c d) (V2 e f) (V2 g h) _:_) -> do
|
--(RadialDistortion (V2 a b) (V2 c d) (V2 e f) (V2 g h) _:_) -> do
|
||||||
(RadialDistortion a b c d e f _:_) -> do
|
rs -> do
|
||||||
glBindFramebuffer GL_FRAMEBUFFER (pdata ^. fbo2 . _1 . unFBO)
|
glBindFramebuffer GL_FRAMEBUFFER (pdata ^. fbo2 . _1 . unFBO)
|
||||||
-- pokeArray (pdata ^. barrelShader . _2 . vboPtr) [a, b, c, d, e, f, g, h]
|
withArray (concatMap rdToVec2s rs) $
|
||||||
withArray [a, b, c, d, e, f] $
|
|
||||||
glNamedBufferSubData (pdata ^. barrelShader . _2 . vboName) 0
|
glNamedBufferSubData (pdata ^. barrelShader . _2 . vboName) 0
|
||||||
(12 * fromIntegral (sizeOf (0 :: Float)))
|
(12 * 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)
|
||||||
glDrawArrays GL_TRIANGLES 0 6
|
glDrawArrays GL_TRIANGLES 0 6
|
||||||
@@ -398,6 +397,9 @@ doDrawing' win pdata u = do
|
|||||||
renderLayer FixedCoordLayer shadV pokeCounts
|
renderLayer FixedCoordLayer shadV pokeCounts
|
||||||
SDL.glSwapWindow win
|
SDL.glSwapWindow win
|
||||||
|
|
||||||
|
rdToVec2s :: Distortion -> [Point2]
|
||||||
|
rdToVec2s (RadialDistortion a b c d e f _) = [a,b,c,d,e,f]
|
||||||
|
|
||||||
bufferPerspectiveMatrixUBO :: Config -> Camera -> GLuint -> IO ()
|
bufferPerspectiveMatrixUBO :: Config -> Camera -> GLuint -> IO ()
|
||||||
bufferPerspectiveMatrixUBO cfig cam uboid =
|
bufferPerspectiveMatrixUBO cfig cam uboid =
|
||||||
withArray
|
withArray
|
||||||
|
|||||||
Reference in New Issue
Block a user