Work on distortions

This commit is contained in:
2025-11-18 10:55:46 +00:00
parent 1205823ddb
commit 8428f08ebd
6 changed files with 86 additions and 47 deletions
+30 -12
View File
@@ -4,20 +4,38 @@ in vec2 distmask;
in vec2 pinch;
out vec4 fColor;
layout (binding = 1) uniform sampler2D screenTexture;
float x = 1 - min(1, dot(distmask,distmask));
float x = 1 - min(1, sqrt(distance(distmask,vec2(0,0))));
float xab = abs(distmask.x);
float yab = abs(distmask.y);
vec3 toYUV (vec3 rgb)
{ return rgb * mat3
( 0.299 , 0.587 , 0.114
,-0.14713,-0.28886, 0.436
, 0.615 ,-0.51499,-0.10001
) ;
}
vec3 toRGB (vec3 yuv)
{ return yuv * mat3
(1, 0 , 1.13983
,1,-0.39465,-0.58060
,1, 2.03211, 0
) ;
}
void main()
{
fColor = (xab < 1 && yab < 1
//? vec4 (0.5*(distmask.x+1),0.5*(distmask.y+1),0,1)
? vec4 (0.5*(distmask.x+1),0.5*(distmask.y+1),0,1)
: texture(screenTexture, texPos));
//fColor = texture(screenTexture, (texPos + x*x*pinch));
//fColor = vec4
// ( texture(screenTexture, (texPos + x*x*pinch)).r
// , texture(screenTexture, (texPos - x*x*pinch)).g
// , texture(screenTexture, (texPos - x*x*(pinch.yx))).b
// , texture(screenTexture, texPos).a
// ) ;
fColor = texture(screenTexture, (texPos + x * pinch));
//fColor = texture(screenTexture, (texPos + x*pinch));
//fColor = texture(screenTexture, (texPos + x*pinch));
// fColor = vec4
// ( texture(screenTexture, (texPos + x*pinch)).r
// , texture(screenTexture, (texPos + x*(-pinch))).g
// , texture(screenTexture, texPos).ba
// ) ;
// fColor = vec4
// ( toRGB(vec3( toYUV(texture(screenTexture, texPos).rgb).r
// , toYUV(texture(screenTexture, (texPos + x*pinch)).rgb).g
// , toYUV(texture(screenTexture, (texPos + x*(pinch))).rgb).b
// ) )
// , 1
// ) ;
}
+32 -23
View File
@@ -1,5 +1,5 @@
#version 450 core
struct DataS { vec2 pos; vec2 v1; vec2 v2; vec2 rad; };
struct DataS { vec2 pos; vec2 v1; vec2 v2; vec2 t1; vec2 t2; vec2 t3; };
layout (std430, binding = 9) readonly buffer Data { DataS data[]; };
layout (std140, binding = 0) uniform TheMat { mat4 theMat; } ;
out vec2 texPos;
@@ -15,32 +15,41 @@ const vec2 cs[4] =
, vec2 (-1, 1)
, vec2 ( 1, 1)
};
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);}
mat4 toTransMat (vec2 p)
{ return mat4
( 1, 0, 0 ,0
, 0, 1, 0 ,0
, 0, 0, 1 ,0
,p.x,p.y, 0 ,1
) ;
}
void main()
{
int k = ks[gl_VertexID];
vec4 off = (theMat * vec4(data[gl_VertexID/6].pos, 0,1));
vec2 r1 = (theMat * vec4(data[gl_VertexID/6].v1, 0,1)).xy
- (theMat * vec4(0,0,0,1)).xy;
vec2 r2 = (theMat * vec4(data[gl_VertexID/6].v2, 0,1)).xy
- (theMat * vec4(0,0, 0,1)).xy;
pinch =
(theMat * vec4(data[gl_VertexID/6].rad, 0,1)).xy
- (theMat * vec4(0,0, 0,1)).xy;
// mat2 distT = mat2(-1/r1.x, -1/r2.x
// ,1/r1.y, -1/r2.y
// );
// mat2 distT = mat2(2, 0
// ,-1/sqrt(2), 1/sqrt(2)
// );
// mat2 distT = mat2(1/r1.x, 2*sqrt(2)
// ,1/r1.y, 2*sqrt(2)
// );
DataS thedata = data[gl_VertexID/6];
vec4 off = theMat * vec4(data[gl_VertexID/6].pos, 0,1);
vec2 r1 = f(thedata.v1);
vec2 r2 = f(thedata.v2);
mat2 distT = inverse (mat2(r1,r2));
// mat2 distT = mat2(1/r1.x, 1/r2.x
// ,1/r1.y, 1/r2.y
// );
//distmask = (cs[k] - off.xy)/r;
distmask = distT * (cs[k] - off.xy);
texPos = 0.5 * (cs[k]+vec2(1,1));
vec4 pinchx = theMat
* toTransMat(thedata.t3)
* toTransMat(thedata.pos)
* mat4
(thedata.t1 , 0, 0
,thedata.t2 , 0, 0
, 0, 0 , 0, 0
, 0, 0 , 0, 1
)
* inverse(toTransMat(thedata.pos))
* inverse(theMat)
* (vec4(cs[k],0,1));
pinch = ncToTex(pinchx.xy) - ncToTex(cs[k]);
texPos = ncToTex(cs[k]);
gl_Position = vec4 (cs[k],0,1);
}