1 Commits

Author SHA1 Message Date
15afab09cb aaltogeneraattori(wip) 2025-07-19 18:38:36 +03:00
7 changed files with 611 additions and 935 deletions

View File

@ -606,6 +606,7 @@ shader_minifier.exe -v -o src\shaders\post.inl src\shaders\post.frag</Command>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Heavy Release|Win32'">true</ExcludedFromBuild>
</ClInclude>
<ClInclude Include="src\waveGenerator.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="src\editor.cpp">
@ -621,6 +622,7 @@ shader_minifier.exe -v -o src\shaders\post.inl src\shaders\post.frag</Command>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Snapshot|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="src\waveGenerator.cpp" />
</ItemGroup>
<ItemGroup>
<None Include="src\shaders\fragment.frag">

View File

@ -5,6 +5,7 @@
<ClCompile Include="src\song.cpp" />
<ClCompile Include="src\editor.cpp" />
<ClCompile Include="src\fft.cpp" />
<ClCompile Include="src\waveGenerator.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="src\debug.h" />
@ -19,6 +20,7 @@
<ClInclude Include="src\editor.h" />
<ClInclude Include="src\sointu\song.h" />
<ClInclude Include="src\fft.h" />
<ClInclude Include="src\waveGenerator.h" />
</ItemGroup>
<ItemGroup>
<None Include="src\shaders\post.inl">

View File

@ -30,6 +30,7 @@
#endif
#include "fft.h"
#include "waveGenerator.h"
#pragma data_seg(".pids")
// static allocation saves a few bytes
@ -127,6 +128,9 @@ int __cdecl main(int argc, char* argv[])
static float fft_output[FFT_SIZE / 2]; // Magnitudes
static float fft_uniform[FFT_SIZE / 4];
static float wave[WAVE_SIZE];
static float wave_uniform[WAVE_SIZE];
do
{
direct_sound_buffer->GetCurrentPosition((DWORD*)&playCursor, NULL);
@ -206,6 +210,24 @@ int __cdecl main(int argc, char* argv[])
glUniform1fvProc(0, SU_NUMSYNCS + 1, syncs);
glUniform1fvProc(8, FFT_SIZE / 4, fft_uniform);
/******************
* WAVE GENERATOR
*******************/
waveGenerator(syncs[4], wave);
for (int i = 0; i < (WAVE_SIZE); i++)
{
float gain = 1.2f;
float alpha = 0.15f; // "Hidastaa" FFT:n piikkej<65>
float threshhold = 0.1f; // Alin arvo mik<69> p<><70>stet<65><74>n shaderille (v<>hent<6E><74> "noisea")
float x_t = wave[i] * gain;
// Exponential smoothing kaava
// s(t) = alpha*x(t)+(1-alpha)*s(t-1)
wave_uniform[i] = (x_t < threshhold) ? 0.f : alpha * (x_t)+(1 - alpha) * wave_uniform[i];
}
glUniform1fvProc(1000, WAVE_SIZE, wave);
glRects(-1, -1, 1, 1);
//syncs[0] = -syncs[0];
@ -243,5 +265,11 @@ int __cdecl main(int argc, char* argv[])
lastPlayCursor = playCursor;
} while(!GetAsyncKeyState(VK_ESCAPE));
ExitProcess(0);
}

File diff suppressed because it is too large Load Diff

View File

