Files
2026-04-18 22:31:51 +02:00

619 lines
20 KiB
C

/* File generated with Shader Minifier 1.1.3
* http://www.ctrl-alt-test.fr
*/
#ifndef SHADER_H_
# define SHADER_H_
const char test_hlsl[] = {
"#define ParticleType_Dead 0\n"
"#define ParticleType_Emitter 1\n"
"#define ParticleType_Point 2\n"
"#define ParticleType_Star 3\n"
"#define SDF_SIMILARITY 2.0\n"
"#define TANGENT_SPEED 8.0\n"
"#define GRADIENT_SPEED 8.0\n"
"RWTexture2D<float4> out0:register(u0);"
"SamplerState sampler0:register(s0);"
"Texture2D tex0:register(t0),tex1:register(t1),tex2:register(t2),tex3:register(t3),tex4:register(t4),tex5:register(t5),tex6:register(t6),tex7:register(t7);struct ParticleState{int type;float3 oldPosition;float3 currentPosition;float3 direction;float3 tangent;float creationTime;float mass;float lifeTime;};cbuffer _0:register(b0){float4 smoothNoiseColor;float4 colorBlend;float3 smoothNoiseDirection;float demoTime;float3 emitterDirection;float deltaTime;float3 emitterPosition;float emitterRadius;float3 cameraPosition;float emitRate;float3 cameraLookat;float lifeTime;float3 cameraUp;float gravity;float3 emitterVelocity;float emitChaos;float emitterMass;float sdfBlendFactor;float smoothNoiseSize;float particleMass;float envelope1;float envelope2;float distort;float note;};struct __1{float4 _d:_dS;float4 _c:_cS;float4x4 _v:_vS;float4x4 _p:_pS;};cbuffer _1:register(b1){__1 _o;};cbuffer _2:register(b2){__1 _c;};"
"float4x4 lookTo(float3 Eye,float3 zaxis,float3 Up)"
"{"
"float3 xaxis=normalize(cross(Up,zaxis)),yaxis=cross(zaxis,xaxis);"
"float4x4 result={xaxis,-dot(xaxis,Eye),yaxis,-dot(yaxis,Eye),zaxis,-dot(zaxis,Eye),0,0,0,1};"
"return transpose(result);"
"}"
"__1 VSCB()"
"{"
"__1 o;"
"float3 direction=normalize(cameraLookat-cameraPosition);"
"o._v=lookTo(cameraPosition,direction,normalize(cameraUp));"
"o._d=float4(direction,0);"
"o._c=float4(cameraPosition,0);"
"o._p=float4x4(1,0,0,0,0,1,0,0,0,0,1,1,0,0,-1,0);"
"return o;"
"}\n"
"#define PI 3.14159265\n"
"static uint rndSeed=0;"
"static const float starThreshold=20.f;"
"uint hash(uint x)"
"{"
"return x+=x<<10,x^=x>>6,x+=x<<3,x^=x>>11,x+=x<<15,x;"
"}"
"void setRndSeed(uint seed)"
"{"
"rndSeed=seed;"
"}"
"float rnd()"
"{"
"return asfloat((rndSeed=hash(rndSeed)&8388607)|1065353216)-1;"
"}"
"float srnd()"
"{"
"return asfloat((rndSeed=hash(rndSeed)&8388607)|1073741824)-3;"
"}"
"float rnd(uint s)"
"{"
"return asfloat(s&8388607|1065353216)-1;"
"}"
"float srnd(uint s)"
"{"
"return asfloat(s&8388607|1073741824)-3;"
"}"
"static const float2x2 mtx=float2x2(.8,.6,-.6,.8);"
"float noise(float2 p)"
"{"
"uint idx=(uint)(floor(p.y)*1024+floor(p.x));"
"return rnd(hash(idx));"
"}"
"float fbm4(float2 p)"
"{"
"float f=0.;"
"f+=.5*noise(p);"
"p=mul(p*2.02,mtx);"
"f+=.25*noise(p);"
"p=mul(p*2.03,mtx);"
"f+=.125*noise(p);"
"p=mul(p*2.01,mtx);"
"f+=.0625*noise(p);"
"return f/.9375;"
"}"
"[numthreads(16,16,1)]"
"void csNoise(int3 id:SV_DispatchThreadID)"
"{"
"float2 v=float2(id.x,id.y);"
"out0[id.xy]=float4(noise(v),0,0,1);"
"}"
"[numthreads(16,16,1)]"
"void csFbm(int3 id:SV_DispatchThreadID)"
"{"
"float2 v=float2(id.x,id.y)/1024.;"
"float f=0.,scale=.5,sum=0.,mag=.25;"
"for(int i=6;i>=0;--i)"
"f+=scale*tex0.SampleLevel(sampler0,v,i).x,sum+=scale,v=mul(v*(1.+.01*i),mtx),scale*=.5,mag*=2.;"
"out0[id.xy]=float4(mag*(f/sum-.5)+.5,0,0,1);"
"}"
"ConsumeStructuredBuffer<ParticleState> particles:register(u0);"
"AppendStructuredBuffer<ParticleState> writeParticles:register(u1);"
"StructuredBuffer<ParticleState> readParticles:register(t0);"
"void emit(int type,float3 oldPosition,float3 position,float3 direction,float mass,float time)"
"{"
"ParticleState emittedParticle;"
"emittedParticle.type=type;"
"emittedParticle.oldPosition=oldPosition;"
"emittedParticle.currentPosition=position;"
"emittedParticle.creationTime=time;"
"emittedParticle.direction=direction;"
"emittedParticle.mass=mass;"
"emittedParticle.lifeTime=lifeTime;"
"emittedParticle.tangent=normalize(float3(srnd(),srnd(),srnd()));"
"writeParticles.Append(emittedParticle);"
"}"
"void recycle(ParticleState particle)"
"{"
"ParticleState newParticle;"
"newParticle.type=particle.type;"
"newParticle.oldPosition=particle.currentPosition;"
"newParticle.currentPosition=particle.currentPosition+particle.direction*abs(deltaTime);"
"newParticle.creationTime=particle.creationTime;"
"newParticle.direction=particle.direction+float3(0,gravity*particle.mass,0)*abs(deltaTime);"
"newParticle.mass=particle.mass;"
"newParticle.lifeTime=particle.lifeTime;"
"newParticle.tangent=particle.tangent;"
"writeParticles.Append(newParticle);"
"}"
"void emitStar()"
"{"
"float3 pos=cameraPosition+sqrt(rnd())*starThreshold*normalize(float3(srnd(),srnd(),srnd()));"
"emit(ParticleType_Star,pos,pos,float3(.1,0.,.1),0.f,0.f);"
"}"
"[numthreads(1,1,1)]"
"void starInit(int3 id:SV_DispatchThreadID)"
"{"
"rndSeed=id.y*256+id.x,emitStar();"
"}"
"float sdSphere(float3 p)"
"{"
"return p/=5,length(p)-1.;"
"}"
"float sdIso1(float3 p)"
"{"
"p/=5;"
"float A=p.x*p.x+p.y*p.y+p.z*p.z-1,B=p.z-1,C=p.z+1;"
"return A*A-(B*B-2*p.x*p.x)*(C*C-2*p.y*p.y);"
"}"
"float sdIso2(float3 p)"
"{"
"return cos(p.x)+cos(p.y)+cos(p.z);"
"}"
"float sdIso3(float3 p)"
"{"
"return sin(p.x)*sin(p.y)*sin(p.z)+sin(p.x)*cos(p.y)*cos(p.z)+cos(p.x)*sin(p.y)*cos(p.z)+cos(p.x)*cos(p.y)*sin(p.z);"
"}"
"float sdBox(float3 p,float3 b)"
"{"
"float3 d=abs(p)-b;"
"return min(max(d.x,max(d.y,d.z)),0.)+length(max(d,0.));"
"}"
"float mengerSponge(float3 p)"
"{"
"p/=3;"
"float d=sdBox(p,float3(1.,1.,1.)),s=1.;"
"for(int m=0;m<3;m++)"
"{"
"float3 a=sign(p)*fmod(p*s,2.)-1.;"
"s*=3.;"
"float3 r=abs(1.-3.*abs(a));"
"float da=max(r.x,r.y),db=max(r.y,r.z),dc=max(r.z,r.x),c=(min(da,min(db,dc))-1.)/s;"
"d=max(d,c);"
"}"
"return d;"
"}"
"float f(float3 p)"
"{"
"float sdfType=floor(sdfBlendFactor),sphere=step(0,sdfType)*(1-step(1,sdfType)),iso1=step(1,sdfType)*(1-step(2,sdfType)),iso2=step(2,sdfType)*(1-step(3,sdfType)),iso3=step(3,sdfType)*(1-step(4,sdfType)),menger=step(4,sdfType)*(1-step(5,sdfType));"
"return sdSphere(p)*sphere+sdIso1(p)*iso1+sdIso2(p)*iso2+sdIso3(p)*iso3+mengerSponge(p)*menger;"
"}"
"void doEmitter(float3 particlePosition,float3 particleDirection,float t)"
"{"
"if(demoTime-t>=emitRate)"
"{"
"float count=ceil((demoTime-t)/emitRate),index=count-1;"
"while(t<=demoTime)"
"{"
"float3 tangent=normalize(float3(srnd(),srnd(),srnd()));"
"if(length(emitterDirection)>0.f)"
"tangent=cross(normalize(emitterDirection),tangent);"
"float3 emitDirection=emitterDirection+emitChaos*normalize(float3(srnd(),srnd(),srnd())),newPosition=particlePosition+tangent*sqrt(rnd())*emitterRadius;"
"emit(ParticleType_Point,newPosition,newPosition+emitDirection*deltaTime*(index--/count),emitDirection,particleMass,t);"
"particlePosition+=particleDirection*emitRate;"
"t+=emitRate;"
"}"
"}"
"}"
"void doUpdate(int3 id:SV_DispatchThreadID,bool bPreserveEmitters)"
"{"
"rndSeed=(id.y*1024+id.x)*demoTime;"
"ParticleState particle=particles.Consume();"
"if(particle.type==ParticleType_Emitter)"
"{"
"float t=particle.creationTime;"
"doEmitter(particle.currentPosition,particle.direction,t);"
"if(bPreserveEmitters)"
"emit(ParticleType_Emitter,particle.currentPosition,particle.currentPosition+particle.direction*abs(deltaTime),particle.direction,particle.mass,demoTime);"
"}"
"else"
" if(particle.type==ParticleType_Point)"
"{"
"float age=(demoTime-particle.creationTime)/particle.lifeTime;"
"uint index;"
"float2 e=float2(.001,0);"
"float3 p=particle.currentPosition;"
"float d=f(p);"
"float3 v=-normalize(float3(f(p+e.xyy)-f(p-e.xyy),f(p+e.yxy)-f(p-e.yxy),f(p+e.yyx)-f(p-e.yyx))),t=cross(particle.tangent,v);"
"v=TANGENT_SPEED*t/(1+pow(abs(d),.5))+GRADIENT_SPEED*v*d*(.5+.5*step(0,-d));"
"v=lerp(particle.direction,v,SDF_SIMILARITY*GRADIENT_SPEED*deltaTime*frac(sdfBlendFactor));"
"particle.direction=v;"
"if(age<=1)"
"recycle(particle);"
"}"
"else"
" if(particle.type==ParticleType_Star)"
"{"
"if(distance(particle.currentPosition,cameraPosition)>starThreshold)"
"emitStar();"
"else"
" recycle(particle);"
"}"
"if(id.x+id.y==0&&note>.1)"
"{"
"rndSeed=1337*demoTime;"
"float3 emitPosition=cameraPosition,cameraDirection=normalize(cameraLookat-cameraPosition),cameraRight=cross(normalize(cameraUp),cameraDirection);"
"emitPosition+=10*cameraDirection;"
"emitPosition-=7*normalize(cameraUp);"
"emitPosition+=(50*note-25)*cameraRight;"
"float t=demoTime-deltaTime;"
"doEmitter(emitPosition,float3(0,0.,0),t);"
"}"
"}"
"[numthreads(1,1,1)]"
"void update(int3 id:SV_DispatchThreadID)"
"{"
"doUpdate(id,true);"
"}"
"[numthreads(1,1,1)]"
"void event1(int3 id:SV_DispatchThreadID)"
"{"
"doUpdate(id,false);"
"}"
"[numthreads(1,1,1)]"
"void event2(int3 id:SV_DispatchThreadID)"
"{"
"doUpdate(id,true);"
"if(id.x+id.y==0)"
"emit(ParticleType_Emitter,emitterPosition,emitterPosition,emitterVelocity,emitterMass,demoTime);"
"}"
"float3 project(float3 v,bool bOld)"
"{"
"float4 r;"
"if(bOld)"
"r=mul(mul(float4(v,1.),_o._v),_o._p);"
"else"
" r=mul(mul(float4(v,1.),_c._v),_c._p);"
"r.x/=1.6;"
"return r.xyz/r.w;"
"}"
"float3 h2r(float h,float s,float v)"
"{"
"return lerp(saturate(abs(frac(h+float3(1,2,3)/3)*6-3)-1),1,s)*v;"
"}struct _2{float3 pos1:TEXCOORD0;float3 pos2:TEXCOORD1;float3 dir:TEXCOORD2;float age:AGE;int type:TYPE;};struct _3{float4 pos:SV_POSITION;float length:LENGTH;float age:AGE;float3 wpos:WORLDPOS;int type:TYPE;};"
"void pvs(uint id:SV_VertexID,out _2 o)"
"{"
"ParticleState particle=readParticles[id];"
"o.pos1=particle.oldPosition;"
"o.pos2=particle.currentPosition;"
"o.dir=particle.direction;"
"o.age=(demoTime-particle.creationTime)/lifeTime;"
"o.type=particle.type;"
"}"
"float particleSize(float z)"
"{"
"return(1+2*envelope1)*.002f/z;"
"}"
"[maxvertexcount(18)]"
"void pgs(point _2 input[1],inout TriangleStream<_3> o)"
"{"
"_2 p=input[0];"
"float3 p1=project(p.pos1,false),p2=project(p.pos2,false);"
"if(p2.z<=0||p1.z<=0)"
"return;"
"float s1=min(.01,particleSize(p1.z)),s2=min(.01,particleSize(p2.z));"
"float2 d=normalize(p2.xy-p1.xy);"
"d+=(1.-step(.5,length(float3(d,0))))*normalize(project(p.dir,false).xy);"
"d+=(1.-step(.5,length(float3(d,0))))*float2(1,0);"
"float2 pr=float2(-d.y,d.x);"
"p1.xy+=d*s1*.5;"
"p2.xy-=d*s2*.5;"
"_3 r;"
"r.length=distance(p1.xy,p2.xy)*128;"
"r.age=p.age;"
"r.type=p.type;"
"r.wpos=p.pos2;"
"r.pos=float4(p1.xy-d*s1,p1.z,1.);"
"o.Append(r);"
"r.pos=float4(p1.xy+pr*s1,p1.z,1.);"
"o.Append(r);"
"r.pos=float4(p1.xy-pr*s1,p1.z,1.);"
"o.Append(r);"
"o.RestartStrip();"
"r.pos=float4(p1.xy-pr*s1,p1.z,1.);"
"o.Append(r);"
"r.pos=float4(p1,1.);"
"o.Append(r);"
"r.pos=float4(p2.xy-pr*s2,p2.z,1.);"
"o.Append(r);"
"o.RestartStrip();"
"r.pos=float4(p1,1.);"
"o.Append(r);"
"r.pos=float4(p2,1.);"
"o.Append(r);"
"r.pos=float4(p2.xy-pr*s2,p2.z,1.);"
"o.Append(r);"
"o.RestartStrip();"
"r.pos=float4(p1,1.);"
"o.Append(r);"
"r.pos=float4(p2.xy+pr*s2,p2.z,1.);"
"o.Append(r);"
"r.pos=float4(p2,1.);"
"o.Append(r);"
"o.RestartStrip();"
"r.pos=float4(p1,1.);"
"o.Append(r);"
"r.pos=float4(p1.xy+pr*s1,p1.z,1.);"
"o.Append(r);"
"r.pos=float4(p2.xy+pr*s2,p2.z,1.);"
"o.Append(r);"
"o.RestartStrip();"
"r.pos=float4(p2.xy+d*s2,p2.z,1.);"
"o.Append(r);"
"r.pos=float4(p2.xy-pr*s2,p2.z,1.);"
"o.Append(r);"
"r.pos=float4(p2.xy+pr*s2,p2.z,1.);"
"o.Append(r);"
"o.RestartStrip();"
"}"
"float3 fusion(float x)"
"{"
"float t=saturate(x);"
"return saturate(float3(sqrt(t),t*t*t,max(sin(5.49763*t),pow(t,12.))));"
"}"
"float noise3d(float3 p)"
"{"
"p+=133+smoothNoiseDirection*demoTime;"
"p/=1000;"
"float n=(tex0.SampleLevel(sampler0,p.yz,0).x+tex0.SampleLevel(sampler0,p.xz,0).x+tex0.SampleLevel(sampler0,p.xy,0).x)/3.;"
"return smoothstep(.5,1.,n);"
"}"
"float4 pps(_3 i):SV_Target"
"{"
"float intensity=1.-i.age;"
"float3 color=fusion(1.-i.age*3);"
"if(i.type==ParticleType_Star)"
"{"
"float x=(distance(i.wpos,cameraPosition)-1)/starThreshold;"
"intensity=5*smoothstep(0,.2,x)*exp(-x*10);"
"intensity/=i.length+8;"
"}"
"else"
"{"
"float n=noise3d(i.wpos);"
"intensity/=i.length+128;"
"color=lerp(color,smoothNoiseColor.xyz,smoothNoiseColor.w*n);"
"}"
"if(i.type==ParticleType_Star)"
"color=float3(intensity,intensity,intensity);"
"return float4(color,intensity);"
"}"
"float mod(float x,float y)"
"{"
"return x-y*floor(x/y);"
"}"
"float2 mod(float2 x,float2 y)"
"{"
"return x-y*floor(x/y);"
"}"
"float3 mod(float3 x,float3 y)"
"{"
"return x-y*floor(x/y);"
"}"
"float2 mod(float2 x,float y)"
"{"
"return x-y*floor(x/y);"
"}"
"float3 mod(float3 x,float y)"
"{"
"return x-y*floor(x/y);"
"}"
"float pulse(float center,float width,float x)"
"{"
"float t=abs(x-center);"
"if(t>width)"
"return 0;"
"t/=width;"
"return 1-t*t*(3-2*t);"
"}"
"static const float rcfMipmapFactor=1.5,rcfStepFactor=5,rcfStrengthRadial=5,rcfStrengthCircumferential=5,rcfRadius=15;"
"static const float2 rcfCenter={.5,.5};"
"float rcfRadialFalloff(float radius,float amount)"
"{"
"return radius*(1+amount*radius*.01);"
"}"
"float4 rcfBlur(float2 tc,float2 resolution,float strength,float circumFerentialStrength)"
"{"
"float2 d=(tc-rcfCenter)*float2(resolution.x/resolution.y,1);"
"float delta=length(d),distortedDelta=rcfRadialFalloff(delta,strength),stepSize=abs(delta-distortedDelta)*rcfStepFactor,radius=rcfRadius;"
"if(circumFerentialStrength>0)"
"d=float2(d.y,-d.x),stepSize*=circumFerentialStrength,radius=floor(rcfRadius*circumFerentialStrength);"
"if(radius<=.5)"
"return tex0.SampleLevel(sampler0,tc,0);"
"d=normalize(d)*stepSize/resolution;"
"float mipLevel=sqrt(stepSize)*rcfMipmapFactor,sigma=radius/2,twoSigmaSquared=2*sigma*sigma;"
"float4 a=0;"
"for(float i=-radius;i<=radius;++i)"
"{"
"float weight=exp(-i*i/twoSigmaSquared);"
"a+=tex0.SampleLevel(sampler0,i*d+tc,mipLevel)*weight;"
"}"
"return a/sqrt(twoSigmaSquared*PI);"
"}"
"[numthreads(16,16,1)]"
"void csRadialBlur(int3 id:SV_DispatchThreadID)"
"{"
"float2 resolution;"
"out0.GetDimensions(resolution.x,resolution.y);"
"float2 tc=(id.xy+.5)/resolution;"
"out0[id.xy]=rcfBlur(tc,resolution,rcfStrengthRadial,0);"
"}"
"[numthreads(16,16,1)]"
"void csCircumferentialBlur(int3 id:SV_DispatchThreadID)"
"{"
"float2 resolution;"
"out0.GetDimensions(resolution.x,resolution.y);"
"float2 tc=(id.xy+.5)/resolution;"
"out0[id.xy]=rcfBlur(tc,resolution,rcfStrengthCircumferential,1);"
"}"
"[numthreads(16,16,1)]"
"void csSensorDirt(int3 id:SV_DispatchThreadID)"
"{"
"float2 tc=id.xy+.5;"
"}"
"static const float ldMinRadius=.025,ldMaxRadius=.075,ldCellWidth=3*ldMaxRadius,ldBorderWidthHalf=.00125,ldSeed=3,ldNumLayers=4;"
"[numthreads(16,16,1)]"
"void csLensDirt(int3 id:SV_DispatchThreadID)"
"{"
"float2 resolution;"
"out0.GetDimensions(resolution.x,resolution.y);"
"float2 tc=(id.xy+.5)/resolution;"
"tc*=float2(resolution.x/resolution.y,1);"
"rndSeed=ldSeed;"
"float4 a=0;"
"for(int i=0;i<ldNumLayers;++i)"
"{"
"float2 p=mod(tc,ldCellWidth)-ldCellWidth/2,c=floor(tc/ldCellWidth);"
"uint seedBackup=rndSeed;"
"rndSeed+=(c.x+c.y*ldCellWidth+i*ldCellWidth*ldCellWidth)*resolution.x;"
"float r=lerp(ldMinRadius,ldMaxRadius,rnd());"
"p+=float2(srnd(),srnd())*(ldCellWidth/2-r);"
"float d=length(p);"
"a+=(float4(rnd(),rnd(),rnd(),1)+.5)*(smoothstep(r,r-ldBorderWidthHalf*2,d)+.25*smoothstep(ldBorderWidthHalf,0,abs(d-r+ldBorderWidthHalf*2)));"
"rndSeed=seedBackup;"
"tc+=ldCellWidth/ldNumLayers;"
"}"
"out0[id.xy]=float4(a.xyz/ldNumLayers,1);"
"}"
"static const float bRadius=160,bSigma=bRadius/3.5,bTwoSigmaSquared=2*bSigma*bSigma;"
"void bBlur(int3 id,float2 direction)"
"{"
"float2 resolution;"
"out0.GetDimensions(resolution.x,resolution.y);"
"float2 sourceResolution;"
"tex0.GetDimensions(sourceResolution.x,sourceResolution.y);"
"float mipLevel=log2(sourceResolution.x/resolution.x);"
"float2 tc=(id.xy+.5)/resolution,d=direction/resolution;"
"float4 a=0;"
"for(float i=-bRadius;i<=bRadius;++i)"
"{"
"float weight=exp(-i*i/bTwoSigmaSquared);"
"a+=tex0.SampleLevel(sampler0,i*d+tc,mipLevel)*weight;"
"}"
"out0[id.xy]=a/sqrt(bTwoSigmaSquared*PI);"
"}"
"[numthreads(16,16,1)]"
"void csBlurH(int3 id:SV_DispatchThreadID)"
"{"
"bBlur(id,float2(1,0));"
"}"
"[numthreads(16,16,1)]"
"void csBlurV(int3 id:SV_DispatchThreadID)"
"{"
"bBlur(id,float2(0,1));"
"}"
"static const float stRadius=160;"
"[numthreads(16,16,1)]"
"void csStreaks(int3 id:SV_DispatchThreadID)"
"{"
"float2 resolution;"
"out0.GetDimensions(resolution.x,resolution.y);"
"float2 sourceResolution;"
"tex0.GetDimensions(sourceResolution.x,sourceResolution.y);"
"float mipLevel=log2(sourceResolution.x/resolution.x);"
"float2 tc=(id.xy+.5)/resolution,d=float2(1,0)/resolution;"
"float4 a=0;"
"for(float i=-stRadius+1;i<stRadius;++i)"
"{"
"float weight=(stRadius-abs(i))*(stRadius-abs(i));"
"a+=tex0.SampleLevel(sampler0,i*d+tc,mipLevel)*weight;"
"}"
"out0[id.xy]=a*1.5/(stRadius*stRadius*stRadius);"
"}"
"static const float dcStrength=10.;"
"static const float2 dcCenter={.5,.5};"
"static const int dcSamples=12;"
"float dcRadialFalloff(float radius,float amount)"
"{"
"return radius*(1+amount*radius*.01);"
"}"
"float4 dcSample(float2 tc,float amount,float2 resolution)"
"{"
"float2 d=(tc-dcCenter)*float2(resolution.x/resolution.y,1);"
"float radius=length(d);"
"d/=radius==0?d:radius;"
"return tex0.SampleLevel(sampler0,dcCenter+d*dcRadialFalloff(radius,amount)/float2(resolution.x/resolution.y,1),0);"
"}"
"[numthreads(16,16,1)]"
"void csDistortChroma(int3 id:SV_DispatchThreadID)"
"{"
"float2 resolution;"
"out0.GetDimensions(resolution.x,resolution.y);"
"float2 tc=(id.xy+.5)/resolution;"
"float4 original=tex0.SampleLevel(sampler0,tc,0);"
"if(dcStrength==0)"
"{"
"out0[id.xy]=original;"
"return;"
"}"
"float4 a=0;"
"for(int i=1;i<=dcSamples;++i)"
"{"
"float lambda=.4f*(i/float(dcSamples+1))+.35f;"
"float4 w=float4(pulse(.65,.1,lambda),pulse(.55,.1,lambda),pulse(.45,.1,lambda),.25)*4.;"
"a+=w*dcSample(tc,-(i-1)/float(dcSamples)*dcStrength,resolution);"
"}"
"a/=dcSamples;"
"out0[id.xy]=lerp(original,a,saturate(dcStrength));"
"}"
"float4 ghRainbow(float angle)"
"{"
"return float4(sin(angle),sin(angle+2.09433),sin(angle+4.18867),1)*.5+.5;"
"}"
"[numthreads(16,16,1)]"
"void csGhosts(int3 id:SV_DispatchThreadID)"
"{"
"float2 resolution;"
"out0.GetDimensions(resolution.x,resolution.y);"
"float2 tc=(id.xy+.5)/resolution;"
"tc=1-tc;"
"float2 texelSize=1/resolution,aspectCorrection=float2(resolution.x/resolution.y,1),direction=(.5-tc)*2;"
"float4 a=0;"
"for(int i=0;i<5;++i)"
"{"
"float2 sc0=1-frac(tc+direction*i*.2),sc1=1-frac(tc+direction*i*.1999);"
"float r=length((sc0-.5)*aspectCorrection);"
"a+=max(0,tex0.SampleLevel(sampler0,sc0,0)-.125)*lerp(1,ghRainbow(r*20),1.5*r);"
"a+=max(0,tex1.SampleLevel(sampler0,sc0,0)-.125)*lerp(1,ghRainbow(r*15+i),1.5*r);"
"}"
"out0[id.xy]=float4(a.xyz/5,1);"
"}"
"float3 saturation(float3 color,float saturation)"
"{"
"return lerp(dot(color,float3(.2126,.7152,.0722)),color,saturation);"
"}"
"float3 liftGammaGain(float3 color,float3 lift,float3 gamma,float3 gain)"
"{"
"return pow(saturate(gain*color+lift*(-gain*color+1)),1/gamma);"
"}"
"float3 uncharted2ToneMapping(float3 c)"
"{"
"float A=.15,B=.5,C=.1,D=.2,E=.02,F=.3,W=11.2;"
"c=(c*(A*c+C*B)+D*E)/(c*(A*c+B)+D*F)-E/F;"
"float white=(W*(A*W+C*B)+D*E)/(W*(A*W+B)+D*F)-E/F;"
"return c/white;"
"}"
"[numthreads(16,16,1)]"
"void csMerge(int3 id:SV_DispatchThreadID)"
"{"
"float2 resolution;"
"out0.GetDimensions(resolution.x,resolution.y);"
"float2 tc=(id.xy+.5)/resolution;"
"tc.x+=sin((tc.y+demoTime)*44)*.05*distort;"
"rndSeed=id.y*720+id.x;"
"float3 rndNoiseXYT=float3(rnd(),rnd(),rnd());"
"rndSeed=id.y;"
"float3 rndNoiseY=float3(rnd(),rnd(),rnd()),base=tex0.SampleLevel(sampler0,tc,0).xyz,blur1=tex1.SampleLevel(sampler0,tc,0).xyz,blur8=tex2.SampleLevel(sampler0,tc,0).xyz,blur32=tex3.SampleLevel(sampler0,tc,0).xyz,streaks=tex4.SampleLevel(sampler0,tc,0).xyz,lensDirt=tex5.SampleLevel(sampler0,tc,0).xyz,ghosts=tex6.SampleLevel(sampler0,tc,0).xyz,color=base.xyz;"
"color+=blur1*.125;"
"color+=blur8*.125;"
"color+=blur32*.125;"
"color+=streaks*lerp(1,rndNoiseY.x,.25)*.25;"
"color+=lensDirt*.25*max(0,dot(tex2.SampleLevel(sampler0,frac(1-tc),0).xyz,float3(.299,.587,.114))-1.);"
"color+=ghosts*.125;"
"color*=lerp(1,rndNoiseXYT,.35);"
"color=max(0,uncharted2ToneMapping(max(0,color*.5)));"
"color=liftGammaGain(color,float3(0,0,0),float3(1,1,1),float3(1,1,1));"
"color=pow(color,1/2.2);"
"color=saturation(color,1.2);"
"color=lerp(color,colorBlend.xyz,colorBlend.w);"
"float4 result=float4(color,dot(color,float3(.299,.587,.114)));"
"out0[id.xy]=result;"
"}"
};
#endif // SHADER_H_