blob: ee9b70570ea4a2ca1905b703a22a753d2c0b66d8 [file] [log] [blame]
static constexpr char SKSL_MINIFIED_sksl_graphite_frag[] =
"$pure half4 sk_error(){return half4(1.,0.,1.,1.);}$pure half4 sk_passthrough"
"(half4 a){return a;}$pure half4 sk_solid_shader(float4 a){return half4(a);}"
"$pure half4 $k(int a,half4 b){half4 c=b;switch(a){case 0:break;case 1:c=half4"
"(b.xyz,1.);break;case 2:c=b.xxxx;break;case 3:c=half4(b.xxx,1.);break;case 4"
":c=b.zyxw;break;}return c;}$pure float $l(int a,float b,half[7]c){float d=float"
"(c[0]);float e=float(c[1]);float f=float(c[2]);float g=float(c[3]);float h="
"float(c[4]);float i=float(c[5]);float j=float(c[6]);float k=sign(b);b=abs(b"
");switch(a){case 1:b=b<h?g*b+j:pow(e*b+f,d)+i;break;case 2:b=pow(max(e+f*pow"
"(b,g),0.)/(h+i*pow(b,g)),j);break;case 3:b=b*e<=1.?pow(b*e,f):exp((b-i)*g)+"
"h;b*=j+1.;break;case 4:b/=j+1.;b=b<=1.?e*pow(b,f):g*log(b-h)+i;break;}return"
" k*b;}$pure half4 sk_color_space_transform(half4 a,int b,int c,half[7]d,half3x3"
" e,int f,half[7]g){float4 h=float4(a);if(bool(b&1)){h=unpremul(h);}if(bool("
"b&2)){h.x=$l(c,h.x,d);h.y=$l(c,h.y,d);h.z=$l(c,h.z,d);}if(bool(b&4)){h.xyz="
"float3x3(e)*h.xyz;}if(bool(b&8)){h.x=$l(f,h.x,g);h.y=$l(f,h.y,g);h.z=$l(f,h"
".z,g);}if(bool(b&16)){h.xyz*=h.w;}return half4(h);}$pure float $m(int a,float"
" b,float c,float d){switch(a){case 0:return clamp(b,c,d);case 1:{float e=d-"
"c;return mod(b-c,e)+c;}case 2:{float e=d-c;float g=2.*e;float h=mod(b-c,g);"
"return mix(h,g-h,step(e,h))+c;}default:return b;}}$pure half4 $n(float2 a,float2"
" b,float4 c,int d,int e,int f,int g,sampler2D h){if(d==3&&f==0){float i=floor"
"(a.x)+.5;if(i<c.x||i>c.z){return half4(0.);}}if(e==3&&f==0){float i=floor(a"
".y)+.5;if(i<c.y||i>c.w){return half4(0.);}}a.x=$m(d,a.x,c.x,c.z);a.y=$m(e,a"
".y,c.y,c.w);float4 i;if(f==0){i=float4(floor(c.xy)+.5,ceil(c.zw)-.5);}else{"
"i=float4(c.xy+.5,c.zw-.5);}float2 j=clamp(a,i.xy,i.zw);half4 k=sample(h,j/b"
");k=$k(g,k);if(f==1){half2 l=half2(a-j);half2 m=abs(l);bool n=d==1;bool o=e"
"==1;if(n||o){float p;float q;half4 r;half4 t;if(n){p=l.x>0.?i.x:i.z;r=sample"
"(h,float2(p,j.y)/b);r=$k(g,r);}if(o){q=l.y>0.?i.y:i.w;t=sample(h,float2(j.x"
",q)/b);t=$k(g,t);}if(n&&o){half4 u=sample(h,float2(p,q)/b);u=$k(g,u);k=mix("
"mix(k,r,m.x),mix(t,u,m.x),m.y);}else if(n){k=mix(k,r,m.x);}else if(o){k=mix"
"(k,t,m.y);}}if(d==3){k*=max(1.-m.x,0.);}if(e==3){k*=max(1.-m.y,0.);}}return"
" k;}$pure half4 $o(float2 a,float2 b,float4 c,int d,int e,float4x4 g,int h,"
"sampler2D i){float2 j=fract(a-.5);a-=1.5;a=floor(a)+.5;float4 k=g*float4(1."
",j.x,j.x*j.x,(j.x*j.x)*j.x);float4 l=g*float4(1.,j.y,j.y*j.y,(j.y*j.y)*j.y)"
";float4 m=float4(0.);for(int n=0;n<4;++n){float4 o=float4(0.);for(int p=0;p"
"<4;++p){o+=k[p]*float4($n(a+float2(float(p),float(n)),b,c,d,e,0,h,i));}m+=l"
"[n]*o;}return half4(m);}$pure half4 sk_image_shader(float2 a,float2 b,float4"
" c,int d,int e,int f,int g,float4x4 h,int i,int j,int k,half[7]l,half3x3 m,"
"int n,half[7]o,sampler2D p){half4 q=g!=0?$o(a,b,c,d,e,h,i,p):$n(a,b,c,d,e,f"
",i,p);return sk_color_space_transform(q,j,k,l,m,n,o);}$pure half4 sk_yuv_image_shader"
"(float2 a,float2 b,float4 c,int d,int e,int f,int g,float4x4 h,half4 i,half4"
" j,half4 k,half4 l,half3x3 m,float3 n,int o,int p,half[7]q,half3x3 r,int s,"
"half[7]t,sampler2D u,sampler2D v,sampler2D w,sampler2D x){half4 y=g!=0?$o(a"
",b,c,d,e,h,0,u):$n(a,b,c,d,e,f,0,u);half4 z=g!=0?$o(a,b,c,d,e,h,0,v):$n(a,b"
",c,d,e,f,0,v);half4 A=g!=0?$o(a,b,c,d,e,h,0,u):$n(a,b,c,d,e,f,0,w);float B="
"float(dot(i,y));float C=float(dot(j,z));float D=float(dot(k,A));half3 E=half3"
"(half(B),half(C),half(D));half4 F;F.xyz=saturate(E*m+half3(n));if(l==half4("
"0.)){F.w=1.;}else{half4 G=g!=0?$o(a,b,c,d,e,h,0,x):$n(a,b,c,d,e,f,0,x);F.w="
"dot(l,G);F.xyz*=F.w;}return sk_color_space_transform(F,o,p,q,r,s,t);}$pure half4"
" sk_dither_shader(half4 a,float2 b,half c,sampler2D d){half f=sample(d,b*.125"
").x-.5;return half4(clamp(a.xyz+f*c,0.,a.w),a.w);}$pure float2 $p(int a,float2"
" b){switch(a){case 0:b.x=clamp(b.x,0.,1.);break;case 1:b.x=fract(b.x);break"
";case 2:{float c=b.x-1.;b.x=(c-2.*floor(c*.5))-1.;if(sk_Caps.mustDoOpBetweenFloorAndAbs"
"){b.x=clamp(b.x,-1.,1.);}b.x=abs(b.x);break;}case 3:if(b.x<0.||b.x>1.){return"
" float2(0.,-1.);}break;}return b;}$pure half4 $q(float4[4]a,float[4]b,float2"
" c){if(c.y<0.){return half4(0.);}else if(c.x<=b[0]){return half4(a[0]);}else"
" if(c.x<b[1]){return half4(mix(a[0],a[1],(c.x-b[0])/(b[1]-b[0])));}else if("
"c.x<b[2]){return half4(mix(a[1],a[2],(c.x-b[1])/(b[2]-b[1])));}else if(c.x<"
"b[3]){return half4(mix(a[2],a[3],(c.x-b[2])/(b[3]-b[2])));}else{return half4"
"(a[3]);}}$pure half4 $r(float4[8]a,float[8]b,float2 c){if(c.y<0.){return half4"
"(0.);}else if(c.x<b[4]){if(c.x<b[2]){if(c.x<=b[0]){return half4(a[0]);}else"
" if(c.x<b[1]){return half4(mix(a[0],a[1],(c.x-b[0])/(b[1]-b[0])));}else{return"
" half4(mix(a[1],a[2],(c.x-b[1])/(b[2]-b[1])));}}else{if(c.x<b[3]){return half4"
"(mix(a[2],a[3],(c.x-b[2])/(b[3]-b[2])));}else{return half4(mix(a[3],a[4],(c"
".x-b[3])/(b[4]-b[3])));}}}else{if(c.x<b[6]){if(c.x<b[5]){return half4(mix(a"
"[4],a[5],(c.x-b[4])/(b[5]-b[4])));}else{return half4(mix(a[5],a[6],(c.x-b[5"
"])/(b[6]-b[5])));}}else{if(c.x<b[7]){return half4(mix(a[6],a[7],(c.x-b[6])/"
"(b[7]-b[6])));}else{return half4(a[7]);}}}}half4 $s(sampler2D a,int b,float2"
" c){if(c.y<0.){return half4(0.);}else if(c.x==0.){return sampleLod(a,float2"
"(0.,.25),0.);}else if(c.x==1.){return sampleLod(a,float2(1.,.25),0.);}else{"
"int f=0;int g=b;for(int h=1;h<b;h<<=1){int i=(f+g)/2;float j=(float(i)+.5)/"
"float(b);float2 k=float2(sampleLod(a,float2(j,.75),0.).xy);float l=ldexp(k."
"x,int(k.y));if(c.x<l){g=i;}else{f=i;}}float h=(float(f)+.5)/float(b);float i"
"=(float(f+1)+.5)/float(b);half4 j=sampleLod(a,float2(h,.25),0.);half4 k=sampleLod"
"(a,float2(i,.25),0.);float2 l=float2(sampleLod(a,float2(h,.75),0.).xy);float"
" m=ldexp(l.x,int(l.y));l=float2(sampleLod(a,float2(i,.75),0.).xy);float n=ldexp"
"(l.x,int(l.y));return half4(mix(float4(j),float4(k),(c.x-m)/(n-m)));}}$pure"
" float2 $t(float2 a,float2 b,float2 c){c-=a;float2 d=b-a;float e=dot(c,d)/dot"
"(d,d);return float2(e,1.);}$pure float2 $u(float2 a,float b,float2 c){float"
" d=distance(c,a)/b;return float2(d,1.);}$pure float2 $v(float2 a,float b,float"
" c,float2 d){d-=a;float e=sk_Caps.atan2ImplementedAsAtanYOverX?2.*atan(-d.y"
",length(d)-d.x):atan(-d.y,-d.x);float f=((e*.159154937+.5)+b)*c;return float2"
"(f,1.);}$pure float3x3 $w(float2 a,float2 b){return float3x3(0.,-1.,0.,1.,0."
",0.,0.,0.,1.)*inverse(float3x3(b.y-a.y,a.x-b.x,0.,b.x-a.x,b.y-a.y,0.,a.x,a."
"y,1.));}$pure float2 $x(float2 a,float2 b,float c,float d,float2 e){const float"
" f=.000244140625;float g=distance(a,b);float h=d-c;bool i=g<f;bool j=abs(h)"
"<f;if(i){if(j){return float2(0.,-1.);}float k=1./h;float l=sign(h);float m="
"c/h;float2 n=(e-a)*k;float o=length(n)*l-m;return float2(o,1.);}else if(j){"
"float3x3 k=$w(a,b);float l=c/g;float m=l*l;float2 n=(k*float3(e,1.)).xy;float"
" o=m-n.y*n.y;if(o<0.){return float2(0.,-1.);}o=n.x+sqrt(o);return float2(o,"
"1.);}else{float k=c/(c-d);bool l=abs(k-1.)<f;if(l){float2 m=a;a=b;b=m;k=0.;"
"}float2 m=a*(1.-k)+b*k;float3x3 n=$w(m,b);float o=abs(1.-k);float p=o;float"
" q=abs(d-c)/g;bool r=abs(q-1.)<f;if(r){o*=.5;p*=.5;}else{o*=q/(q*q-1.);p/=sqrt"
"(abs(q*q-1.));}n=float3x3(o,0.,0.,0.,p,0.,0.,0.,1.)*n;float2 s=(n*float3(e,"
"1.)).xy;float u=1./q;float v=sign(1.-k);bool w=!r&&q>1.;float x=-1.;if(r){x"
"=dot(s,s)/s.x;}else if(w){x=length(s)-s.x*u;}else{float y=s.x*s.x-s.y*s.y;if"
"(y>=0.){if(l||v<0.){x=-sqrt(y)-s.x*u;}else{x=sqrt(y)-s.x*u;}}}if(!w&&x<0.){"
"return float2(0.,-1.);}float y=k+v*x;if(l){y=1.-y;}return float2(y,1.);}}$pure"
" half4 sk_linear_grad_4_shader(float2 a,float4[4]b,float[4]c,float2 d,float2"
" e,int f,int g,int h){float2 i=$t(d,e,a);i=$p(f,i);half4 j=$q(b,c,i);return"
" $interpolated_to_rgb_unpremul(j,g,h);}$pure half4 sk_linear_grad_8_shader("
"float2 a,float4[8]b,float[8]c,float2 d,float2 e,int f,int g,int h){float2 i"
"=$t(d,e,a);i=$p(f,i);half4 j=$r(b,c,i);return $interpolated_to_rgb_unpremul"
"(j,g,h);}$pure half4 sk_linear_grad_tex_shader(float2 a,float2 b,float2 c,int"
" d,int e,int f,int g,sampler2D h){float2 i=$t(b,c,a);i=$p(e,i);half4 j=$s(h"
",d,i);return $interpolated_to_rgb_unpremul(j,f,g);}$pure half4 sk_radial_grad_4_shader"
"(float2 a,float4[4]b,float[4]c,float2 d,float e,int f,int g,int h){float2 i"
"=$u(d,e,a);i=$p(f,i);half4 j=$q(b,c,i);return $interpolated_to_rgb_unpremul"
"(j,g,h);}$pure half4 sk_radial_grad_8_shader(float2 a,float4[8]b,float[8]c,"
"float2 d,float e,int f,int g,int h){float2 i=$u(d,e,a);i=$p(f,i);half4 j=$r"
"(b,c,i);return $interpolated_to_rgb_unpremul(j,g,h);}$pure half4 sk_radial_grad_tex_shader"
"(float2 a,float2 b,float c,int d,int e,int f,int g,sampler2D h){float2 i=$u"
"(b,c,a);i=$p(e,i);half4 j=$s(h,d,i);return $interpolated_to_rgb_unpremul(j,"
"f,g);}$pure half4 sk_sweep_grad_4_shader(float2 a,float4[4]b,float[4]c,float2"
" d,float e,float f,int g,int h,int i){float2 j=$v(d,e,f,a);j=$p(g,j);half4 k"
"=$q(b,c,j);return $interpolated_to_rgb_unpremul(k,h,i);}$pure half4 sk_sweep_grad_8_shader"
"(float2 a,float4[8]b,float[8]c,float2 d,float e,float f,int g,int h,int i){"
"float2 j=$v(d,e,f,a);j=$p(g,j);half4 k=$r(b,c,j);return $interpolated_to_rgb_unpremul"
"(k,h,i);}$pure half4 sk_sweep_grad_tex_shader(float2 a,float2 b,float c,float"
" d,int e,int f,int g,int h,sampler2D i){float2 j=$v(b,c,d,a);j=$p(f,j);half4"
" k=$s(i,e,j);return $interpolated_to_rgb_unpremul(k,g,h);}$pure half4 sk_conical_grad_4_shader"
"(float2 a,float4[4]b,float[4]c,float2 d,float2 e,float f,float g,int h,int i"
",int j){float2 k=$x(d,e,f,g,a);k=$p(h,k);half4 l=$q(b,c,k);return $interpolated_to_rgb_unpremul"
"(l,i,j);}$pure half4 sk_conical_grad_8_shader(float2 a,float4[8]b,float[8]c"
",float2 d,float2 e,float f,float g,int h,int i,int j){float2 k=$x(d,e,f,g,a"
");k=$p(h,k);half4 l=$r(b,c,k);return $interpolated_to_rgb_unpremul(l,i,j);}"
"$pure half4 sk_conical_grad_tex_shader(float2 a,float2 b,float2 c,float d,float"
" e,int f,int g,int h,int i,sampler2D j){float2 k=$x(b,c,d,e,a);k=$p(g,k);half4"
" l=$s(j,f,k);return $interpolated_to_rgb_unpremul(l,h,i);}$pure half4 sk_matrix_colorfilter"
"(half4 a,float4x4 b,float4 c,int d){if(bool(d)){a=$rgb_to_hsl(a.xyz,a.w);}else"
"{a=unpremul(a);}half4 e=half4(b*float4(a)+c);if(bool(d)){e=$hsl_to_rgb(e.xyz"
",e.w);}else{e=saturate(e);e.xyz*=e.w;}return e;}$pure half4 noise_helper(half2"
" a,half2 b,int c,sampler2D d){half4 f;f.xy=floor(a);f.zw=f.xy+half2(1.);if("
"bool(c)){f-=step(b.xyxy,f)*b.xyxy;}half g=sample(d,float2(half2(f.x*.00390625"
",.5))).x;half h=sample(d,float2(half2(f.z*.00390625,.5))).x;half2 i=half2(g"
",h);if(sk_Caps.PerlinNoiseRoundingFix){i=floor(i*half2(255.)+half2(.5))*half2"
"(.003921569);}half4 j=256.*i.xyxy+f.yyww;j*=half4(.00390625);return j;}$pure"
" half4 noise_function(half2 a,half4 b,sampler2D c){half2 d=fract(a);half2 e"
"=(d*d)*(half2(3.)-2.*d);const half f=.00390625;half4 g;for(int h=0;h<4;h++)"
"{half i=(half(h)+.5)*.25;half4 j=sample(c,float2(half2(b.x,i)));half4 k=sample"
"(c,float2(half2(b.y,i)));half4 l=sample(c,float2(half2(b.w,i)));half4 m=sample"
"(c,float2(half2(b.z,i)));half2 n;half2 o=d;n.x=dot((j.yw+j.xz*f)*2.-half2(1."
"),o);o.x-=1.;n.y=dot((k.yw+k.xz*f)*2.-half2(1.),o);half2 p;p.x=mix(n.x,n.y,"
"e.x);o.y-=1.;n.y=dot((l.yw+l.xz*f)*2.-half2(1.),o);o.x+=1.;n.x=dot((m.yw+m."
"xz*f)*2.-half2(1.),o);p.y=mix(n.x,n.y,e.x);g[h]=mix(p.x,p.y,e.y);}return g;"
"}$pure half4 perlin_noise_shader(float2 a,float2 b,float2 c,int d,int e,int"
" f,sampler2D g,sampler2D h){half2 k=half2(floor(a)*b);half4 l=half4(0.);half2"
" m=half2(c);half n=1.;for(int o=0;o<e;++o){half4 p=noise_helper(k,m,f,g);half4"
" q=noise_function(k,p,h);if(d!=0){q=abs(q);}q*=n;l+=q;k*=half2(2.);n*=.5;m*="
"half2(2.);}if(d==0){l=l*half4(.5)+half4(.5);}l=saturate(l);return half4(l.xyz"
"*l.www,l.w);}$pure half4 sk_blend(half4 a,half4 b,int c){switch(c){case 0:{"
"return blend_clear(a,b);}case 1:{return blend_src(a,b);}case 2:{return blend_dst"
"(a,b);}case 3:{return blend_porter_duff(half4(1.,0.,0.,-1.),a,b);}case 4:{return"
" blend_porter_duff(half4(0.,1.,-1.,0.),a,b);}case 5:{return blend_porter_duff"
"(half4(0.,0.,1.,0.),a,b);}case 6:{return blend_porter_duff(half4(0.,0.,0.,1."
"),a,b);}case 7:{return blend_porter_duff(half4(0.,0.,-1.,0.),a,b);}case 8:{"
"return blend_porter_duff(half4(0.,0.,0.,-1.),a,b);}case 9:{return blend_porter_duff"
"(half4(0.,0.,1.,-1.),a,b);}case 10:{return blend_porter_duff(half4(0.,0.,-1."
",1.),a,b);}case 11:{return blend_porter_duff(half4(0.,0.,-1.,-1.),a,b);}case"
" 12:{return blend_porter_duff(half4(1.,1.,0.,0.),a,b);}case 13:{return blend_modulate"
"(a,b);}case 14:{return blend_screen(a,b);}case 15:{return blend_overlay(0.,"
"a,b);}case 16:{return blend_darken(1.,a,b);}case 17:{return blend_darken(-1."
",a,b);}case 18:{return blend_color_dodge(a,b);}case 19:{return blend_color_burn"
"(a,b);}case 20:{return blend_overlay(1.,a,b);}case 21:{return blend_soft_light"
"(a,b);}case 22:{return blend_difference(a,b);}case 23:{return blend_exclusion"
"(a,b);}case 24:{return blend_multiply(a,b);}case 25:{return blend_hslc(half2"
"(0.,1.),a,b);}case 26:{return blend_hslc(half2(1.),a,b);}case 27:{return blend_hslc"
"(half2(0.),a,b);}case 28:{return blend_hslc(half2(1.,0.),a,b);}default:return"
" half4(0.);}}$pure half4 sk_coeff_blend(half4 a,half4 b,half4 c){return blend_porter_duff"
"(c,a,b);}$pure half4 sk_table_colorfilter(half4 a,sampler2D b){half4 c=(unpremul"
"(a)*255.)*.00390625+.001953125;half4 d=half4(sample(b,float2(half2(c.x,.375"
"))).x,sample(b,float2(half2(c.y,.625))).x,sample(b,float2(half2(c.z,.875)))"
".x,1.);return d*sample(b,float2(half2(c.w,.125))).x;}$pure half4 sk_gaussian_colorfilter"
"(half4 a){half b=1.-a.w;b=exp((-b*b)*4.)-.018;return half4(b);}$pure float inverse_grad_len"
"(float2 a,float2x2 b){float2 c=a*b;return inversesqrt(dot(c,c));}$pure float2"
" elliptical_distance(float2 a,float2 b,float c,float2x2 d){float2 e=1./(b*b"
"+c*c);float2 g=e*a;float h=inverse_grad_len(g,d);float i=(.5*h)*(dot(a,g)-1."
");float j=((b.x*c)*e.x)*h;return float2(j-i,j+i);}void corner_distance(inout"
" float2 a,float2x2 b,float2 c,float2 d,float2 e,float2 f){float2 g=f-d;if(g"
".x>0.&&g.y>0.){if(f.x>0.&&f.y>0.||c.x>0.&&c.y<0.){float2 h=elliptical_distance"
"(g*e,f,c.x,b);if(f.x-c.x<=0.){h.y=1.;}else{h.y*=-1.;}a=min(a,h);}else if(c."
"y==0.){float h=((c.x-g.x)-g.y)*inverse_grad_len(e,b);a.x=min(a.x,h);}}}void"
" corner_distances(inout float2 a,float2x2 b,float2 c,float4 e,float4 f,float4"
" g){corner_distance(a,b,c,e.xy,float2(-1.),float2(f.x,g.x));corner_distance"
"(a,b,c,e.zy,float2(1.,-1.),float2(f.y,g.y));corner_distance(a,b,c,e.zw,float2"
"(1.),float2(f.z,g.z));corner_distance(a,b,c,e.xw,float2(-1.,1.),float2(f.w,"
"g.w));}";