@ -1,336 +1,183 @@
// 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_syncs "n"
# define VAR_fft_output "l"
# define VAR_o "i"
# define VAR_syncs "m"
# define VAR_wave "n"
const char *fragment_frag =
"#version 460\n"
"precision mediump float;"
"out vec4 v;"
"layout(location=0)uniform float n[7];"
"layout(location=8)uniform float f[512];"
"float m=n[0];\n"
"#define saturate(x)clamp(x,0.,1.)\n"
"#define dot2(x)dot(x,x)\n"
"float d=m*.25,s=sin(d)*.5+.7;"
"vec3 e=vec3(9.*cos(d),6.*abs(sin(d))/-.75+s,1);"
"float c=sin(d)*.075+.125;"
"vec3 x=vec3(1,.6,.3),o=vec3(.2,.01,.6),p=vec3(.95,.93,.88),l=vec3(.05),r=vec3(0,9,21);"
"struct Ray{vec3 origin,direction;};"
"struct Rect{vec3 center,side1,side2,side3,side4;vec3 up,right,front;vec2 halfSize;};"
"mat3 t()"
"out vec4 i;"
"const float f=2.*acos(-1.),v=sqrt(5.)*.5+.5;"
"layout(location=0)uniform float m[7];"
"layout(location=8)uniform float l[512];"
"layout(location=1000)uniform float n[512];"
"float x=m[0];"
"vec2 t()"
"{"
"float v=d;"
"return mat3(cos(v),-sin(v),0.,sin(v),cos(v),0.,0.,0.,1.);"
"vec2 i=2.*((gl_FragCoord.xy+vec2(0)*.5)/vec2(1920,1080)-.5);"
"i.x*=1;"
"return i;"
"}"
"vec3 t(vec3 v,float d)"
"float t(vec3 v,vec2 i)"
"{"
"vec3 f=vec3(0,1,0);"
"return f*cos(d)+cross(v,f)*sin(d)+v*dot(v,f)*(1.-cos(d));"
"v=abs(v);"
"return max(v.y-i.y,max(v.x*sqrt(3.)*.5+v.z*.5,v.z)-i.x);"
"}"
"mat3 t(vec3 v)"
"float t(vec3 v,float i)"
"{"
"v=normalize(vec3(0,1,0)-v);"
"vec3 d=normalize(cross(v,vec3(0,1,0)));"
"return mat3(d,normalize(cross(d,v)),v);"
"return length(v)-i;"
"}"
"Ray t(vec2 v)"
"mat2 e()"
"{"
"vec3 d=r;"
"return Ray(d,normalize(t(d)*vec3(v,2.5)));"
"float v=x*2.,i=sin(v);"
"v=cos(v);"
"return mat2(v,-i,i,v);"
"}"
"void t(out Rect v)"
"float e(int v)"
"{"
"float f=d;"
"v.up=vec3(0,0,1);"
"v.right=vec3(1,0,0);"
"v.front=normalize(cross(v.right,v.up));"
"v.halfSize=vec2(2.5,1.5)*(vec2(cos(f),sin(f))*.25+.75);"
"v.center=vec3(0,6,sin(f)*4.-1.5);"
"v.side1=v.center+v.halfSize.x*v.right+v.halfSize.y*v.up;"
"v.side2=v.center-v.halfSize.x*v.right+v.halfSize.y*v.up;"
"v.side3=v.center-v.halfSize.x*v.right-v.halfSize.y*v.up;"
"v.side4=v.center+v.halfSize.x*v.right-v.halfSize.y*v.up;"
"v=clamp(v,0,511);"
"float i=n[v];"
"return log(1.+i*15.);"
"}"
"float t(vec3 v,vec3 d,vec3 f,vec3 i,vec3 c)"
"vec2 e(vec3 v)"
"{"
"v=normalize(cross(d,f));"
"f=normalize(cross(f,i));"
"i=normalize(cross(i,c));"
"d=normalize(cross(c,d));"
"return acos(dot(-v,f))+acos(dot(-f,i))+acos(dot(-i,d))+acos(dot(-d,v))-2.*acos(-1.);"
"}"
"vec3 R,y;"
"Rect i;"
"vec2 t(vec2 v,vec2 i)"
"{"
"return v.x<i.x?"
"v:"
"i;"
"}"
"float h(vec3 v)"
"{"
"return v.y+.75;"
"}"
"float h(vec3 v,vec3 d,float f)"
"{"
"return length(v-d)-f;"
"}"
"float h(vec3 v,vec3 d,vec3 f)"
"{"
"v-=d;"
"d=f-d;"
"float y=saturate(dot(v,d)/dot(d,d));"
"return length(v-d*y)-c;"
"}"
"float h(vec3 v,vec3 f,vec3 d,vec3 i,vec3 y)"
"{"
"vec3 x=d-f,s=v-f,c=i-d,n=v-d,R=y-i;"
"i=v-i;"
"d=f-y;"
"f=v-y;"
"v=cross(x,d);"
"return sqrt(sign(dot(cross(x,v),s))+sign(dot(cross(c,v),n))+sign(dot(cross(R,v),i))+sign(dot(cross(d,v),f))<3.?"
"min(min(min(dot2(x*clamp(dot(x,s)/dot2(x),0.,1.)-s),dot2(c*clamp(dot(c,n)/dot2(c),0.,1.)-n)),dot2(R*clamp(dot(R,i)/dot2(R),0.,1.)-i)),dot2(d*clamp(dot(d,f)/dot2(d),0.,1.)-f)):"
"dot(v,s)*dot(v,s)/dot2(v));"
"}"
"vec2 w(vec3 v)"
"{"
"vec2 d=t(t(t(t(t(vec2(h(v),3),vec2(h(v,vec3(-4.5,.75,0),1.5),1.05)),vec2(h(v,vec3(-1.5,.75,0),1.5),1.25)),vec2(h(v,vec3(1.5,.75,0),1.5),1.45)),vec2(h(v,vec3(4.5,.75,0),1.5),1.65)),vec2(h(v,e,s),0));"
"d=t(d,vec2(h(v,R,y),0));"
"return t(d,vec2(h(v,i.side1,i.side2,i.side3,i.side4),0));"
"}"
"vec2 a(vec3 v)"
"{"
"return t(t(t(t(vec2(v.y+.75,3),vec2(h(v,vec3(-4.5,.75,0),1.5),1.05)),vec2(h(v,vec3(-1.5,.75,0),1.5),1.25)),vec2(h(v,vec3(1.5,.75,0),1.5),1.45)),vec2(h(v,vec3(4.5,.75,0),1.5),1.65));"
"}"
"vec2 u(vec3 v)"
"{"
"return t(t(t(t(vec2(h(v),3),vec2(h(v,vec3(-4.5,.75,0),1.5),1.05)),vec2(h(v,vec3(-1.5,.75,0),1.5),1.25)),vec2(h(v,vec3(1.5,.75,0),1.5),1.45)),vec2(h(v,vec3(4.5,.75,0),1.5),1.65));"
"}"
"vec3 C(vec3 v)"
"{"
"vec2 i=vec2(2e-4,0);"
"return normalize(vec3(a(v+i.xyy).x,a(v+i.yxy).x,a(v+i.yyx))-a(v).x);"
"}"
"vec2 C(Ray v)"
"{"
"float d=0.;"
"vec2 f=vec2(-1);"
"for(int i=0;i<128;++i)"
"float i=0.,f=1e9,m=0.;"
"vec2 n=vec2(7);"
"m=t(vec3(v.x,v.y-16.,v.z-10.),2.);"
"f=min(f,m);"
"if(f==m)"
"i=1.;"
"vec3 l=vec3(v.x,v.y-16.,v.z-10.);"
"l.xy=e()*l.xy;"
"m=t(vec3(l.x+4.,l.yz),.2),f=min(f,m);"
"if(f==m)"
"i=1.;"
"m=t(vec3(l.x-4.,l.yz),.2),f=min(f,m);"
"if(f==m)"
"i=1.;"
"m=t(vec3(l.x,l.y+4.,l.z),.2),f=min(f,m);"
"if(f==m)"
"i=1.;"
"m=t(vec3(l.x,l.y-4.,l.z),.2),f=min(f,m);"
"if(f==m)"
"i=1.;"
"for(float l=0.;l<16.;l++)"
"{"
"f=w(v.origin+v.direction*d);"
"if(f.x<2e-4*d||d>=1e2)"
"break;"
"d+=f.x;"
"}"
"if(d>=1e2)"
"f.y=-1.;"
"return vec2(d,f.y);"
"}"
"vec2 a(Ray v)"
"{"
"float d=0.;"
"vec2 f=vec2(-1);"
"for(int i=0;i<64;++i)"
"{"
"f=u(v.origin+v.direction*d);"
"if(f.x<2e-4*d||d>=1e2)"
"break;"
"d+=f.x;"
"}"
"if(d>=1e2)"
"f.y=-1.;"
"return vec2(d,f.y);"
"}\n"
"#if 1\n"
"float h(Ray v)"
"{"
"float d=1.,f=0.;"
"for(int i=0;i<64;++i)"
"{"
"vec2 c=u(v.origin+v.direction*f);"
"if(c.y>0.)"
"vec3 x=v+vec3(1.8*8,-5,-2.08*10)+vec3(0,0,2.08*l);"
"for(float v=0.;v<16.;v++)"
"{"
"d=min(d,.5+.5*c.x/(.125*f));"
"if(d<0.)"
"break;"
"f+=clamp(c.x,.005,.5);"
"x=mod(v,2.)==0.?"
"x-vec3(1.8,0,1):"
"x+vec3(-1.8,0,1);"
"int y=int(length(vec2(v,l)-n.xy));"
"m=t(x,vec2(.86,1.+e(y)*2.));"
"f=min(f,m);"
"if(f==m)"
"i=1.;"
"}"
"}"
"return smoothstep(0.,1.,max(d,0.));"
"}\n"
"#else\n"
"float h(Ray v)"
"return vec2(f,i);"
"}"
"vec3 e(vec3 v,vec3 i,inout vec3 f)"
"{"
"float f=0.;"
"for(int d=0;d<64;++d)"
"float m=0.,l=0.,y=0.;"
"for(int r=0;r<30;r++)"
"{"
"float i=u(v.origin+v.direction*f).x;"
"if(i<2e-4)"
"return 0.;"
"f+=i;"
"}"
"return 1.;"
"}\n"
"#endif\n"
"float C(float v,float d,float f)"
"{"
"d*=d;"
"return f*f*d/pow(v*v*(d-1.)+1.,2.);"
"}"
"float a(float v,float d,float f)"
"{"
"d*=d;"
"return d*f/pow(v*v*(d-1.)+1.,2.);"
"}"
"float h(float v,float d,float f)"
"{"
"d*=d;"
"return f*f*f*d/pow(v*v*(d-1.)+1.,2.);"
"}"
"float C(float v,float d)"
"{"
"return v/max(v*(1.-d)+d,2e-7);"
"}"
"float t(float v,float d,float f)"
"{"
"f+=1.;"
"f=f*f/8.;"
"return C(v,f)*C(d,f);"
"}"
"vec3 C(vec3 v,float d)"
"{"
"return v+(1.-v)*pow(1.-d,5.);"
"}"
"vec2 a(float v,float d)"
"{"
"vec4 i=v*vec4(-1,-.0275,-.572,.022)+vec4(1,.0425,1.04,-.04);"
"return vec2(-1.04,1.04)*(min(i.x*i.x,exp2(-9.28*d))*i.x+i.y)+i.zw;"
"}"
"vec4 C(vec3 v,vec3 d,vec3 f,vec3 i,vec3 c,float x,float n,float R,out vec3 r,out float y)"
"{"
"vec3 m=e-v,o=dot(m,i)*i-m;"
"i=m+o*saturate(s/length(o));"
"o=normalize(i);"
"m=normalize(f+o);"
"R=length(i);"
"float p=max(dot(d,o),0.);"
"y=pow(saturate(1.-pow(R/20.,4.)),2.)/(R*R+1.);"
"y*=h(Ray(v+d*2e-4,o));"
"float a=n*n;"
"R=saturate(a+s/(2.*R));"
"r=C(c,max(dot(m,f),0.));"
"m=C(max(dot(d,m),0.),a,R)*t(x,p,n)*r;"
"return vec4(m,p);"
"}"
"vec4 a(vec3 v,vec3 d,vec3 f,vec3 i,vec3 x,float m,float n,float s,out vec3 r,out float o)"
"{"
"vec4 e=vec4(0);"
"vec3 p=R-v,l=y-v;"
"s=length(p);"
"float w=length(l);"
"e.w=2.*saturate(dot(d,p)/(2.*s)+dot(d,l)/(2.*w))/(s*w+dot(p,l)+2.);"
"l-=p;"
"w=dot(i,l);"
"s=length(l);"
"vec3 z=p+l*saturate((dot(i,p)*w-dot(p,l))/(s*s-w*w));"
"i=dot(z,i)*i-z;"
"z+=i*saturate(c/length(i));"
"i=normalize(f+normalize(z));"
"w=length(z);"
"s=w/20.;"
"o=1./(s*s+1.);"
"o*=h(Ray(v+d*2e-4,normalize(p+l*.5)));"
"s=n*n;"
"w=saturate(s+c/(2.*w));"
"r=C(x,dot(i,f));"
"e.xyz=a(max(dot(d,i),0.),s,w)*t(m,e.w,n)*r;"
"return e;"
"}"
"vec4 h(vec3 v,vec3 d,vec3 f,vec3 s,vec3 c,float x,float n,float R,out vec3 r,out float y)"
"{"
"vec4 e=vec4(0);"
"R=dot(cross(i.right,i.up),i.center-v);"
"if(R>0.)"
"return e;"
"vec3 m=i.side1-v,o=i.side2-v,p=i.side3-v,l=i.side4-v;"
"e.w=t(v,m,o,p,l)*.2*(saturate(dot(normalize(m),d))+saturate(dot(normalize(o),d))+saturate(dot(normalize(p),d))+saturate(dot(normalize(l),d))+saturate(dot(normalize(i.center-v),d)));"
"y=h(Ray(v+d*2e-4,normalize(i.center)));"
"Ray w=Ray(v,s);"
"m=w.origin+w.direction*(dot(i.front,i.center-w.origin)/dot(i.front,w.direction))-i.center;"
"vec2 z=vec2(dot(m,i.right),dot(m,i.up));"
"z=min(abs(z),i.halfSize)*sign(z);"
"m=i.center+i.right*z.x+i.up*z.y-v;"
"o=normalize(f+normalize(m));"
"R=n*n;"
"float a=saturate(R+4./(2.*length(m)));"
"r=C(c,dot(o,f));"
"e.xyz=h(max(dot(d,o),0.),R,a)*t(x,e.w,n)*r;"
"return e;"
"}"
"vec3 t(Ray v)"
"{"
"vec3 f=vec3(2,0,0)*t(),s=vec3(6.*sin(d),3,5);"
"R=s-f;"
"y=s+f;"
"t(i);"
"f=vec3(0);"
"vec2 c=C(v);"
"s=v.origin+v.direction*c.x;"
"vec3 m=C(s),n=-v.direction,e=reflect(v.direction,m);"
"float w=max(dot(m,n),0.);"
"vec3 r=o;"
"float z=fract(c.y),F=.88;"
"vec3 u=p;"
"if(c.y>-1.)"
"{"
"if(c.y>2.)"
"r=vec3(.31,.62,.47),z=max(.05,r.x*.5),F=.05,u=l;"
"else if(c.y<.5)"
"return x*64.;"
"vec3 v=mix(u,r,F),d=vec3(0);"
"float i=1.;"
"vec4 R=C(s,m,n,e,v,w,z,F,d,i);"
"d=(1.-d)*(1.-F);"
"vec3 y=vec3(0);"
"float p=1.;"
"vec4 g=a(s,m,n,e,v,w,z,F,y,p);"
"y=(1.-y)*(1.-F);"
"vec3 b=vec3(0);"
"float A=1.;"
"vec4 B=h(s,m,n,e,v,w,z,F,b,A);"
"b=(1.-b)*(1.-F);"
"f=f+(d*.3183098861*r+R.xyz)*256.*R.w*i+(y*.3183098861*r+g.xyz)*512.*g.w*p+(b*.3183098861*r+B.xyz)*64.*B.w*A+r*.025;"
"A=z*z;"
"b=vec3(.1125,.1875,.25)+e.y*.35;"
"Ray D=Ray(s,vec3(0));"
"for(int v=0;v<8;++v)"
"f=v+i*m;"
"vec2 n=e(f);"
"m+=n.x*1.2;"
"l=n.y;"
"if(m>1e2)"
"break;"
"if(n.x<.001*m)"
"{"
"float d=float(v)/float(8);"
"D.direction=normalize(t(e,2.*acos(-1.)*d)*A+e);"
"vec2 i=a(D);"
"if(floor(i.y)==3.)"
"b=vec3(.1,.3,.2);"
"else if(floor(i.y)==1.)"
"b+=o;"
"y=1.;"
"break;"
"}"
"b/=float(8);"
"vec2 E=a(z,w);"
"b=b*(v*E.x+E.y)+max(vec3(.754554516862612,.748542953903366,.790921515418539)+vec3(-.083856548007422,.09253350096321,.322764661032516)*m.y+vec3(.308152705331738,.366796330467391,.466698181299906)*m.z+vec3(-.188884931542396,-.277402551592231,-.377844212327557)*m.x,0.)*.3183098861*r;"
"f=(f+b*.84)*x;"
"}"
"return mix(f,vec3(.01,.006,.004),clamp(1.-exp(-c.x*.08),0.,1.));"
"if(m>1e2)"
"m=0.;"
"return vec3(m,l,y);"
"}"
"float e(vec3 v,vec3 m,float i)"
"{"
"float f=1.,l=.02;"
"for(int r=0;r<6;r++)"
"{"
"if(l>i)"
"break;"
"float x=e(v+l*m).x;"
"f=min(f,x/(4.*l));"
"l+=clamp(x,.1,.8);"
"if(f<-1.)"
"break;"
"}"
"f=max(f,-1.);"
"return.25*(1.+f)*(1.+f)*(2.-f);"
"}"
"vec3 t(vec3 v)"
"{"
"vec2 i=vec2(.01,0);"
"return normalize(vec3(e(v+i.xyy).x-e(v-i.xyy).x,e(v+i.yxy).x-e(v-i.yxy).x,e(v+i.yyx).x-e(v-i.yyx).x));"
"}"
"vec3 e(vec3 v,vec3 f,vec3 m,vec3 i,vec3 x,float l)"
"{"
"v-=m;"
"float r=length(v);"
"v=normalize(v);"
"float n=3./(1.+.09*r+.032*r*r),y=max(dot(x,v),0.);"
"i=normalize(v-i);"
"vec3 z=vec3(.04);"
"z+=(1.-z)*pow(clamp(1.-max(dot(i,v),0.),0.,1.),5.);"
"r=e(m+x*.01,v,r);"
"return(f*y*n+f*pow(max(dot(x,i),0.),mix(128.,8.,l))*n*z)*r;"
"}"
"vec3 e(vec3 v,vec3 f,vec3 i,float m)"
"{"
"float l=.01;"
"vec3 x=vec3(0);"
"if(m==0.)"
"x=vec3(.8314,.2941,.2941),l=.1;"
"else if(m==1.)"
"x=vec3(.6196,.6118,.6118),l=.7;"
"else if(m==2.)"
"x=vec3(.3255,.4784,.3255),l=.2;"
"else if(m==3.)"
"x=vec3(.2471,.3059,.6314),l=1.;"
"else if(m==4.)"
"x=vec3(.9961,1,.9922),l=.1;"
"else if(m==5.)"
"x=vec3(.9961,1,.9922),l=.3;"
"v=vec3(0)+e(vec3(-10,10,0),vec3(.77,.26,.73),v,i,f,l)+e(vec3(0,10,-5),vec3(.08,.62,.75),v,i,f,l)+e(vec3(0,25,0),vec3(.5137,.1961,.7725),v,i,f,l)+vec3(.08,.62,.75)*clamp(dot(f,normalize(vec3(0,1,-3)*vec3(0,-1,-2))),0.,1.)*.8;"
"return x*max(vec3(0),v);"
"}"
"vec3 e(vec2 v,vec3 f)"
"{"
"f=normalize(vec3(0,10,10)-f);"
"vec3 m=normalize(cross(vec3(0,1,0),f));"
"return normalize(v.x*m+v.y*normalize(cross(f,m))+f);"
"}"
"vec3 d()"
"{"
"return vec3(0,30,25);"
"}"
"vec3 d(vec2 v)"
"{"
"vec3 f=e(v,d()),i=vec3(.102,.2431,.3412),m=vec3(0),l=e(d(),f,m);"
"if(l.x>0.)"
"{"
"vec3 v=t(m);"
"i=e(m,v,f,l.y);"
"}"
"return i;"
"}"
"void main()"
"{"
"vec2 d=vec2(1920,1080);"
"d=(2.*gl_FragCoord.xy-d.xy)/d.y;"
"Ray f=t(d);"
"vec3 i=t(f);"
"v=vec4(i,1);"
"vec3 v=d(t());"
"i=vec4(v,1);"
"}";
#endif // FRAGMENT_INL_

