Work on distortion shader

This commit is contained in:
2025-11-15 13:21:11 +00:00
parent 5dfc97a683
commit d436b853eb
8 changed files with 44 additions and 55 deletions
+1 -1
View File
@@ -34,7 +34,7 @@ vec4 shiftNear(vec4 pos)
return (sp.z > 100 ? projNear(pos) : sp);
}
// Output 6 vertices for 4 data inputs
int ks[6] = // Inputdata: n1a Shadow:
const int ks[6] = // Inputdata: n1a Shadow:
{0,1,2 // 2--3 / p2--p3
,2,1,3 // | | p0---p1 / |
}; // 0--1 / / |
+3 -13
View File
@@ -1,20 +1,10 @@
#version 450 core
in vec2 texPos;
in vec2 texDist;
in float gfactor;
in vec2 vcpos;
in vec2 distmask;
out vec4 fColor;
layout (binding = 1) uniform sampler2D screenTexture;
float f ( float x) {
if (x>1) {return 1;} else {return (1-gfactor)*x + gfactor;}
}
float x = min(1, dot(distmask,distmask));
void main()
{
float t = f(length(texDist));
float r = texture(screenTexture , (t*texPos - vcpos)).r ;
vec2 gb = texture(screenTexture
, 0.5+0.5 *( vcpos + t * (texPos - vcpos))
).gb
;
fColor = vec4(r,gb,1);
fColor = mix(texture(screenTexture, texPos),vec4(1,0,0,1),x);
}
+22 -13
View File
@@ -1,18 +1,27 @@
#version 450 core
layout (location = 0) in vec2 pos;
layout (location = 1) in vec2 rad1;
layout (location = 2) in vec2 rad2;
layout (location = 3) in float factor;
struct DataS { vec2 pos; vec2 rad1; vec2 rad2; };
layout (std430, binding = 9) readonly buffer Data { DataS data[]; };
layout (std140, binding = 0) uniform TheMat { mat4 theMat; } ;
out vec2 vCen;
out vec2 vRad1;
out vec2 vRad2;
out float vFactor;
out vec2 texPos;
out vec2 distmask;
const int ks[6] =
{0,1,2 // 2--3
,2,1,3 // | |
}; // 0--1
const vec2 cs[4] =
{ vec2 (-1,-1)
, vec2 ( 1,-1)
, vec2 (-1, 1)
, vec2 ( 1, 1)
};
void main()
{
gl_Position = vec4(0,0,0,1);
vCen = (theMat * vec4(pos,0,1)).xy;
vRad1 = (theMat * vec4(rad1,0,1)).xy;
vRad2 = (theMat * vec4(rad2,0,1)).xy;
vFactor = factor;
int k = ks[gl_VertexID];
vec4 off = (theMat * vec4(data[gl_VertexID/6].pos, 0,1));
float r = distance
((theMat * vec4(data[gl_VertexID/6].rad1, 0,1)).xy
,(theMat * vec4(0,0, 0,1)).xy);
distmask = (cs[k] - off.xy)/r;
texPos = 0.5 * (cs[k]+vec2(1,1));
gl_Position = vec4 (cs[k],0,1);
}