From 83606f875ea6521eab8a7dabcb4b5149930bb562 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20J=C3=A4rvisalo?= Date: Wed, 24 Jul 2024 23:36:31 +0300 Subject: [PATCH] Textures --- 4kdemo.compofiller | 2 +- minified.config | 2 +- shader.glsl | 63 ++++++------ shader_minified.h | 245 +++++++++++++++++++++++++++------------------ 4 files changed, 178 insertions(+), 134 deletions(-) diff --git a/4kdemo.compofiller b/4kdemo.compofiller index a1db361..baa5bd0 100644 --- a/4kdemo.compofiller +++ b/4kdemo.compofiller @@ -6,7 +6,7 @@ PROJECT_INFO_FILE=prod.nfo PROJECT_SCREENSHOT= # Currently active config file name -ACTIVE_CONFIG=base.config +ACTIVE_CONFIG=minified.config # ------- GUI options/preferences -------- # Automatically rebuild DLLs when things have changed? diff --git a/minified.config b/minified.config index 8882112..1ffbf6c 100644 --- a/minified.config +++ b/minified.config @@ -12,7 +12,7 @@ CRINKLER_ORDERTRIES=4000 SHADER_FILE=shader_minified.h TIME_UNIFORM_NAME='v' RESOLUTION_UNIFORM_NAME='y' -TEXTS_UNIFORM_NAME='f' +TEXTS_UNIFORM_NAME='a' USE_WIDECHAR_TEXTS=1 TIME_DIVIDER=44100.000 TIME_BASE=seconds diff --git a/shader.glsl b/shader.glsl index 72f61ef..ed2c920 100644 --- a/shader.glsl +++ b/shader.glsl @@ -30,12 +30,12 @@ float hash(vec2 p) return fract( p.x*p.y*(p.x+p.y) ); } -float noise( in vec2 p ) +float noise( in vec2 p, float scale ) { vec2 i = floor( p ); vec2 f = fract( p ); vec2 u = f*f*(3.0-2.0*f); - return -0.2+0.2*mix( mix( hash( i + vec2(0.0,0.0) ), + return -scale+scale*mix( mix( hash( i + vec2(0.0,0.0) ), hash( i + vec2(1.0,0.0) ), u.x), mix( hash( i + vec2(0.0,1.0) ), hash( i + vec2(1.0,1.0) ), u.x), u.y); @@ -44,7 +44,7 @@ float noise( in vec2 p ) float displacement( vec3 p ) { - return noise(10.*p.xy+u_time) + 0.5*noise(10.*(p.xy+2.0)-u_time); + return noise(10.*p.xy+u_time, 0.2) + 0.5*noise(10.*(p.xy+2.0)-u_time, 0.2); } ///////////////// @@ -101,10 +101,10 @@ float sdTriPrism( vec3 p, vec2 h, float rot ) ////////////////// // ANIMATION // ////////////////// +const float TWOPI = 6.28318530718; // Rotate ring with duration d and startTime s float ringRotateFunc(float d, float s, float timeFact) { - const float TWOPI = 6.28318530718; float maxCycles = d; float startTime = s; float phase = ((u_time * timeFact) - startTime) / TWOPI; @@ -151,11 +151,12 @@ return x; vec2 map( in vec3 p) { + float mat = 0.; // Stargate // Ring boxes - const float an = 6.283185/24.0; - float sector = round(atan(p.y,p.x)/an); + const float an = TWOPI/24.0; + float sector = floor(atan(p.y,p.x)/an + 0.5); float angrot = sector*an; vec3 q = p; q.xy = mat2(cos(angrot),-sin(angrot), @@ -180,8 +181,8 @@ vec2 map( in vec3 p) //vec3 p2 = prismAnim(p); - float secDist = 6.283185 / 8.0; // sector distance - float angle = ((24.67 / 6.283185 )); // sector size + float secDist = TWOPI / 8.0; // sector distance + float angle = ((24.67 / TWOPI )); // sector size vec3 q = p; float rotationIncrement = angle + (index * secDist); @@ -193,7 +194,7 @@ vec2 map( in vec3 p) rotationIncrement = rotationIncrement - 0.2; } - float prismSector = round(atan(p.y,p.x)/(rotationIncrement)); + float prismSector = floor(atan(p.y,p.x)/(rotationIncrement) + 0.5); q.xy = rot2D(rotationIncrement) * q.xy; // We can now call each prism by it's index @@ -219,8 +220,8 @@ vec2 map( in vec3 p) //Rotating glyphs vec3 p2 = ringAnim(p); - float an2 = (6.283185/32.0); - float sector2 = round((atan(p2.y,p2.x)/an2) ); + float an2 = (TWOPI/32.0); + float sector2 = floor((atan(p2.y,p2.x)/an2) + 0.5 ); float angrot2 = sector2*an2; vec3 q2 = p2; q2.xy = rot2D(angrot2)*q2.xy; @@ -232,9 +233,11 @@ vec2 map( in vec3 p) const float stepHeight = 0.1; float stepDist = 1.5; const float stepWidth = 2.0; + float steps = 1000.; for(int i = 0; i < 4; i++) { float step = sdBox2(vec3(p.x,p.y+stepDist,p.z), vec3(stepWidth,stepHeight,stepDist)) - 0.05; + steps = min(steps, step); d = min(d, step); stepDist += stepHeight * 2.0; } @@ -251,10 +254,18 @@ vec2 map( in vec3 p) cylinder1 = cylinder1 + disp; water = max(-cylinder2, cylinder1); water = max(water, cylinder3); - } - d = min(d, water); + d = min(d, water); + } - return vec2( d ); + if (d==min(water,0.1)) + { + mat = 1.0; + } + else if (d==min(steps, 0.1)) + { + mat = 2.0; + } + return vec2( d, mat ); } //////////////// @@ -357,13 +368,13 @@ void main( ) col += vec3(dif * vec3(0.5,0.2,0.1)); if(mat==0.){ - col *= vec3(0,0,1); + col *= vec3(1,1,1); } else if(mat==1.){ - col *= vec3(0,1,0); + col *= (noise(5.*(p.xy+2.)+u_time, -1.0) * noise(50.*(p.xy+2.), -0.4) + 0.5*noise(20.*(p.xy+2.0)-u_time, -0.5) * noise(5.*(p.xy+2.0), -0.75))*smoothstep(0.,0.75,(u_time-5.0)*0.1) + vec3(0.,0.,0.5*noise(10.*(p.xy+4.0)-u_time, -0.5)) + vec3(0.,0.,0.5); } else if(mat==2.){ - col *= vec3(1,0,0); + col *= vec3(0.545,0.27,0.074) - 0.2*noise((vec2(100.*p.x+300.,75.*p.z+150.0)), -2.2) * noise((vec2(15.*p.x+2.0,3.*p.z+2.)), -1.) + noise((vec2(15.*p.x+2.4,3.*p.z+2.)), -0.25); } } gl_FragColor = vec4(col, 1); @@ -374,23 +385,7 @@ void main( ) // ************* post-process pass ****************** // Uncomment this to try a post-processing "effect" - vec4 c = texture2D(texture_sampler, (gl_FragCoord.xy / u_resolution )), - c1 = texture2D(texture_sampler, ((gl_FragCoord.xy + vec2(1.0, 0.0)) / u_resolution) ), - c2 = texture2D(texture_sampler, ((gl_FragCoord.xy + vec2(0.0, 1.0)) / u_resolution) ), - c3 = texture2D(texture_sampler, ((gl_FragCoord.xy + vec2(1.0, 1.0)) / u_resolution) ), - c4 = texture2D(texture_sampler, ((gl_FragCoord.xy + vec2(-1.0, 1.0)) / u_resolution) ), - c5 = texture2D(texture_sampler, ((gl_FragCoord.xy + vec2(-1.0, 0.0)) / u_resolution) ), - c6 = texture2D(texture_sampler, ((gl_FragCoord.xy + vec2(-1.0, -1.0)) / u_resolution) ), - c7 = texture2D(texture_sampler, ((gl_FragCoord.xy + vec2(0.0, -1.0)) / u_resolution) ), - c8 = texture2D(texture_sampler, ((gl_FragCoord.xy + vec2(1.0, -1.0)) / u_resolution) ) - ; - - // weird emboss effect - // gl_FragColor = (c - c1 - c2 - c3 - c4 + c5 + c6 + c7 + c8) / 2.0; - - - // some sort of gamma correction with smoothing - gl_FragColor = sqrt(c * 2.0 + c1 + c2 + c3 + c4 + c5 + c6 + c7 + c8) / 3.0; + gl_FragColor = texture2D(texture_sampler, (gl_FragCoord.xy / u_resolution )); } } diff --git a/shader_minified.h b/shader_minified.h index 0230763..4df6b92 100644 --- a/shader_minified.h +++ b/shader_minified.h @@ -1,31 +1,57 @@ // Generated with Shader Minifier 1.3.6 (https://github.com/laurentlb/Shader_Minifier/) #ifndef SHADER_MINIFIED_H_ # define SHADER_MINIFIED_H_ -# define VAR_texts "f" -# define VAR_texture_sampler "x" +# define VAR_texts "a" +# define VAR_texture_sampler "f" # define VAR_u_resolution "y" # define VAR_u_time "v" const char *__temp_cleaned_shader_glsl = "uniform vec2 y;" "uniform float v;" - "uniform sampler2D x,f;" + "uniform sampler2D f,a;" "mat2 n(float v)" "{" - "float x=sin(v),y=cos(v);" - "return mat2(y,-x,x,y);" + "float f=sin(v),y=cos(v);" + "return mat2(y,-f,f,y);" "}" - "float n(float v,float x,float y)" + "float n(float v,float y,float x)" "{" - "float m=max(y-abs(v-x),0.);" - "return max(v,x)+m*m*.25/y;" + "float f=max(x-abs(v-y),0.);" + "return max(v,y)+f*f*.25/x;" "}" - "float n(vec3 v,vec3 y)" + "float s(vec2 v)" "{" - "vec3 x=abs(v)-y;" - "return length(max(x,0.))+min(max(x.x,max(x.y,x.z)),0.);" + "v=50.*fract(v*.3183099);" + "return fract(v.x*v.y*(v.x+v.y));" "}" - "float s(vec3 v)" + "float n(vec2 v,float y)" + "{" + "vec2 f=floor(v),m=fract(v),a=m*m*(3.-2.*m);" + "return-y+y*mix(mix(s(f+vec2(0)),s(f+vec2(1,0)),a.x),mix(s(f+vec2(0,1)),s(f+vec2(1)),a.x),a.y);" + "}" + "float m(vec3 y)" + "{" + "return n(10.*y.xy+v,.2)+.5*n(10.*(y.xy+2.)-v,.2);" + "}" + "float m(vec3 v,vec3 y,vec3 m,float x)" + "{" + "vec3 f=m-y,a=v-y;" + "float s=dot(f,f),c=dot(a,f),n=length(a*s-f*c)-x*s,h=abs(c-s*.5)-s*.5,i=n*n,z=h*h*s,g=max(n,h)<0.?" + "-min(i,z):" + "(n>0.?" + "i:" + "0.)+(h>0.?" + "z:" + "0.);" + "return sign(g)*sqrt(abs(g))/s;" + "}" + "float m(vec3 v,vec3 y)" + "{" + "vec3 f=abs(v)-y;" + "return length(max(f,0.))+min(max(f.x,max(f.y,f.z)),0.);" + "}" + "float x(vec3 v)" "{" "vec2 f=vec2(.2);" "v.xy*=n(.5);" @@ -40,128 +66,151 @@ const char *__temp_cleaned_shader_glsl = "float x=length(v.xy)*sign(-v.y)*f.x,a=abs(v.z)-f.y;" "return length(max(vec2(x,a),0.))+min(max(x,a),0.);" "}" - "float s(float x,float y,float m)" + "float m(float y,float x,float f)" "{" - "float f=(v*m-y)/(2.*acos(-1.));" - "f=min(f,x);" - "return 2.*acos(-1.)*f;" + "float i=(v*f-x)/(2.*acos(-1.));" + "i=min(i,y);" + "return 2.*acos(-1.)*i;" "}" - "vec3 m(vec3 y)" + "vec3 t(vec3 y)" "{" - "float x=9.+9.*clamp(sin(s(2.,0.,1.)*.05),-.9,.9);" + "float f=9.+9.*clamp(sin(m(2.,0.,1.)*.05),-.9,.9);" "if(v>=2.)" - "x=9.+9.*clamp(sin(s(2.,0.,1.)*.05),-.9,.9),y.xy=n(x)*y.xy;" + "f=9.+9.*clamp(sin(m(2.,0.,1.)*.05),-.9,.9),y.xy=n(f)*y.xy;" "if(v>=14.)" - "x=9.+9.*clamp(sin(s(2.,14.,1.)*.05),-.9,.9),y.xy=n(x*-1.)*y.xy;" + "f=9.+9.*clamp(sin(m(2.,14.,1.)*.05),-.9,.9),y.xy=n(f*-1.)*y.xy;" "return y;" "}" - "float m(float x,float y)" + "float s(float y,float f)" "{" - "if(v>=y)" - "x+=.045*clamp(sin(s(2.4,y*10.,10.)*.4),-.9,.9);" - "return x;" + "if(v>=f)" + "y+=.045*clamp(sin(m(2.4,f*10.,10.)*.4),-.9,.9);" + "return y;" "}" - "vec2 a(vec3 v)" + "vec2 h(vec3 y)" "{" - "float x=round(atan(v.y,v.x)/.261799375)*.261799375;" - "vec3 f=v;" - "f.xy=mat2(cos(x),-sin(x),sin(x),cos(x))*f.xy;" - "float y=length(max(abs(f.xy-vec2(1.8,0))-vec2(.24,.14),0.))-.02;" - "y=min(y,abs(length(v.xy)-1.8)-.2);" - "float i=abs(length(v.xy)-1.75)-.08;" - "i=n(i,abs(v.z-.1)-.04,.005);" - "y=max(-i,y);" - "y=n(y,abs(v.z)-.1,.02);" - "float r=1.;" - "for(int a=0;a<8;a++)" + "float f=0.;" + "const float a=2.*acos(-1.)/24.;" + "float i=floor(atan(y.y,y.x)/a+.5)*a;" + "vec3 r=y;" + "r.xy=mat2(cos(i),-sin(i),sin(i),cos(i))*r.xy;" + "float c=length(max(abs(r.xy-vec2(1.8,0))-vec2(.24,.14),0.))-.02;" + "c=min(c,abs(length(y.xy)-1.8)-.2);" + "float g=abs(length(y.xy)-1.75)-.08;" + "g=n(g,abs(y.z-.1)-.04,.005);" + "c=max(-g,c);" + "c=n(c,abs(y.z)-.1,.02);" + "float h=1.;" + "for(int l=0;l<8;l++)" "{" - "vec3 c=v;" - "float z=24.67/6.283185+r*.785398125;" - "if(a==1)" - "z+=.2;" - "if(a==7)" - "z-=.2;" - "c.xy=n(z)*c.xy;" - "if(a>0)" + "vec3 z=y;" + "float b=24.67/(2.*acos(-1.))+h*(2.*acos(-1.)/8.);" + "if(l==1)" + "b+=.2;" + "if(l==7)" + "b-=.2;" + "z.xy=n(b)*z.xy;" + "if(l>0)" "{" - "c.x=c.x-1.95;" - "if(a==1)" - "c.x=m(c.x,13.);" - "if(a==2)" - "c.x=m(c.x,26.);" - "float l=s(vec3(c))-.02;" - "y=min(y,l);" + "z.x=z.x-1.95;" + "if(l==1)" + "z.x=s(z.x,13.);" + "if(l==2)" + "z.x=s(z.x,26.);" + "float p=x(vec3(z))-.02;" + "c=min(c,p);" "}" - "r+=1.;" + "h+=1.;" "}" - "vec3 a=m(v);" - "float c=6.283185/32.;" - "vec3 l=a;" - "l.xy=n(round(atan(a.y,a.x)/c)*c)*l.xy;" - "float z=n(l.xyz-vec3(1.75,0,0),vec3(.04,.14,.05))-.02;" - "y=min(y,z);" - "float e=1.5;" - "for(int u=0;u<4;u++)" + "vec3 l=t(y);" + "float z=2.*acos(-1.)/32.;" + "vec3 b=l;" + "b.xy=n(floor(atan(l.y,l.x)/z+.5)*z)*b.xy;" + "float p=m(b.xyz-vec3(1.75,0,0),vec3(.04,.14,.05))-.02;" + "c=min(c,p);" + "float e=1.5,u=1e3;" + "for(int C=0;C<4;C++)" "{" - "float h=n(vec3(v.x,v.y+e,v.z),vec3(2,.1,e))-.05;" - "y=min(y,h);" + "float D=m(vec3(y.x,y.y+e,y.z),vec3(2,.1,e))-.05;" + "u=min(u,D);" + "c=min(c,D);" "e+=.2;" "}" - "return vec2(y);" + "float D=1e3;" + "if(v>2.)" + "{" + "float C=m(y,vec3(0),vec3(0,0,-.01),1.6),F=m(y,vec3(0,0,1),vec3(0,0,-1),2.-v*2.+4.),E=m(y,vec3(0,0,1),vec3(0,0,-1),1.6),d=0.;" + "if(v>5.)" + "d=m(y+4.)*min((v-5.)*.5,.25);" + "C+=d;" + "D=max(-F,C);" + "D=max(D,E);" + "c=min(c,D);" + "}" + "if(c==min(D,.1))" + "f=1.;" + "else if(c==min(u,.1))" + "f=2.;" + "return vec2(c,f);" "}" - "float a(vec3 x,vec3 y)" + "float h(vec3 y,vec3 v)" "{" - "float f=0.,v;" + "float f=0.,c;" "for(int i=0;i<80;i++)" "{" - "vec3 m=x+y*f;" - "v=a(m).x;" - "f+=v;" - "if(v<.001||f>1e2)" + "vec3 x=y+v*f;" + "c=h(x).x;" + "f+=c;" + "if(c<.001||f>1e2)" "break;" "}" "return f;" "}" - "vec3 h(vec3 v)" + "vec3 p(vec3 v)" "{" - "float y=a(v).x;" - "vec2 x=vec2(.01,0);" - "vec3 f=y-vec3(a(v-x.xyy).x,a(v-x.yxy).x,a(v-x.yyx));" - "return normalize(f);" + "float f=h(v).x;" + "vec2 y=vec2(.01,0);" + "vec3 c=f-vec3(h(v-y.xyy).x,h(v-y.yxy).x,h(v-y.yyx));" + "return normalize(c);" "}" - "float a(vec3 v,vec3 x,float y)" + "float h(vec3 v,vec3 y,float f)" "{" - "vec3 f=normalize(x-v),m=h(v);" - "float i=clamp(dot(m,f),0.,.75),c=a(v+m*.0025,f);" - "if(c0.)" "{" - "vec3 m=v+f*c;" - "float l=a(m).y,r=a(m,vec3(3,5,4),.2);" - "i=vec3(r*vec3(1));" - "r=a(m,vec3(-3,5,-4),.1);" - "i+=vec3(r*vec3(.5,.2,.1));" - "if(l==0.)" - "i*=vec3(0,0,1);" - "else if(l==1.)" - "i*=vec3(0,1,0);" - "else if(l==2.)" - "i*=vec3(1,0,0);" + "float l=h(x,a);" + "if(l<1e3)" + "{" + "vec3 z=x+a*l;" + "float m=h(z).y,r=h(z,vec3(3,5,4),.2);" + "i=vec3(r*vec3(1));" + "r=h(z,vec3(-3,5,-4),.1);" + "i+=vec3(r*vec3(.5,.2,.1));" + "if(m==0.)" + "i*=vec3(1);" + "else if(m==1.)" + "i*=(n(5.*(z.xy+2.)+v,-1.)*n(50.*(z.xy+2.),-.4)+.5*n(20.*(z.xy+2.)-v,-.5)*n(5.*(z.xy+2.),-.75))*smoothstep(0.,.75,(v-5.)*.1)+vec3(0,0,.5*n(10.*(z.xy+4.)-v,-.5))+vec3(0,0,.5);" + "else if(m==2.)" + "i*=vec3(.545,.27,.074)-.2*n(vec2(1e2*z.x+3e2,75.*z.z+150.),-2.2)*n(vec2(15.*z.x+2.,3.*z.z+2.),-1.)+n(vec2(15.*z.x+2.4,3.*z.z+2.),-.25);" + "}" + "gl_FragColor=vec4(i,1);" "}" - "gl_FragColor=vec4(i,1);" + "else" + " gl_FragColor=texture2D(f,gl_FragCoord.xy/y);" "}"; #endif // SHADER_MINIFIED_H_