Skip to content

Instantly share code, notes, and snippets.

@Osmiogrzesznik
Created November 9, 2023 19:44
Show Gist options
  • Save Osmiogrzesznik/dc4ee2e84af002d4580643571871d019 to your computer and use it in GitHub Desktop.
Save Osmiogrzesznik/dc4ee2e84af002d4580643571871d019 to your computer and use it in GitHub Desktop.
precision mediump float;
//precision lowp float;
uniform sampler2D tex;
uniform sampler2D tex2;
uniform sampler2D tex3;
uniform float texWidth;
uniform float texHeight;
// uniform float iTime;
uniform vec3 keyColor;
uniform float similarity;
uniform float weird;
uniform float smoothness;
uniform float spill;
const float PHI = 1.61803398874989484820459; // Φ = Golden Ra
float eas(float x){
float u = (sin(-1.57+x*3.14)+1.)/2.;
return u;
}
// From https://github.com/libretro/glsl-shaders/blob/master/nnedi3/shaders/rgb-to-yuv.glsl
vec2 RGBtoUV2(vec3 rgb) {
return vec2(
rgb.r * -0.169 + rgb.g * -0.331 + rgb.b * 0.5 + 0.5,
rgb.r * 0.5 + rgb.g * -0.419 + rgb.b * -0.081 + 0.5
);
}
vec3 RGBtoUV(vec3 rgb) {
return vec3(rgb.r,rgb.g,rgb.b);
}
float GoN(in vec2 xy, in float seed)
{
return sin(fract(tan(distance(xy*PHI, xy)*seed)*xy.x));
}
float ChromaDist (vec2 texCoord){
return distance(RGBtoUV(texture2D(tex2, texCoord).rgb), RGBtoUV(keyColor));
}
float ClPlDist6(vec2 texCoord2){
float gg = 0.0;
vec2 texCoord = texCoord2 + vec2(gg,gg);
float iu = distance(texture2D(tex2, texCoord).rgb, vec3(0,0,0));
return distance(iu,0.5);
}
float ClPlDist2(vec2 texCoord2){
float gg = 0.0;
vec2 texCoord = texCoord2 + vec2(gg,gg);
float iu = distance(texture2D(tex2, texCoord).rgb, vec3(0,0,0));
return distance(iu,0.5);
}
float ClPlDist(vec2 texCoord2){
float gg = 0.0;
vec2 texCoord = texCoord2 + vec2(gg,gg);
float iu = distance(RGBtoUV(texture2D(tex, texCoord).rgb), RGBtoUV(texture2D(tex2, texCoord).rgb));
float sim = pow(eas(similarity),1.);
float ffff = distance(iu,sim);
return distance(ffff,.5)*4.;
}
vec4 ProcessChromaKey(vec2 texCoord) {
vec4 rgba1 = texture2D(tex, texCoord);
vec4 rgba2 = texture2D(tex2, texCoord);
float sim = pow(eas(similarity),2.);
vec4 rgba = mix(rgba1,rgba2,sim);
return rgba;
}
vec2 fract2(vec2 fc,vec2 fc2){
float xx = fc.x;
float yy= fc.y;
float xx2 = fc2.x;
float yy2 = fc2.y;
float x = fract(xx/xx2);
float y = fract(yy/yy2);
return vec2(x,y);
}
float ProcessCoord(float a,float b){
return abs(sin(cos(b*0.001*weird)*(a/texWidth)));
}
vec2 NormCoord2(vec2 fc){
vec2 fc5 = floor(fc/7.);
vec2 fc10 = floor(fc/5.);
vec2 fc15 = floor(fc/51.);
vec4 c4 = texture2D(tex2, vec2(0.5,0.5));
float a5 = GoN(fc5,c4.x);
float a10 = GoN(fc10,c4.y);
float a15 = GoN(fc15,c4.z);
vec2 tc = vec2((fc.x/texWidth),(1.0-fc.y/texHeight));
vec2 tc5 = vec2((fc5.x/texWidth),(1.0-fc5.y/texHeight));
vec2 tc10 = vec2((fc10.x/texWidth),(1.0-fc10.y/texHeight));
if(a5<0.2 && a10<0.4 && a15 <.5){
tc.x = tc.x+ tc5.x;
tc.y = tc.y * tc5.y;
}
return tc;
}
vec2 NormCoord(vec2 fc){
vec2 tc = vec2((fc.x/texWidth),(1.0-fc.y/texHeight));
return tc;
}
float rand(vec2 co,float seed){
return fract(sin(dot(co, vec2(12.9898, 78.233))) * seed);
}
void main(void) {
float m=.5;// do not change
float p =3.*similarity;
float f = .1*similarity;
vec2 fco = vec2(gl_FragCoord.x,gl_FragCoord.y);
vec2 fc = vec2(fco);
vec2 texCoord = NormCoord(fc);
vec2 tc = texCoord;
float cd = ClPlDist(tc);
// float cd = ChromaDist(tc);
vec2 fc3 = floor(fc/1.1);
vec2 fc5 = floor(fc/5.);
vec2 fc10 = floor(fc/7.);
vec4 c1 = texture2D(tex, sin(-fc));
vec4 c3 = texture2D(tex, atan(-fc3));
vec4 c5 = texture2D(tex, atan(-fc5));
//float a5 = GoN(fc,c4.x*similarity*seed);
float seed= 43758.5453;
float a1 = GoN(fc,c1.y*similarity*seed*.0018);
float a3 = GoN(fc3,c3.y*similarity*seed*.0018);
a3 = pow(a3,1.);
a1 = pow(a1,1.);
float cd2= cd;
//cd2 = mix(cd,a3,cd);
//cd= mix(cd,a1,cd);
//float af = mix(a1,a3,.5);
cd = pow(cd,p);
m= pow(m,p);
cd = cd*f;
cd2 = cd2*f;
m=m*f;
if(1==1){
//by distance to the middle
float cdf =(cd-m);
float cdf2 =(cd2-m);
float sim = pow(eas(similarity),1.);
tc.x= mix(tc.x + cdf,tc.x,sim);
tc.y= mix(tc.y + cdf,tc.y,sim);//tc.y + cdf2;
}
gl_FragColor = ProcessChromaKey(tc);//vec4(af);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment