Make shaders compile on mobile (untested).

This commit is contained in:
Mari the Deer 2022-07-08 22:22:35 +02:00
commit 4ed74289ed
17 changed files with 61 additions and 54 deletions

View file

@ -3,14 +3,14 @@
void SetupMaterial( inout Material mat )
{
vec2 size = textureSize(tex,0);
vec2 size = vec2(textureSize(tex,0));
vec2 pxsize = vec2(1./size.x,1./size.y);
vec2 pos = vTexCoord.st;
vec2 f = fract(pos*size);
pos += (.5-f)*pxsize;
vec4 p0q0 = texture(tex,pos);
vec4 p1q0 = texture(tex,pos+vec2(pxsize.x,0));
vec4 p0q1 = texture(tex,pos+vec2(0,pxsize.y));
vec4 p1q0 = texture(tex,pos+vec2(pxsize.x,0.));
vec4 p0q1 = texture(tex,pos+vec2(0.,pxsize.y));
vec4 p1q1 = texture(tex,pos+vec2(pxsize.x,pxsize.y));
vec4 pInterp_q0 = mix(p0q0,p1q0,f.x);
vec4 pInterp_q1 = mix(p0q1,p1q1,f.x);

View file

@ -35,7 +35,7 @@ void SetupMaterial( inout Material mat )
vec4 ProcessLight( Material mat, vec4 color )
{
#ifdef AMBIENT_GLOW
float glow = .75+.25*sin(timer*8);
float glow = .75+.25*sin(timer*8.);
return vec4(vec3(glow),color.a);
#else
return color;

View file

@ -6,7 +6,7 @@ float rnd( in vec2 sd )
{
//return cos(sd.y*3874.8674+sd.x*6783.5325)*2737.8474;
// use noise tex instead of trig-based PRNG, much better and doesn't break on intel
return texelFetch(noisetex,ivec2(mod(sd.x,256.),mod(sd.y,256.)),0).x;
return texelFetch(noisetex,ivec2(int(mod(sd.x,256.)),int(mod(sd.y,256.))),0).x;
}
// haha are you telling me I can't declare arrays like in C?

View file

@ -33,7 +33,10 @@ vec4 blacktoalpha( in vec4 src )
return dst;
}
#ifdef NO_BILINEAR
#define BilinearSample(x,y,z,w) texture(x,y)
vec4 BilinearSample( in sampler2D tex, in vec2 pos, in vec2 size, in vec2 pxsize )
{
return texture(tex,pos);
}
#else
vec4 BilinearSample( in sampler2D tex, in vec2 pos, in vec2 size, in vec2 pxsize )
{
@ -54,7 +57,7 @@ vec3 GradientMap( in vec3 color )
float gray = dot(color,vec3(.333333));
vec2 size = vec2(512.,8.);
vec2 pxsize = 1./size;
return BilinearSample(gradtex,vec2(gray/2.+.25,0),size,pxsize).rgb;
return BilinearSample(gradtex,vec2(gray/2.+.25,0.),size,pxsize).rgb;
}
void SetupMaterial( inout Material mat )
@ -81,8 +84,8 @@ void SetupMaterial( inout Material mat )
// second layer, alpha blend
vec4 tmp = BilinearSample(Layer2,uv,size,pxsize);
vec4 tmp2;
tmp2.a = tmp.a+base.a*(1-tmp.a);
tmp2.rgb = (tmp.rgb*tmp.a+base.rgb*base.a*(1-tmp.a))/tmp2.a;
tmp2.a = tmp.a+base.a*(1.-tmp.a);
tmp2.rgb = (tmp.rgb*tmp.a+base.rgb*base.a*(1.-tmp.a))/tmp2.a;
base = tmp2;
// third layer, hard light with two multiplied masks
tmp.xy = BilinearSample(Layer3,uv,size,pxsize).xy;

View file

@ -2,7 +2,7 @@
void SetupMaterial( inout Material mat )
{
vec2 size = textureSize(tex,0);
vec2 size = vec2(textureSize(tex,0));
vec2 pxsize = vec2(1./size.x,1./size.y);
vec2 pos = vTexCoord.st-vec2(.5)*pxsize;
vec2 fcoord = fract(pos*size-vec2(.5));

View file

@ -3,8 +3,8 @@
void main()
{
vec2 uv = TexCoord;
vec2 bresl = textureSize(InputTexture,0);
vec2 sr = vec2(1.0,bresl.y/bresl.x);
vec2 bresl = vec2(textureSize(InputTexture,0));
vec2 sr = vec2(1.,bresl.y/bresl.x);
vec2 flood = texture(WarpTex,uv*sr+vec2(timer*.02,-timer*.04)).xy;
flood += texture(WarpTex,uv*sr*2.+vec2(-timer*.07,-timer*.13)).xy;
flood += texture(WarpTex,uv*sr*.5+vec2(0.,-timer*.06)).xy;

View file

@ -12,7 +12,7 @@ vec2 heatdist( in vec2 uv )
void main()
{
vec2 uv = TexCoord;
vec2 bresl = textureSize(InputTexture,0);
vec2 bresl = vec2(textureSize(InputTexture,0));
vec2 sr = vec2(1.,bresl.y/bresl.x);
// vignette fade, will be needed later
vec2 vuv = uv.xy*(1.-uv.yx)*4.;

View file

@ -12,7 +12,7 @@ void main()
float distfct = clamp(pow(dist,1.2)*.85-(.75+.5*(1.-str)),0.,1.);
ofs *= distfct;
vec3 col = texture(InputTexture,uv+ofs).rgb;
col += pow(max(0,ice.z),1.45)*.65*str*distfct;
col += pow(max(0.,ice.z),1.45)*.65*str*distfct;
float str2 = str*(.9+texture(NoiseTex,vec2(timer*.05)).x*.2);
float ang = timer*.05;
uv *= sr;

View file

@ -6,30 +6,30 @@ const float thr3 = 19.3;
float rnd2( in vec2 sd )
{
return fract(cos(dot(sd*floor(Timer*15.0),vec2(145.34,142.55)))*2745.84);
return fract(cos(dot(sd*floor(Timer*15.),vec2(145.34,142.55)))*2745.84);
}
float rnd( in float sd )
{
return rnd2(vec2(sd,1.0));
return rnd2(vec2(sd,1.));
}
void main()
{
vec2 coord = TexCoord;
vec2 uv_c[3] = vec2[3](coord,coord,coord);
vec2 blka = floor(coord*vec2(22.0,12.0));
vec2 blkb = floor(coord*vec2(6.0,9.0));
vec2 blka = floor(coord*vec2(22.,12.));
vec2 blkb = floor(coord*vec2(6.,9.));
float noiz = pow(rnd2(blka),thr1)*pow(rnd2(blkb),thr2)-pow(rnd(4.53),thr3)*str2;
uv_c[0].x += str1*noiz*(rnd(3.35)-0.5);
uv_c[1].x += str1*noiz*(rnd(4.63)-0.5);
uv_c[2].x += str1*noiz*(rnd(5.62)-0.5);
uv_c[0].y += str1*noiz*(rnd(4.55)-0.5);
uv_c[1].y += str1*noiz*(rnd(3.67)-0.5);
uv_c[2].y += str1*noiz*(rnd(5.54)-0.5);
uv_c[0].x += str1*noiz*(rnd(3.35)-.5);
uv_c[1].x += str1*noiz*(rnd(4.63)-.5);
uv_c[2].x += str1*noiz*(rnd(5.62)-.5);
uv_c[0].y += str1*noiz*(rnd(4.55)-.5);
uv_c[1].y += str1*noiz*(rnd(3.67)-.5);
uv_c[2].y += str1*noiz*(rnd(5.54)-.5);
vec4 res;
res.r = texture(InputTexture,uv_c[0]).r;
res.g = texture(InputTexture,uv_c[1]).g;
res.b = texture(InputTexture,uv_c[2]).b;
res.a = 1.0;
res.a = 1.;
FragColor = res;
}

View file

@ -10,7 +10,11 @@ const float ns = -.08;
const float np = 3.95;
const float bnp = 1.7;
#define darkmask(a,b) (a>.5)?(2.*a*(.5+b)):(1.-2.*(1.-a)*(1.-((.5+b))))
float darkmask( in float a, in float b )
{
if ( a > .5 ) return 2.*a*(.5+b);
return 1.-2.*(1.-a)*(1.-((.5+b)));
}
vec3 grain( in vec3 res, in vec2 coord )
{
@ -19,7 +23,7 @@ vec3 grain( in vec3 res, in vec2 coord )
vec2 s2 = coord+vec2(ts,0.);
vec2 s3 = coord+vec2(ts,ts);
float n1, n2, n3;
vec2 nr = textureSize(NoiseTexture,0);
vec2 nr = vec2(textureSize(NoiseTexture,0));
s1 = mod(s1*nm1.x*nr,1.);
s2 = mod(s2*nm1.y*nr,1.);
s3 = mod(s3*nm1.z*nr,1.);
@ -35,7 +39,7 @@ vec3 grain( in vec3 res, in vec2 coord )
n1 = texture(NoiseTexture,s1).r;
n2 = texture(NoiseTexture,s2).g;
n3 = texture(NoiseTexture,s3).b;
float n4 = (n1+n2+n3)/3.0;
float n4 = (n1+n2+n3)/3.;
vec3 ng = vec3(n4);
vec3 nc = vec3(n1,n2,n3);
vec3 nt = pow(clamp(mix(ng,nc,ns),0.,1.),vec3(np));
@ -52,7 +56,7 @@ void main()
{
vec2 coord = TexCoord;
vec4 res = texture(InputTexture,coord);
vec2 sfact = max(vec2(640.,400.),textureSize(InputTexture,0)*.5);
vec2 sfact = max(vec2(640.,400.),vec2(textureSize(InputTexture,0))*.5);
coord = floor(coord*sfact)/sfact;
res.rgb = grain(res.rgb,coord);
FragColor = res;

View file

@ -5,14 +5,14 @@ vec3 sharpened( vec2 uv )
vec3 col = texture(InputTexture,uv).rgb*9.;
vec2 bresl = vec2(textureSize(InputTexture,0));
vec2 bof = vec2(1./bresl.x,1./bresl.y);
col -= texture(InputTexture,uv+vec2(bof.x,0)).rgb;
col -= texture(InputTexture,uv+vec2(2.*bof.x,0)).rgb;
col -= texture(InputTexture,uv+vec2(-bof.x,0)).rgb;
col -= texture(InputTexture,uv+vec2(-2.*bof.x,0)).rgb;
col -= texture(InputTexture,uv+vec2(0,bof.y)).rgb;
col -= texture(InputTexture,uv+vec2(0,2.*bof.y)).rgb;
col -= texture(InputTexture,uv+vec2(0,-bof.y)).rgb;
col -= texture(InputTexture,uv+vec2(0,-2.*bof.y)).rgb;
col -= texture(InputTexture,uv+vec2(bof.x,0.)).rgb;
col -= texture(InputTexture,uv+vec2(2.*bof.x,0.)).rgb;
col -= texture(InputTexture,uv+vec2(-bof.x,0.)).rgb;
col -= texture(InputTexture,uv+vec2(-2.*bof.x,0.)).rgb;
col -= texture(InputTexture,uv+vec2(0.,bof.y)).rgb;
col -= texture(InputTexture,uv+vec2(0.,2.*bof.y)).rgb;
col -= texture(InputTexture,uv+vec2(0.,-bof.y)).rgb;
col -= texture(InputTexture,uv+vec2(0.,-2.*bof.y)).rgb;
return col;
}
@ -26,5 +26,5 @@ void main()
vec2 suv = fract((uv-.5)*(1.-.01*i*(.3+str*4.))+.5);
col += sharpened(suv)*pow(p,2.4)*vec3(1.2,.7,.2)*(.4+str);
}
FragColor = vec4(col,1.0);
FragColor = vec4(col,1.);
}

View file

@ -5,10 +5,10 @@ vec2 calcdist( vec2 duv )
{
vec2 uv = vec2(0.);
vec2 dist = 2.*texture(warptex,duv*.2).xy-1.;
dist.x *= abs(mod(dist.y+timer*0.34536,4.)-2.)-1.;
dist.x *= abs(mod(dist.y+timer*.34536,4.)-2.)-1.;
uv.x += dist.x*.02*dfact;
dist = 2.*texture(warptex,(duv+uv)*.3).xy-1.;
dist.y *= abs(mod(dist.x+timer*0.25363,4.)-2.)-1.;
dist.y *= abs(mod(dist.x+timer*.25363,4.)-2.)-1.;
uv.y -= dist.y*.03*dfact;
return uv;
}
@ -16,7 +16,7 @@ vec2 calcdist( vec2 duv )
void main()
{
vec2 uv = TexCoord+calcdist(TexCoord-vec2(0.,timer*.02));
vec2 bresl = textureSize(InputTexture,0);
vec2 bresl = vec2(textureSize(InputTexture,0));
vec2 sr = vec2(1.,bresl.y/bresl.x);
float p = distance(uv,vec2(.5));
uv = (uv-.5)*(1.-dfact*.07)+.5;

View file

@ -18,5 +18,5 @@ void main()
}
col /= 5.;
col *= vec3(1.2,.9,.7);
FragColor = vec4(col,1.0);
FragColor = vec4(col,1.);
}

View file

@ -6,9 +6,9 @@ void main()
{
vec2 uv = TexCoord.st;
vec3 base = texture(InputTexture,uv).rgb;
vec2 bof = 1.0/textureSize(InputTexture,0);
vec2 bof = 1./vec2(textureSize(InputTexture,0));
int rsamples, tstep = 1;
vec2 bstr = bof*4.0;
vec2 bstr = bof*4.;
float bstep;
vec2 rcoord;
for ( int i=1; i<=5; i++ )
@ -16,7 +16,7 @@ void main()
rsamples = i*3;
for ( int j=0; j<rsamples; j++ )
{
bstep = PI*2.0/rsamples;
bstep = PI*2./rsamples;
rcoord = vec2(cos(j*bstep),sin(j*bstep))*i;
tstep++;
base.rgb += texture(InputTexture,uv+rcoord*bstr).rgb;
@ -24,7 +24,7 @@ void main()
}
base /= tstep;
vec2 p = vec2(.5)-uv;
vec2 sz = textureSize(InputTexture,0);
vec2 sz = vec2(textureSize(InputTexture,0));
if ( sz.x > sz.y ) p.x *= sz.x/sz.y;
else p.y *= sz.y/sz.x;
vec3 col = texture(InputTexture,uv+p*pow(length(p),8.)*20.).rgb;

View file

@ -5,10 +5,10 @@ vec2 calcdist( vec2 duv )
{
vec2 uv = vec2(0.);
vec2 dist = 2.*texture(warptex,duv*.4).xy-1.;
dist.x *= abs(mod(dist.y+timer*0.24536,4.)-2.)-1.;
dist.x *= abs(mod(dist.y+timer*.24536,4.)-2.)-1.;
uv.x += dist.x*.02*dfact;
dist = 2.*texture(warptex,(duv+uv)*.3).xy-1.;
dist.y *= abs(mod(dist.x+timer*0.15363,4.)-2.)-1.;
dist.y *= abs(mod(dist.x+timer*.15363,4.)-2.)-1.;
uv.y -= dist.y*.03*dfact;
return uv;
}
@ -16,7 +16,7 @@ vec2 calcdist( vec2 duv )
void main()
{
vec2 uv = TexCoord+calcdist(TexCoord-vec2(0.,timer*.08));
vec2 bresl = textureSize(InputTexture,0);
vec2 bresl = vec2(textureSize(InputTexture,0));
vec2 sr = vec2(1.,bresl.y/bresl.x);
float p = distance(uv,vec2(.5));
uv = (uv-.5)*(1.-dfact*.11)+.5;

View file

@ -5,10 +5,10 @@ vec2 calcdist( vec2 duv )
{
vec2 uv = vec2(0.);
vec2 dist = 2.*texture(warptex,duv*.2).xy-1.;
dist.x *= abs(mod(dist.y+timer*0.34536,4.)-2.)-1.;
dist.x *= abs(mod(dist.y+timer*.34536,4.)-2.)-1.;
uv.x += dist.x*.03*dfact;
dist = 2.*texture(warptex,(duv+uv)*.3).xy-1.;
dist.y *= abs(mod(dist.x+timer*0.45363,4.)-2.)-1.;
dist.y *= abs(mod(dist.x+timer*.45363,4.)-2.)-1.;
uv.y -= dist.y*.02*dfact;
return uv;
}
@ -16,7 +16,7 @@ vec2 calcdist( vec2 duv )
void main()
{
vec2 uv = TexCoord+calcdist(TexCoord-vec2(0.,timer*.2));
vec2 bresl = textureSize(InputTexture,0);
vec2 bresl = vec2(textureSize(InputTexture,0));
vec2 sr = vec2(1.,bresl.y/bresl.x);
float p = distance(uv,vec2(.5));
uv = (uv-.5)*(1.-dfact*.12)+.5;