Files
4k_synthwave/src/shaders/fragment.inl
2025-07-28 14:33:47 +03:00

176 lines
4.6 KiB
C++

// Generated with Shader Minifier 1.5.1 (https://github.com/laurentlb/Shader_Minifier/)
#ifndef FRAGMENT_INL_
# define FRAGMENT_INL_
# define VAR_fft_output "f"
# define VAR_o "v"
# define VAR_shapes "H"
# define VAR_syncs "m"
# define VAR_test "l"
# define VAR_u_ShapesTex "a"
const char *fragment_frag =
"#version 460\n"
"precision mediump float;"
"out vec4 v;"
"const float i=2.*acos(-1.),n=sqrt(5.)*.5+.5;"
"layout(location=0)uniform float m[12];"
"layout(location=20)uniform float f[512];"
"layout(location=600)uniform vec3 H[15];"
"layout(location=700)uniform vec3 l;"
"layout(binding=0)uniform sampler2D a;"
"float g=m[0];"
"mat2 t()"
"{"
"float v=sin(.5),a=cos(.5);"
"return mat2(a,-v,v,a);"
"}"
"float t(vec3 v,vec2 i)"
"{"
"v=abs(v);"
"return max(v.y-i.y,max(v.x*sqrt(3.)*.5+v.z*.5,v.z)-i.x);"
"}\n"
"#define zclamp(a)max(a,0.0)\n"
"struct HexData{vec3 local;vec2 axial;};"
"HexData t(vec3 v)"
"{"
"float i=sqrt(3.)/3.*v.x-1./3.*v.z,f=2./3.*v.z,a=round(i),x=round(f),l=round(-i-f),m=abs(a-i),n=abs(x-f);"
"i=abs(l+i+f);"
"if(m>n&&m>i)"
"a=-x-l;"
"else if(n>i)"
"x=-a-l;"
"i=sqrt(3.)*(a+x*.5);"
"f=1.5*x;"
"HexData r;"
"r.local=v-vec3(i,0,f);"
"r.axial=vec2(a,x);"
"return r;"
"}"
"struct HexData{vec3 local;vec2 axial;};"
"float t(vec2 v)"
"{"
"float i=v.x,a=v.y;"
"return max(abs(i),max(abs(a),abs(-i-a)));"
"}"
"vec2 s(vec3 v)"
"{"
"vec2 i=vec2(v.y,0);"
"HexData m=t(vec3(v.x,v.y-2.5,v.z));"
"float l=1.+f[int(clamp(t(m.axial)+1.,0.,511.))]*3.;"
"vec3 r=m.local;"
"r.xz*=t();"
"l=t(vec3(r.x,r.y-l/2,r.z),vec2(.83,l/2));"
"i=min(i,vec2(l,0));"
"for(float f=0.;f<16.;f++)"
"for(float l=0.;l<16.;l++)"
"{"
"ivec2 m=textureSize(a,0);"
"vec2 n=vec2(l,f)/vec2(m);"
"vec4 r=texture(a,n);"
"if(r.w<.5)"
"continue;"
"i=min(i,vec2(length(v-vec3(-70.+r.x*2.,12.+r.y*80.,0))-.8,1));"
"}"
"return i;"
"}"
"vec3 s(vec3 v,vec3 i,inout vec3 f)"
"{"
"float l=0.,a=0.,x=0.;"
"for(int r=0;r<30;r++)"
"{"
"f=v+i*x;"
"vec2 m=s(f);"
"x+=m.x;"
"l=m.y;"
"if(x>4e2)"
"break;"
"if(m.x<1e-5*(x*.00125+1.))"
"{"
"a=1.;"
"break;"
"}"
"}"
"return vec3(x,l,a);"
"}"
"float s(vec3 v,vec3 i,float f)"
"{"
"float l=1.,a=.02;"
"for(int r=0;r<6;r++)"
"{"
"if(a>f)"
"break;"
"float m=s(v+a*i).x;"
"l=min(l,m/(4.*a));"
"a+=clamp(m,.1,.8);"
"if(l<-1.)"
"break;"
"}"
"l=max(l,-1.);"
"return.25*(1.+l)*(1.+l)*(2.-l);"
"}"
"vec3 x(vec3 v)"
"{"
"vec2 i=vec2(.01,0);"
"v=vec3(s(v+i.xyy).x-s(v-i.xyy).x,s(v+i.yxy).x-s(v-i.yxy).x,s(v+i.yyx).x-s(v-i.yyx).x);"
"return normalize(v);"
"}"
"vec3 s(vec3 v,vec3 l,vec3 i,vec3 a,float f)"
"{"
"vec3 m=vec3(.77,.26,.73);"
"v-=l;"
"float r=length(v);"
"v=normalize(v);"
"float x=30./(1.+.09*r+.032*r*r),n=max(dot(a,v),0.);"
"i=normalize(v-i);"
"vec3 e=vec3(.04);"
"e+=(1.-e)*pow(clamp(1.-max(dot(i,v),0.),0.,1.),5.);"
"r=s(l+a*.01,v,r);"
"return(m*n*x+m*pow(max(dot(a,i),0.),mix(128.,8.,f))*x*e)*r;"
"}"
"vec3 s(vec3 v,vec3 a,vec3 i,float l)"
"{"
"float f=.01;"
"vec3 m=vec3(0);"
"if(l==0.)"
"m=vec3(.8314,.2941,.2941),f=.1;"
"else if(l==1.)"
"m=vec3(.6196,.6118,.6118),f=.7;"
"else if(l==2.)"
"m=vec3(.3255,.4784,.3255),f=.2;"
"else if(l==3.)"
"m=vec3(.2471,.3059,.6314),f=1.;"
"else if(l==4.)"
"m=vec3(.9961,1,.9922),f=.1;"
"else if(l==5.)"
"m=vec3(.9961,1,.9922),f=.3;"
"vec3 r=vec3(0);"
"r+=s(vec3(0,40,-10),v,i,a,f);"
"r+=s(vec3(0,20,15),v,i,a,f);"
"r+=vec3(.08,.62,.75)*clamp(dot(a,normalize(vec3(0,1,-3)*vec3(0,-1,-2))),0.,1.)*.8;"
"return m*max(vec3(0),r);"
"}"
"vec3 s(vec2 i,vec3 v)"
"{"
"v=normalize(vec3(0,10,0)-v);"
"vec3 f=normalize(cross(vec3(0,1,0),v));"
"return normalize(v+i.x*f+i.y*cross(v,f));"
"}"
"vec3 s(vec2 v)"
"{"
"vec3 i=vec3(-20,20,-20),a=s(v,i),l=vec3(0),f=vec3(0);"
"i=s(i,a,f);"
"if(i.x>0.)"
"{"
"vec3 v=x(f);"
"l=s(f,v,a,i.y);"
"}"
"return l*exp(-i.x*.01)+mix(l,mix(vec3(.2667,.2941,.3451),vec3(.302,.3176,.3725),pow(max(dot(a,vec3(0,-.5,1.8)),0.),clamp(m[1]+m[2]+m[3],0.,1.)*5.)),1.-exp(-i.x*.01))*(1.-exp(-i.x*.01));"
"}"
"void main()"
"{"
"vec3 l=s(gl_FragCoord.xy*vec2(.00104166667,.00185185185)-1.);"
"v=vec4(l,1);"
"}";
#endif // FRAGMENT_INL_