scaledFFT

This commit is contained in:
Teemu Järvisalo
2025-07-24 23:50:49 +03:00
parent 62e58d0e1f
commit 77e5f0fc70
2 changed files with 81 additions and 105 deletions

View File

@ -129,7 +129,7 @@ vec2 mapScene(in vec3 p) {
float gridsize = 16.0; // or GRID if you want full size
//float hexGap = 0.2;
for(float j = 0.; j < gridsize; j++) {
for(float i = 0.; i < gridsize; i++) {
ivec2 texSize = textureSize(u_hexGridTex, 0);
@ -142,7 +142,7 @@ vec2 mapScene(in vec3 p) {
// Optionally use hexDist for ripple effect with FFT
int index = clamp(int((hexDist / 34.)*512.), 0, 511);
float hexSize = fft_output[index] * 5.0;
float hexSize = getScaledFFT(index, 15. ,0.);
float a = sdHex(p - hexPos, 1.0 + hexSize, 0.0);
res = min(res, vec2(a, 1.));
@ -323,10 +323,10 @@ vec3 shading(vec3 v, vec3 n, vec3 dir, float material) {
}
vec3 lights = vec3(0.);
lights += addPointLight(vec3(0., 40.0, -10.), vec3(0.77, 0.26, 0.73), 30.0, v, dir, n, shininess);
//lights += addPointLight(vec3(0., 40.0, -10.), vec3(0.77, 0.26, 0.73), 30.0, v, dir, n, shininess);
//lights += addPointLight(vec3(0., 20.0, 15.), vec3(0.77, 0.26, 0.73), 30.0, v, dir, n, shininess);
// LIGHTS IN HEX GRID PATTERN
float gridsize = 16.0; // or GRID if you want full size
vec3 p = vec3(0.);
for(float j = 0.; j < gridsize; j++) {
@ -341,14 +341,13 @@ vec3 shading(vec3 v, vec3 n, vec3 dir, float material) {
// Optionally use hexDist for ripple effect with FFT
int index = clamp(int((hexDist / 34.)*512.), 0, 511);
float hexSize = fft_output[index] * 5.0;
float hexSize = getScaledFFT(index, 15. ,0.);
//float a = sdHex(p - hexPos, 1.0 + hexSize, 0.0);
lights += addPointLightNoShadow(vec3(hexPos.x, (hexPos.y + hexSize) + 3., hexPos.z), palette(hexSize* 1.5), clamp(hexSize * 3., 0., 1.) ,v, dir, n, shininess);
lights += addPointLightNoShadow(vec3(hexPos.x, (hexPos.y + hexSize) + 2., hexPos.z), palette(hexSize* 1.5), clamp(hexSize * 5., 0., 1.) ,v, dir, n, shininess);
}
}
vec3 lightDir = vec3(0., 1., -3);
//float sun_dif = clamp(dot(n, lightDir), 0., 1.);
//float shadow = softshadow(v + n * 0.01, lightDir, .01, 30., 18.);

View File

@ -1,24 +1,30 @@
// Generated with Shader Minifier 1.5.1 (https://github.com/laurentlb/Shader_Minifier/)
#ifndef FRAGMENT_INL_
# define FRAGMENT_INL_
# define VAR_fft_output "i"
# define VAR_o "f"
# define VAR_shapes "s"
# define VAR_syncs "m"
# define VAR_fft_output "m"
# define VAR_o "v"
# define VAR_shapes "l"
# define VAR_syncs "i"
# define VAR_test "k"
# define VAR_u_hexGridTex "d"
# define VAR_u_hexGridTex "c"
const char *fragment_frag =
"#version 460\n"
"precision mediump float;"
"out vec4 f;"
"const float n=2.*acos(-1.),v=sqrt(5.)*.5+.5;"
"layout(location=0)uniform float m[12];"
"layout(location=20)uniform float i[512];"
"layout(location=600)uniform vec3 s[15];"
"out vec4 v;"
"const float n=2.*acos(-1.),f=sqrt(5.)*.5+.5;"
"layout(location=0)uniform float i[12];"
"layout(location=20)uniform float m[512];"
"layout(location=600)uniform vec3 l[15];"
"layout(location=700)uniform vec3 k;"
"uniform sampler2D d;"
"float C=m[0];"
"uniform sampler2D c;"
"float s=i[0];"
"float t(int v)"
"{"
"v=clamp(v,0,511);"
"float n=m[v];"
"return log(1.+n*15.);"
"}"
"float t(vec3 v,vec2 i)"
"{"
"v=abs(v);"
@ -33,52 +39,36 @@ const char *fragment_frag =
"vec2 t(vec3 v)"
"{"
"vec2 f=t(vec2(v.y,0),vec2(length(v-vec3(2.+k.x*2.,12.+k.y*10.,0))-.2,1));"
"for(float n=0.;n<16.;n++)"
"for(float i=0.;i<16.;i++)"
"for(float l=0.;l<16.;l++)"
"{"
"ivec2 m=textureSize(d,0);"
"vec2 y=vec2(l,n)/vec2(m);"
"vec4 c=texture(d,y);"
"f=min(f,vec2(t(v-c.xyz,vec2(.86,1.+i[clamp(int(c.w/34.*512.),0,511)]*5.)),1));"
"ivec2 n=textureSize(c,0);"
"vec2 m=vec2(l,i)/vec2(n);"
"vec4 d=texture(c,m);"
"f=min(f,vec2(t(v-d.xyz,vec2(.86,1.+t(clamp(int(d.w/34.*512.),0,511)))),1));"
"}"
"return f;"
"}"
"vec3 t(vec3 v,vec3 i,inout vec3 f)"
"{"
"float d=0.,n=0.,y=0.;"
"for(int l=0;l<30;l++)"
"float c=0.,l=0.,n=0.;"
"for(int r=0;r<30;r++)"
"{"
"f=v+i*d;"
"vec2 m=t(f);"
"d+=m.x;"
"n=m.y;"
"if(d>1e2)"
"f=v+i*c;"
"vec2 d=t(f);"
"c+=d.x;"
"l=d.y;"
"if(c>1e2)"
"break;"
"if(m.x<.001*d)"
"if(d.x<.001*c)"
"{"
"y=1.;"
"n=1.;"
"break;"
"}"
"}"
"if(d>1e2)"
"d=0.;"
"return vec3(d,n,y);"
"}"
"float t(vec3 v,vec3 i,float f)"
"{"
"float d=1.,l=.02;"
"for(int n=0;n<6;n++)"
"{"
"if(l>f)"
"break;"
"float m=t(v+l*i).x;"
"d=min(d,m/(4.*l));"
"l+=clamp(m,.1,.8);"
"if(d<-1.)"
"break;"
"}"
"d=max(d,-1.);"
"return.25*(1.+d)*(1.+d)*(2.-d);"
"if(c>1e2)"
"c=0.;"
"return vec3(c,l,n);"
"}"
"vec3 e(vec3 v)"
"{"
@ -86,82 +76,69 @@ const char *fragment_frag =
"v=vec3(t(v+i.xyy).x-t(v-i.xyy).x,t(v+i.yxy).x-t(v-i.yxy).x,t(v+i.yyx).x-t(v-i.yyx).x);"
"return normalize(v);"
"}"
"vec3 e(vec3 v,vec3 f,vec3 d,float i)"
"{"
"vec3 m=vec3(.77,.26,.73),l=vec3(0,40,-10)-v;"
"float n=length(l);"
"l=normalize(l);"
"float y=30./(1.+.09*n+.032*n*n),c=max(dot(d,l),0.);"
"f=normalize(l-f);"
"vec3 r=vec3(.04);"
"r+=(1.-r)*pow(clamp(1.-max(dot(f,l),0.),0.,1.),5.);"
"n=t(v+d*.01,l,n);"
"return(m*c*y+m*pow(max(dot(d,f),0.),mix(128.,8.,i))*y*r)*n;"
"}"
"vec3 e(vec3 v,vec3 i,float d,vec3 f,vec3 n,vec3 m,float l)"
"vec3 e(vec3 v,vec3 i,float c,vec3 f,vec3 n,vec3 l,float m)"
"{"
"v-=f;"
"float r=length(v);"
"v=normalize(v);"
"r=clamp(d-r*r/11.56,0.,1.);"
"d=max(dot(m,v),0.);"
"r=clamp(c-r*r/11.56,0.,1.);"
"c=max(dot(l,v),0.);"
"f=normalize(v-n);"
"n=vec3(.04);"
"v=n+(1.-n)*pow(clamp(1.-max(dot(f,v),0.),0.,1.),5.);"
"return i*d*r+i*pow(max(dot(m,f),0.),mix(128.,8.,l))*r*v;"
"return i*c*r+i*pow(max(dot(l,f),0.),mix(128.,8.,m))*r*v;"
"}"
"vec3 t(vec3 v,vec3 f,vec3 m,float l)"
"vec3 e(vec3 v,vec3 f,vec3 i,float n)"
"{"
"float n=.01;"
"vec3 y=vec3(0);"
"if(l==0.)"
"y=vec3(.8314,.2941,.2941),n=.1;"
"else if(l==1.)"
"y=vec3(.6196,.6118,.6118),n=.7;"
"else if(l==2.)"
"y=vec3(.3255,.4784,.3255),n=.2;"
"else if(l==3.)"
"y=vec3(.2471,.3059,.6314),n=1.;"
"else if(l==4.)"
"y=vec3(.9961,1,.9922),n=.1;"
"else if(l==5.)"
"y=vec3(.9961,1,.9922),n=.3;"
"float m=.01;"
"vec3 l=vec3(0);"
"if(n==0.)"
"l=vec3(.8314,.2941,.2941),m=.1;"
"else if(n==1.)"
"l=vec3(.6196,.6118,.6118),m=.7;"
"else if(n==2.)"
"l=vec3(.3255,.4784,.3255),m=.2;"
"else if(n==3.)"
"l=vec3(.2471,.3059,.6314),m=1.;"
"else if(n==4.)"
"l=vec3(.9961,1,.9922),m=.1;"
"else if(n==5.)"
"l=vec3(.9961,1,.9922),m=.3;"
"vec3 r=vec3(0);"
"r+=e(v,m,f,n);"
"for(float l=0.;l<16.;l++)"
"for(float y=0.;y<16.;y++)"
"for(float n=0.;n<16.;n++)"
"for(float l=0.;l<16.;l++)"
"{"
"ivec2 c=textureSize(d,0);"
"vec2 x=vec2(y,l)/vec2(c);"
"vec4 t=texture(d,x);"
"vec3 k=t.xyz;"
"float C=i[clamp(int(t.w/34.*512.),0,511)]*5.;"
"r+=e(vec3(k.x,k.y+C+3.,k.z),vec3(.46,.2,.94)+vec3(.66,.64,.77)*cos(6.28318*(C*1.5*vec3(.91,.62,.97)+vec3(.26,.2,.84))),clamp(C*3.,0.,1.),v,m,f,n);"
"ivec2 d=textureSize(c,0);"
"vec2 y=vec2(l,n)/vec2(d);"
"vec4 s=texture(c,y);"
"vec3 k=s.xyz;"
"float x=t(clamp(int(s.w/34.*512.),0,511));"
"r+=e(vec3(k.x,k.y+x+2.,k.z),vec3(.46,.2,.94)+vec3(.66,.64,.77)*cos(6.28318*(x*1.5*vec3(.91,.62,.97)+vec3(.26,.2,.84))),clamp(x*5.,0.,1.),v,i,f,m);"
"}"
"r+=vec3(.08,.62,.75)*clamp(dot(f,normalize(vec3(0,1,-3)*vec3(0,-1,-2))),0.,1.)*.8;"
"return y*max(vec3(0),r);"
"return l*max(vec3(0),r);"
"}"
"vec3 e(vec2 v,vec3 f)"
"vec3 e(vec2 i,vec3 v)"
"{"
"f=normalize(vec3(0,-1,10)-f);"
"vec3 n=normalize(cross(vec3(0,1,0),f));"
"return normalize(f+v.x*n+v.y*cross(f,n));"
"v=normalize(vec3(0,-1,10)-v);"
"vec3 n=normalize(cross(vec3(0,1,0),v));"
"return normalize(v+i.x*n+i.y*cross(v,n));"
"}"
"vec3 e(vec2 v)"
"{"
"vec3 f=vec3(-10,20,-20),n=e(v,f),l=vec3(0),d=vec3(0);"
"f=t(f,n,d);"
"if(f.x>0.)"
"vec3 n=vec3(-10,20,-20),l=e(v,n),f=vec3(0),m=vec3(0);"
"n=t(n,l,m);"
"if(n.x>0.)"
"{"
"vec3 v=e(d);"
"l=t(d,v,n,f.y);"
"vec3 v=e(m);"
"f=e(m,v,l,n.y);"
"}"
"return l;"
"return f;"
"}"
"void main()"
"{"
"vec3 v=e(gl_FragCoord.xy*vec2(.00104166667,.00185185185)-1.);"
"f=vec4(v,1);"
"vec3 n=e(gl_FragCoord.xy*vec2(.00104166667,.00185185185)-1.);"
"v=vec4(n,1);"
"}";
#endif // FRAGMENT_INL_