87
src/waveGenerator.cpp Normal file
View File

@ -0,0 +1,87 @@
#include "waveGenerator.h"
#include <cmath>
const float DECAY_FACTOR = 0.80f; // Amplitude decay per iteration
const float PI = 3.14159265f;
const float WAVE_LENGTH = 3.0f;
const float WAVE_SPEED = 0.5f;
const int speed = 1;
float waveOffset = 0.0f;
float temp[WAVE_SIZE] = { 0.0f }; // Temp buffer for propagation
//float wave[WAVE_SIZE] = { 0.0f }; // Wave buffer
float clamp(float value) {
if (value > 4.f) {
value = 4.f;
}
if (value < 0.f) {
value = 0.f;
}
return value;
}
// Generate a sine wave into the beginning of the array
void generateSineWave(float amplitude, float* wave) {
for (int i = 0; i < WAVE_SIZE; ++i) {
float sine = std::sin(2.0f * PI * i / WAVE_LENGTH);
float sample = 1.0f + sine;
wave[i] = clamp(sample * amplitude);
}
}
// Shift wave and apply decay
void propagateWave(float* wave) {
for (int i = WAVE_SIZE - 1; i >= speed; --i) {
wave[i] = wave[i - speed] * DECAY_FACTOR;
}
// Decay the front section that no longer receives new values
for (int i = 0; i < speed; ++i) {
wave[i] = wave[i] * DECAY_FACTOR;
}
}
/*
void propagateWave(float* wave) {
waveOffset += WAVE_SPEED;
for (int i = 0; i < WAVE_SIZE; ++i) {
float srcIndex = i - waveOffset;
if (srcIndex < 0 || srcIndex >= WAVE_SIZE - 1) {
temp[i] = 0.0f;
}
else {
int index0 = srcIndex - (srcIndex < 0 && srcIndex != (int)srcIndex);
int index1 = index0 + 1;
float t = srcIndex - index0;
float value = (1.0f - t) * wave[index0] + t * wave[index1];
temp[i] = clamp(value * DECAY_FACTOR);
}
}
//// Copy temp back to wave
for (int i = 0; i < WAVE_SIZE; ++i) {
wave[i] = temp[i];
}
//// Prevent offset overflow
if (waveOffset >= 1.0f) {
waveOffset -= waveOffset - (waveOffset < 0 && srcIndex != (int)srcIndex);
}
}
*/
void waveGenerator(float sound, float* wave) {
generateSineWave(sound, wave);
propagateWave(wave);
}

7
src/waveGenerator.h Normal file
View File

@ -0,0 +1,7 @@
#pragma once
#include <cmath>
#define WAVE_SIZE 512
void generateSineWave(float amplitude, float* wave);
void propagateWave(float* wave);
void waveGenerator(float sound, float* wave);