lisää optimointia

This commit is contained in:
2024-07-29 08:13:18 +03:00
parent b4c88efb92
commit f5cfde0373
5 changed files with 473 additions and 328 deletions

View File

@ -1,11 +1,7 @@
#version 460
precision mediump float;
uniform vec2 u_resolution;
uniform float u_time;
uniform vec2 u_mouse;
out vec4 my_fragColor;
uniform sampler2D texture_sampler;
uniform sampler2D texts;
@ -955,6 +951,6 @@ void main()
// fade out at the end
// finalColor*=vec3(clamp((120.-u_time)*.35, 0., 1.));
my_fragColor = vec4(finalColor, 1.);
gl_FragColor = vec4(finalColor, 1.);
}

View File

@ -10,7 +10,7 @@ include $(PARENT_CONFIG)
EXE_LINKER_PROGRAM=Crinkler
CRINKLER_ORDERTRIES=4000
SHADER_FILE=shader_minified.h
TIME_UNIFORM_NAME='y'
TIME_UNIFORM_NAME='m'
RESOLUTION_UNIFORM_NAME='v'
TEXTS_UNIFORM_NAME='f'
USE_WIDECHAR_TEXTS=1

View File

@ -1,4 +1,4 @@
// precision mediump float;
//precision mediump float;
uniform vec2 u_resolution;
uniform float u_time;
const float PI = 22./7.;
@ -26,7 +26,7 @@ float noise( in vec2 p, float scale )
{
vec2 i = floor( p );
vec2 f = fract( p );
vec2 u = f*f*(3.0-2.0*f);
vec2 u = f*f*(3.-2.*f);
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) ),
@ -35,12 +35,15 @@ float noise( in vec2 p, float scale )
float displacement( vec3 p )
{
return noise(10.*p.xy+u_time+1e3, 0.2) + 0.5*noise(10.*(p.xy+2.0)-u_time+1e3, 0.2);
return noise(10.*p.xy+u_time+1e3, 0.2) + 0.5*noise(10.*(p.xy+2.0)-u_time+1e3, .2);
}
/////////////////
// GEOMETRY //
/////////////////
float sdSphere(vec3 p, float r) {
return length(p)-r;
}
float sdCappedCylinder( vec3 p, float h, float r )
{
@ -91,6 +94,7 @@ vec3 fogColor2 = vec3(.7, .4, .2); // fog color2
vec3 indirColor = vec3(.2, .1, .3); // indirect light color
vec3 light1Color = vec3(.9, .5, .7);
vec3 light2Color = vec3(.8, .7, .5);
vec3 chevronColor = vec3(.9, .3, 0.);
// with duration d, startTime s and speed up with timeFact
float timedSine(float maxCycles, float startTime, float timeFact) {
@ -138,11 +142,11 @@ vec2 map(in vec3 p)
// Stargate
// Ring boxes
const float an = PI/12.;
float angrot = floor(atan(p.y,p.x)/an + .5)*an;
float an = PI/12.;
float anRot = floor(atan(p.y,p.x)/an + .5)*an;
vec3 q = p;
q.xy = mat2(cos(angrot),-sin(angrot),
sin(angrot), cos(angrot))*q.xy;
q.xy = mat2(cos(anRot),-sin(anRot),
sin(anRot), cos(anRot))*q.xy;
float d = sdBox( q.xy - vec2(1.8,0.), vec2(0.24,0.14) ) - .02;
// Main ring
@ -150,85 +154,71 @@ vec2 map(in vec3 p)
d = min(d,d2);
// Inner ring
float d3 = abs(length(p.xy) - 1.75) - .08;
d3 = smax( d3, abs(p.z - .1)-.04, .005 );
d = max(-d3,d);
d2 = abs(length(p.xy) - 1.75) - .08;
d2 = smax( d2, abs(p.z - .1)-.04, .005 );
d = max(-d2,d);
// Depth slice rings
d = smax( d, abs(p.z)-.1, .02 );
// Prisms
for(float i = 0.; i < 8.; i++ ) {
float secDist = PI / 4.; // sector distance
float angle = 24.67 / (PI * 2.); // sector size
vec3 q = p;
float rotationIncrement = angle + ((i+1.)*secDist);
// Prisms
for(float i = 0.; i < 8.; i++ ) {
an = 24.67 / (PI * 2.); // sector size
q = p;
anRot = an + (i+1.) * PI / 4.;
// Nudge first and the last prism out of the ground
if (i == 1.) rotationIncrement += .2;
if (i == 7.) rotationIncrement -= .2;
q.xy = rot2D(rotationIncrement) * q.xy;
if (i == 1.) anRot += .2;
if (i == 7.) anRot -= .2;
q.xy = rot2D(anRot) * q.xy;
float rotateDelay = STARTDELAY + ((i - 1.) * glyphPhase + 1.5);
float rotateDelay = STARTDELAY + (i - 1.) * glyphPhase + 1.5;
// We can now call each prism by it's index
// draw all except the middle bottom prism
if (i > 0.) {
q.x -= 1.95;
vec3 q2 = q; // new point for movable parts
if(u_time > rotateDelay) q2.x = prismAnim(q2.x, rotateDelay);
float prismOut = sdTriPrism(vec3(q2.x - .14, q2.y - 0. , q2.z), vec2(.22,.22), .5) - .01;
float prismIn = sdTriPrism(vec3(q2.x, q2.y, q2.z ), vec2(.2,.12), .5) - .02;
float prismTop = sdTriPrism(vec3(q.x - .06, q.y, q.z), vec2(.1,.15), .5) - .01;
float d4 = max(-prismOut, prismIn);
d4 = min(d4, prismTop);
d = min(d, d4);
if(u_time > rotateDelay) q2.x = prismAnim(q2.x, rotateDelay);
float prismTop = sdTriPrism(vec3(q.x - .06, q.y, q.z), vec2(.1,.15), .5)-.01;
d2 = max(- sdTriPrism(vec3(q2.x - .14, q2.y - 0. , q2.z), vec2(.22,.22), .5) - .01 , sdTriPrism(vec3(q2.x, q2.y, q2.z ), vec2(.2,.12), .5) - .02);
d2 = min(d2, prismTop);
d = min(d, d2);
// glyph locking thing material
if (d == d4) mat = 4.;
if (d == d2) mat = 4.;
// glyph locking prism material
if( d == prismTop && u_time > rotateDelay + .2) mat = 5.;
}
}
//Rotating glyphs
vec3 p2 = ringAnim(p);
float an2 = PI/16.;
vec3 p2 = ringAnim(p);
vec3 q2 = p2;
q2.xy = rot2D(floor((atan(p2.y,p2.x)/an2) + .5)*an2)*q2.xy;
float d5 = sdBox2( q2.xyz - vec3(1.75,0.,0.), vec3(.04, .14, .05) ) - .02;
d = min(d, d5);
if (d==d5) mat = 4.;
an = PI/16.;
q2.xy = rot2D(floor((atan(p2.y,p2.x)/an) + .5)*an)*q2.xy;
d2 = sdBox2( q2.xyz - vec3(1.75,0.,0.), vec3(.04, .14, .05) ) - .02;
d = min(d, d2);
if (d==d2) mat = 4.;
// Gate Base
// Gate Base
d2 = 1e3;
float stepDist = 1.5;
float steps = 1e3;
for(int i = 0; i < 4; i++) {
float step = sdBox2(vec3(p.x,p.y+stepDist,p.z), vec3(2., .1,stepDist)) - .05;
steps = min(steps, step);
d2 = min(d2, step);
d = min(d, step);
stepDist += .2;
}
if (d==d2) mat = 2.0;
float sand = (p.y + 4.25) + 1.5*noise((vec2((p.x*.04),(p.z-40.)*.04))+100., 15.);
//sand += noise(p.yz, .25); // + 0.025*noise(p.xz*50.+100., .05);
d = min(d,sand);
float water = 1000.;
float cylinder1 = sdCappedCylinder ( p, .025, 1.6);
float cylinder2 = sdCappedCylinder ( p, 2.0, clamp((2.0 - (u_time*2.0 - 2.0*23.0)),0.,2.0));
float cylinder3 = sdCappedCylinder ( p, 0.3, 1.6);
float disp = 0.;
disp = displacement(p)*clamp(((u_time-24.0)*0.5), 0., 0.25);
cylinder1 = cylinder1 + disp;
water = max(-cylinder2, cylinder1);
water = max(water, cylinder3);
d = min(d, water);
if (d==water) mat = 1.0;
if (d==steps) mat = 2.0;
if (d==sand) mat = 3.0;
d2 = (p.y + 4.25) + 1.5*noise((vec2((p.x*.04),(p.z-40.)*.04))+100., 15.);
d = min(d,d2);
if (d==d2) mat = 3.0;
d2 = 1e3;
d2 = max(-sdCappedCylinder(p, 2.0, clamp((2.0 - (u_time*2.0 - 2.0*23.0)),0.,2.0)), sdCappedCylinder(p, .025, 1.6)+ displacement(p)*clamp(((u_time-24.0)*0.5), 0., 0.25));
d2 = max(d2, sdCappedCylinder ( p, 0.3, 1.6));
d = min(d, d2);
if (d==d2) mat = 1.0;
return vec2( d, mat );
}
@ -335,15 +325,14 @@ vec3 colorFlashesAnim(in vec3 col) {
float delay = 10.75;
if(u_time > delay) {
float x = smoothstep(-1.,.8,sin((timedSine(.8, delay, 8.)*2.)));
col = mix(col, vec3(.95, .35, .06) * (x * 1.4), x *.76);
col = mix(col, chevronColor * (x * 1.4), x *.76);
}
return col;
}
void main()
vec3 sceneGate(vec2 uv)
{
// Initialization
vec2 uv = (gl_FragCoord.xy * 2. - u_resolution.xy) / u_resolution.y;
// Initialization
vec3 ro = cameraPos();
vec3 rd = getCameraRayDir(uv, ro, cameraPointAt(), 2.); // ray direction
vec3 col = vec3(0.); // color
@ -359,24 +348,14 @@ void main()
// 2: Light position
// 3: Light intensity
// 4: Shadow intensity
float dif = 0.; //getLight(p, vec3( 2, 50, 2), .5, .2);
// Color for light 1
// col = vec3(dif * vec3(0.9216, 0.9294, 0.9412));
// Light 2
dif = getLight(p, vec3( 10., 15., 25.), 1., .2);
float dif = getLight(p, vec3( 10., 15., 25.), 1., .2);
col += dif * light1Color;
dif = getLight(p, vec3( 4., 2., -15.), 1., 1.);
col += dif * light2Color;
/*vec3 lightPosition = vec3(1.7,-1.1,0.3);
float len = length( lightPosition - p);
float att = 8.0 / (1.0 + 8.1*len + 0.01*len*len); // light attenuation
if(u_time > 10.76) {
col += vec3(dif * vec3(0.95, 0.35, 0.06) * att);
}*/
// indirect lightning -> vec3 in normalize is light direction
col += indirColor * clamp( dot( getNormal(p), normalize(vec3(0. , 1., 10.))), 0., 1.);
@ -391,13 +370,86 @@ void main()
else if(mat==4.)
col *= vec3(.1);
else if(mat ==5.)
col *= vec3(0.9, 0.3, 0.); // activated glyph color
col *= chevronColor; // activated glyph color
}
float fogAmount = .01;
// col = col*exp(-d*fogAmount) + applyFog(col, d, rd, vec3(0., .3, -1.), fogAmount) * (1.0-exp(-d*fogAmount));
col = applyFog(col, d, rd, vec3(0., -.1, -1.), fogAmount);
col = colorFlashesAnim(col); // animated color flash
gl_FragColor = vec4(postProcess(col), 1.);
float fogAmount = .01;
col = applyFog(col, d, rd, vec3(0., -.1, -1.), fogAmount);
col = colorFlashesAnim(col); // animated color flash
return postProcess(col);
}
void pMod1(inout float p, float size) {
float halfsize = size*0.5;
p = mod(p + halfsize, size) - halfsize;
}
void getQ(inout vec3 q, float i, float speed, float radius) {
q.z -= .5;
q.xy *= rot2D(sin(speed*u_time*.25)*PI);
q.x -= radius * sin(i / PI);
q.y -= radius * cos(i / PI);
q.z += i * .01;
}
vec2 map2(vec3 pos) {
float d = 1e3;
float mat;
pMod1(pos.z, 1.);
for (float i = 0.; i < 90.; i++) {
vec3 q = pos;
getQ(q, i, -1., 3.);
float b = sdSphere(q, 0.05);
d = min(d, b);
if (d == b) mat = 0.;
q = pos;
getQ(q, i, 1., .3);
b = sdSphere(q, 0.01);
d = min(d, b);
if (d == b) mat = 1.;
}
return vec2(d, mat);
}
vec3 palette(float t) {
vec3 a = vec3(0.5, 0.5, 0.5);
vec3 b = vec3(1.0, 1.0, 1.0);
vec3 c = vec3(1.0, 1.0, 1.0);
vec3 d = vec3(0.0, 0.66, 0.33);
return a + b * cos(6.3 * (c*t+d));
}
float rayMarch2(vec3 ro, vec3 rd) {
float t = 0.;
float d;
for (int i = 0; i < 60; i++) {
vec3 p = ro + rd * t;
d = map2(p).x;
t += d;
if (d < .002 || t > 20.) break;
}
return t;
}
vec3 sceneTunnel(vec2 uv) {
vec3 ro = vec3(0.,0.,u_time*2. );
vec3 rd = normalize(vec3(uv, .7));
float d = rayMarch2(ro, rd);
vec3 p = ro + rd * d;
float mat = map2(p).y;
vec3 col = vec3(0., 0., .1);
if (d < 10.) {
if (mat == 0.) col = vec3( 0., .3, .6);
if (mat == 1.) col = palette(1. - .4*d);
}
return col;
}
void main() {
vec2 uv = (gl_FragCoord.xy * 2. - u_resolution.xy) / u_resolution.y;
if (u_time < 29.) {
gl_FragColor = vec4(sceneGate(uv), 1.);
} else {
gl_FragColor = vec4(sceneTunnel(uv), 1.);
}
}

View File

@ -2,21 +2,21 @@
#ifndef SHADER_MINIFIED_H_
# define SHADER_MINIFIED_H_
# define VAR_u_resolution "v"
# define VAR_u_time "y"
# define VAR_u_time "m"
const char *__temp_cleaned_shader_glsl =
"uniform vec2 v;"
"uniform float y;"
"const float m=22./7.;"
"uniform float m;"
"const float y=22./7.;"
"mat2 f(float v)"
"{"
"float y=sin(v),f=cos(v);"
"return mat2(f,-y,y,f);"
"float f=sin(v),m=cos(v);"
"return mat2(m,-f,f,m);"
"}"
"float f(float v,float y,float m)"
"float f(float v,float f,float m)"
"{"
"float f=max(m-abs(v-y),0.);"
"return max(v,y)+f*f*.25/m;"
"float y=max(m-abs(v-f),0.);"
"return max(v,f)+y*y*.25/m;"
"}"
"float n(vec2 v)"
"{"
@ -30,131 +30,133 @@ const char *__temp_cleaned_shader_glsl =
"}"
"float x(vec3 v)"
"{"
"return f(10.*v.xy+y+1e3,.2)+.5*f(10.*(v.xy+2.)-y+1e3,.2);"
"return f(10.*v.xy+m+1e3,.2)+.5*f(10.*(v.xy+2.)-m+1e3,.2);"
"}"
"float n(vec3 v,float y,float m)"
"float n(vec3 v,float y)"
"{"
"vec2 f=abs(vec2(length(v.xy),v.z))-vec2(m,y);"
"return min(max(f.x,f.y),0.)+length(max(f,0.));"
"return length(v)-y;"
"}"
"float n(vec3 v,vec3 y)"
"float n(vec3 v,float f,float m)"
"{"
"vec3 f=abs(v)-y;"
"return length(max(f,0.))+min(max(f.x,max(f.y,f.z)),0.);"
"vec2 c=abs(vec2(length(v.xy),v.z))-vec2(m,f);"
"return min(max(c.x,c.y),0.)+length(max(c,0.));"
"}"
"float x(vec3 v,vec2 y)"
"float x(vec3 v,vec3 y)"
"{"
"vec3 m=abs(v)-y;"
"return length(max(m,0.))+min(max(m.x,max(m.y,m.z)),0.);"
"}"
"float s(vec3 v,vec2 y)"
"{"
"v.xy*=f(.5);"
"vec3 m=abs(v);"
"return max(m.z-y.y,max(m.x*.866025+v.y*.5,-v.y)-y.x*.5);"
"}"
"vec3 i=vec3(.4,.2,.4),c=vec3(.7,.4,.2),a=vec3(.2,.1,.3),s=vec3(.9,.5,.7),k=vec3(.8,.7,.5);"
"float x(float v,float f,float x)"
"vec3 i=vec3(.4,.2,.4),c=vec3(.7,.4,.2),a=vec3(.2,.1,.3),k=vec3(.9,.5,.7),l=vec3(.8,.7,.5),p=vec3(.9,.3,0);"
"float s(float v,float f,float x)"
"{"
"f*=x;"
"float i=(y*x-f)/m;"
"return m*min(i,v);"
"float i=(m*x-f)/y;"
"return y*min(i,v);"
"}"
"vec3 p(vec3 v)"
"vec3 s(vec3 v)"
"{"
"for(float m=0.;m<7.;m++)"
"for(float i=0.;i<7.;i++)"
"{"
"float c=9.+m*2.;"
"if(y>c)"
"float y=9.+i*2.;"
"if(m>y)"
"{"
"float i=1.;"
"if(mod(m,2.)>=1.)"
"i=-1.;"
"v.xy*=f((9.+9.*clamp(sin(x(1.5,c,4.)*.06),-.9,.9))*i);"
"float c=1.;"
"if(mod(i,2.)>=1.)"
"c=-1.;"
"v.xy*=f((9.+9.*clamp(sin(s(1.5,y,4.)*.06),-.9,.9))*c);"
"}"
"}"
"return v;"
"}"
"float p(float v,float f)"
"float h(float v,float f)"
"{"
"if(y>=f)"
"v+=.045*clamp(sin(x(3.,f,40.)*.4),-.8,.8);"
"if(m>=f)"
"v+=.045*clamp(sin(s(3.,f,40.)*.4),-.8,.8);"
"return v;"
"}"
"vec2 h(vec3 v)"
"{"
"float c=0.;"
"const float i=m/12.;"
"float a=floor(atan(v.y,v.x)/i+.5)*i;"
"vec3 r=v;"
"r.xy=mat2(cos(a),-sin(a),sin(a),cos(a))*r.xy;"
"float e=length(max(abs(r.xy-vec2(1.8,0))-vec2(.24,.14),0.))-.02;"
"e=min(e,abs(length(v.xy)-1.8)-.2);"
"float s=abs(length(v.xy)-1.75)-.08;"
"s=f(s,abs(v.z-.1)-.04,.005);"
"e=max(-s,e);"
"e=f(e,abs(v.z)-.1,.02);"
"for(float l=0.;l<8.;l++)"
"float c=0.,i=y/12.,r=floor(atan(v.y,v.x)/i+.5)*i;"
"vec3 a=v;"
"a.xy=mat2(cos(r),-sin(r),sin(r),cos(r))*a.xy;"
"float l=length(max(abs(a.xy-vec2(1.8,0))-vec2(.24,.14),0.))-.02,z=abs(length(v.xy)-1.8)-.2;"
"l=min(l,z);"
"z=abs(length(v.xy)-1.75)-.08;"
"z=f(z,abs(v.z-.1)-.04,.005);"
"l=max(-z,l);"
"l=f(l,abs(v.z)-.1,.02);"
"for(float e=0.;e<8.;e++)"
"{"
"vec3 h=v;"
"float z=24.67/(m*2.)+(l+1.)*(m/4.);"
"if(l==1.)"
"z+=.2;"
"if(l==7.)"
"z-=.2;"
"h.xy=f(z)*h.xy;"
"float k=(l-1.)*2.+1.5+9.;"
"if(l>0.)"
"i=24.67/(y*2.);"
"a=v;"
"r=i+(e+1.)*y/4.;"
"if(e==1.)"
"r+=.2;"
"if(e==7.)"
"r-=.2;"
"a.xy=f(r)*a.xy;"
"float p=9.+(e-1.)*2.+1.5;"
"if(e>0.)"
"{"
"h.x-=1.95;"
"vec3 d=h;"
"if(y>k)"
"d.x=p(d.x,k);"
"float t=x(vec3(d.x-.14,d.yz),vec2(.22))-.01,C=x(vec3(d),vec2(.2,.12))-.02,F=x(vec3(h.x-.06,h.yz),vec2(.1,.15))-.01,g=max(-t,C);"
"g=min(g,F);"
"e=min(e,g);"
"if(e==g)"
"a.x-=1.95;"
"vec3 d=a;"
"if(m>p)"
"d.x=h(d.x,p);"
"float C=s(vec3(a.x-.06,a.yz),vec2(.1,.15))-.01;"
"z=max(-s(vec3(d.x-.14,d.yz),vec2(.22))-.01,s(vec3(d),vec2(.2,.12))-.02);"
"z=min(z,C);"
"l=min(l,z);"
"if(l==z)"
"c=4.;"
"if(e==F&&y>k+.2)"
"if(l==C&&m>p+.2)"
"c=5.;"
"}"
"}"
"vec3 h=p(v);"
"float z=m/16.;"
"vec3 l=h;"
"l.xy=f(floor(atan(h.y,h.x)/z+.5)*z)*l.xy;"
"float g=n(l.xyz-vec3(1.75,0,0),vec3(.04,.14,.05))-.02;"
"e=min(e,g);"
"if(e==g)"
"vec3 d=s(v),e=d;"
"i=y/16.;"
"e.xy=f(floor(atan(d.y,d.x)/i+.5)*i)*e.xy;"
"z=x(e.xyz-vec3(1.75,0,0),vec3(.04,.14,.05))-.02;"
"l=min(l,z);"
"if(l==z)"
"c=4.;"
"float k=1.5,d=1e3;"
"for(int t=0;t<4;t++)"
"z=1e3;"
"float p=1.5;"
"for(int C=0;C<4;C++)"
"{"
"float C=n(vec3(v.x,v.y+k,v.z),vec3(2,.1,k))-.05;"
"d=min(d,C);"
"e=min(e,C);"
"k+=.2;"
"float k=x(vec3(v.x,v.y+p,v.z),vec3(2,.1,p))-.05;"
"z=min(z,k);"
"l=min(l,k);"
"p+=.2;"
"}"
"float C=v.y+4.25+1.5*f(vec2(v.x*.04,(v.z-40.)*.04)+1e2,15.);"
"e=min(e,C);"
"float t=1e3,F=n(v,.025,1.6),E=n(v,2.,clamp(2.-y*2.+46.,0.,2.)),D=n(v,.3,1.6),u=0.;"
"u=x(v)*clamp((y-24.)*.5,0.,.25);"
"F+=u;"
"t=max(-E,F);"
"t=max(t,D);"
"e=min(e,t);"
"if(e==t)"
"c=1.;"
"if(e==d)"
"if(l==z)"
"c=2.;"
"if(e==C)"
"z=v.y+4.25+1.5*f(vec2(v.x*.04,(v.z-40.)*.04)+1e2,15.);"
"l=min(l,z);"
"if(l==z)"
"c=3.;"
"return vec2(e,c);"
"z=1e3;"
"z=max(-n(v,2.,clamp(2.-m*2.+46.,0.,2.)),n(v,.025,1.6)+x(v)*clamp((m-24.)*.5,0.,.25));"
"z=max(z,n(v,.3,1.6));"
"l=min(l,z);"
"if(l==z)"
"c=1.;"
"return vec2(l,c);"
"}"
"float h(vec3 v,vec3 y)"
"float r(vec3 v,vec3 y)"
"{"
"float i=0.,f;"
"for(int e=0;e<90;e++)"
"float i=0.,m;"
"for(int f=0;f<90;f++)"
"{"
"vec3 m=v+y*i;"
"f=h(m).x;"
"i+=f;"
"if(abs(f)<.002||i>4e2)"
"vec3 l=v+y*i;"
"m=h(l).x;"
"i+=m;"
"if(abs(m)<.002||i>4e2)"
"break;"
"}"
"return i;"
@ -163,21 +165,21 @@ const char *__temp_cleaned_shader_glsl =
"{"
"float m=h(v).x;"
"vec2 y=vec2(.01,0);"
"vec3 f=m-vec3(h(v-y.xyy).x,h(v-y.yxy).x,h(v-y.yyx));"
"return normalize(f);"
"vec3 l=m-vec3(h(v-y.xyy).x,h(v-y.yxy).x,h(v-y.yyx));"
"return normalize(l);"
"}"
"float h(vec3 v,vec3 m,float y)"
"{"
"vec3 f=normalize(m-v),e=r(v);"
"float i=clamp(dot(e,f),0.,1.),c=h(v+e*.0025,f);"
"if(abs(c)<length(m-v))"
"i*=y;"
"return i;"
"vec3 f=normalize(m-v),l=r(v);"
"float c=clamp(dot(l,f),0.,1.),z=r(v+l*.0025,f);"
"if(abs(z)<length(m-v))"
"c*=y;"
"return c;"
"}"
"vec3 p(vec2 v,vec3 y,vec3 m)"
"vec3 r(vec2 v,vec3 y,vec3 m)"
"{"
"vec3 f=normalize(m-y),c=normalize(cross(vec3(0,1,0),f));"
"return normalize(f*2.+v.x*c+v.y*cross(f,c));"
"vec3 f=normalize(m-y),z=normalize(cross(vec3(0,1,0),f));"
"return normalize(f*2.+v.x*z+v.y*cross(f,z));"
"}"
"vec3 e(vec3 f)"
"{"
@ -188,63 +190,128 @@ const char *__temp_cleaned_shader_glsl =
"}"
"vec3 e()"
"{"
"vec3 v=vec3(0,clamp(6.-y,2.,6.),clamp(75.-y*8.,6.,75.));"
"if(y>7.5)"
"v+=vec3(0,clamp(7.5-y,-1.,0.),0);"
"if(y>10.5)"
"vec3 v=vec3(0,clamp(6.-m,2.,6.),clamp(75.-m*8.,6.,75.));"
"if(m>7.5)"
"v+=vec3(0,clamp(7.5-m,-1.,0.),0);"
"if(m>10.5)"
"v=vec3(2,-1,1);"
"if(y>12.)"
"if(m>12.)"
"v=vec3(-1,-1,4);"
"return v;"
"}"
"vec3 f()"
"{"
"vec3 v=vec3(0,-.5,0);"
"if(y>10.5)"
"if(m>10.5)"
"v=vec3(1.7,-1.1,0);"
"if(y>12.)"
"if(m>12.)"
"v=vec3(0,.1,0);"
"return v;"
"}"
"vec3 t(vec3 v)"
"{"
"if(y>10.75)"
"if(m>10.75)"
"{"
"float f=smoothstep(-1.,.8,sin(x(.8,10.75,8.)*2.));"
"v=mix(v,f*1.4*vec3(.95,.35,.06),f*.76);"
"float f=smoothstep(-1.,.8,sin(s(.8,10.75,8.)*2.));"
"v=mix(v,f*1.4*p,f*.76);"
"}"
"return v;"
"}"
"void main()"
"vec3 d(vec2 v)"
"{"
"vec2 m=(gl_FragCoord.xy*2.-v.xy)/v.y;"
"vec3 y=e(),x=p(m,y,f()),l=vec3(0);"
"float d=h(y,x);"
"vec3 m=e(),y=r(v,m,f()),z=vec3(0);"
"float d=r(m,y);"
"if(d<150.)"
"{"
"vec3 z=y+x*d;"
"float g=h(z).y,C=0.;"
"C=h(z,vec3(10,15,25),.2);"
"l+=C*s;"
"C=h(z,vec3(4,2,-15),1.);"
"l+=C*k;"
"l+=a*clamp(dot(r(z),normalize(vec3(0,1,10))),0.,1.);"
"if(g==0.)"
"l*=vec3(.3);"
"else if(g==1.)"
"l*=vec3(0,0,.5);"
"else if(g==2.)"
"l*=vec3(.3,.1,0);"
"else if(g==3.)"
"l*=vec3(.8,.8,.5)+f(z.xz*5e2+1e2,.3);"
"else if(g==4.)"
"l*=vec3(.1);"
"else if(g==5.)"
"l*=vec3(.9,.3,0);"
"vec3 x=m+y*d;"
"float C=h(x).y,n=h(x,vec3(10,15,25),.2);"
"z+=n*k;"
"n=h(x,vec3(4,2,-15),1.);"
"z+=n*l;"
"z+=a*clamp(dot(r(x),normalize(vec3(0,1,10))),0.,1.);"
"if(C==0.)"
"z*=vec3(.3);"
"else if(C==1.)"
"z*=vec3(0,0,.5);"
"else if(C==2.)"
"z*=vec3(.3,.1,0);"
"else if(C==3.)"
"z*=vec3(.8,.8,.5)+f(x.xz*5e2+1e2,.3);"
"else if(C==4.)"
"z*=vec3(.1);"
"else if(C==5.)"
"z*=p;"
"}"
"l=mix(l,mix(i,c,pow(max(dot(x,vec3(0,-.1,-1)),0.),8.)),1.-exp(-d*.01));"
"l=t(l);"
"gl_FragColor=vec4(e(l),1);"
"z=mix(z,mix(i,c,pow(max(dot(y,vec3(0,-.1,-1)),0.),8.)),1.-exp(-d*.01));"
"z=t(z);"
"return e(z);"
"}"
"void w(inout float v)"
"{"
"v=mod(v+.5,1.)-.5;"
"}"
"void d(inout vec3 v,float l,float i,float z)"
"{"
"v.z-=.5;"
"v.xy*=f(sin(i*m*.25)*y);"
"v.x-=z*sin(l/y);"
"v.y-=z*cos(l/y);"
"v.z+=l*.01;"
"}"
"vec2 C(vec3 v)"
"{"
"float m=1e3,z;"
"w(v.z);"
"for(float f=0.;f<90.;f++)"
"{"
"vec3 l=v;"
"d(l,f,-1.,3.);"
"float i=n(l,.05);"
"m=min(m,i);"
"if(m==i)"
"z=0.;"
"l=v;"
"d(l,f,1.,.3);"
"i=n(l,.01);"
"m=min(m,i);"
"if(m==i)"
"z=1.;"
"}"
"return vec2(m,z);"
"}"
"float C(vec3 v,vec3 y)"
"{"
"float i=0.,m;"
"for(int f=0;f<60;f++)"
"{"
"vec3 l=v+y*i;"
"m=C(l).x;"
"i+=m;"
"if(m<.002||i>20.)"
"break;"
"}"
"return i;"
"}"
"vec3 g(vec2 v)"
"{"
"vec3 l=vec3(0,0,m*2.),z=normalize(vec3(v,.7));"
"float f=C(l,z),c=C(l+z*f).y;"
"vec3 y=vec3(0,0,.1);"
"if(f<10.)"
"{"
"if(c==0.)"
"y=vec3(0,.3,.6);"
"if(c==1.)"
"y=vec3(.5)+vec3(1)*cos(6.3*(vec3(1)*(1.-.4*f)+vec3(0,.66,.33)));"
"}"
"return y;"
"}"
"void main()"
"{"
"vec2 l=(gl_FragCoord.xy*2.-v.xy)/v.y;"
"gl_FragColor=m<29.?"
"vec4(d(l),1):"
"vec4(g(l),1);"
"}";
#endif // SHADER_MINIFIED_H_

View File

@ -1,99 +1,74 @@
uniform float time;
uniform vec2 resolution;
precision mediump float;
uniform float u_time;
uniform vec2 u_resolution;
uniform sampler2D texture_sampler;
uniform sampler2D texts;
float zoom = 1.;
float gTime = 0.;
float getBeat(void) {
return floor(abs(time*4.) / (60./145.) );
}
float getBar(void) {
return floor(abs(time) / (60./145.));
}
vec2 csqr(vec2 a) {
return vec2(a.x * a.x - a.y * a.y, 2. * a.x * a.y);
}
mat2 rot(float a) {
return mat2(cos(a), sin(a), -sin(a), cos(a));
}
float sdBox(vec3 p, vec3 b) {
vec3 q = abs(p) - b;
return length(max(q, 0.0)) + min(max(q.x, max(q.y, q.z)), 0.0);
float sdSphere(vec3 p, float r) {
return length(p)-r;
}
float box(vec3 pos, float scale) {
pos *= scale;
float base = sdBox(pos, vec3(.4, .4, .2)) / 1.5;
pos.xy *= 5.;
pos.y -= 3.5;
pos.xy *= rot(.55);
float result = -base;
return result;
float pMod1(inout float p, float size) {
float halfsize = size*0.5;
float c = floor((p + halfsize)/size);
p = mod(p + halfsize, size) - halfsize;
return c;
}
float box_set(vec3 pos, float time) {
vec3 pos_origin = pos;
pos = pos_origin;
pos.y += sin(gTime * 0.4) * 2.5;
pos.xy *= rot(.8);
float box1 = box(pos, 2. - abs(sin(gTime * 0.4)) * 1.5);
pos = pos_origin;
pos.y -= sin(gTime * 0.4) * 2.5;
pos.xy *= rot(.8);
float box2 = box(pos, 2. - abs(sin(gTime * 0.4)) * 1.5);
pos = pos_origin;
pos.x += sin(gTime * 0.4) * 2.5;
pos.xy *= rot(.8);
float box3 = box(pos, 2. - abs(sin(gTime * 0.4)) * 1.5);
pos = pos_origin;
pos.x -= sin(gTime * 0.4) * 2.5;
pos.xy *= rot(.8);
float box4 = box(pos, 2. - abs(sin(gTime * 0.4)) * 1.5);
pos = pos_origin;
pos.xy *= rot(.8);
float box5 = box(pos, .5) * 6.;
pos = pos_origin;
float box6 = box(pos, .5) * 6.;
float result = max(max(max(max(max(box1, box2), box3), box4), box5), box6);
return result;
}
float map(vec3 pos, float time) {
float box_set1 = box_set(pos, time);
return box_set1;
}
vec4 mainImage2(vec2 fragCoord) {
vec2 p = (fragCoord.xy * 2. - resolution.xy) / min(resolution.x, resolution.y);
vec3 ro = vec3( time * 4., -time , time * 8.);
vec3 ray = normalize(vec3(p, 0.55));
ray.xy = ray.xy * rot(sin(time * .1) * 6.);
ray.yz = ray.yz * rot(sin(time * .01) * .2);
float t = 0.1;
vec3 col = vec3(0.);
float ac = 0.0;
for(int i = 0; i < 99; i++) {
vec3 pos = -ro + ray * t;
pos = mod(pos - 2.5, 4.) - 2.;
gTime = time - float(i) * 0.01;
float d = map(pos, time);
d = max(abs(d), 0.03);
ac += exp(-d * 26.);
t += d * 0.55;
vec2 map(vec3 pos) {
vec3 p = pos;
float d = 1e3;
float mat = 0.;
for (float i = 0.; i < 60.; i++) {
vec3 q = p;
pMod1(q.z, 1.);
q.xy *= rot(sin(u_time*0.25)*3.);
q.x -= 1.5 * cos(i / 3.1415);
q.y -= 1.5 * sin(i / 3.1415);
q.z += (8. - i) * 0.01;
float b = sdSphere(q, 0.02);
d = min(d, b);
if (d == b) {
mat = 0.;
}
}
col = vec3(ac * 0.025);
col += vec3(0.1 + sin(time) * 0.2, 0.5, 0.);
return vec4(col, 1.0 - t * (0.02 + 0.02 * sin(time)));
for (float i = 0.; i < 99.; i++) {
vec3 q = p;
pMod1(q.z, 1.);
q.z -= .5;
q.xy *= rot(cos(-u_time*0.25)*2.);
q.x -= 3. * cos(i / 3.1415);
q.y -= 3. * sin(i / 3.1415);
q.z += i * 0.01;
float b = sdSphere(q, 0.03);
d = min(d, b);
if (d == b) {
mat = 1.;
}
}
for (float i = 0.; i < 20.; i++) {
vec3 q = p;
pMod1(q.z, 0.5);
q.xy *= rot(-sin(u_time)*1.5);
q.x -= .25 * cos(i / 3.1415);
q.y -= .25 * sin(i / 3.1415);
float b = sdSphere(q, 0.01);
d = min(d, b);
if (d == b) {
mat = 2.;
}
}
return vec2(d, mat);
}
vec3 palette(float t) {
@ -104,6 +79,59 @@ vec3 palette(float t) {
return a + b * cos(6.28318 * (c*t+d));
}
vec2 rayMarch2(vec3 ro, vec3 rd) {
float t = 0.;
float d;
float ac = 0.;
for (int i = 0; i < 60; i++) {
vec3 p = ro + rd * t; // "cast" rays
d = map(p).x; // Get distance to objects
t += d; // "march" the ray
ac += exp(-d * 10.);
if (abs(d) < .002 || t > 20.) break;
}
return vec2(t, ac);
}
vec4 mainImage2() {
vec2 uv = (gl_FragCoord.xy * 2. - u_resolution.xy) / u_resolution.y;
//vec3 ro = vec3( u_time * 4., -u_time , u_time * 8.);
vec3 ro=vec3(0,0,u_time );
vec3 ray = normalize(vec3(uv, .7));
ray.xy *= rot(sin(u_time)*0.5);
vec2 rm = rayMarch2(ro, ray);
float d = rm.x;
float ac = rm.y;
vec3 p = ro + ray * d;
float mat = map(p).y;
vec3 col = vec3(0.0235, 0.0157, 0.1451);
if (d < 10.) {
if (mat == 0.) {
col = mix(col, vec3( 0., 0.3, 0.6) + 1. * 0.1*d, 0.4) * ac * 0.3;
}
if (mat == 1.) {
col = mix(col, palette(1. - 0.4*d), 0.2)*ac*0.5;
}
if (mat == 2.) {
col = palette( 0.5 + (1. -0.75 * d ) * 0.4);
}
}
return vec4(col, 1.0);
}
void main(void) {
gl_FragColor = mainImage2();
}
/*
float rand(vec2 co) {
float a = 12.9898;
float b = 78.233;
@ -114,18 +142,18 @@ float rand(vec2 co) {
}
vec3 noise(vec2 uv) {
float rng = rand(vec2(uv.x+time, uv.y));
float rng = rand(vec2(uv.x+u_time, uv.y));
vec3 col = vec3(0.0+rng*0.1, 0.2+rng*0.1, 0.4+rng*0.1);
col.x += sin(uv.x+time*0.2)*0.1;
col.y += sin(uv.y+time*0.2)*0.1;
col.z += sin(uv.y+time*0.2)*0.1;
col.x += sin(uv.x+u_time*0.2)*0.1;
col.y += sin(uv.y+u_time*0.2)*0.1;
col.z += sin(uv.y+u_time*0.2)*0.1;
return col;
}
vec3 wave(vec2 uv, float phase, float _offset, float height, float waveLenght, float color) {
float val = -(sin(phase+uv.x*waveLenght+time) + (uv.y*6.+height)+_offset)*0.055;
val *= 1. + sin(phase + uv.x*waveLenght+time) + (uv.y*6.-height+_offset);
float val = -(sin(phase+uv.x*waveLenght+u_time) + (uv.y*6.+height)+_offset)*0.055;
val *= 1. + sin(phase + uv.x*waveLenght+u_time) + (uv.y*6.-height+_offset);
//return smoothstep(0.0, 1.0, val) * palette(color/360.);
return clamp(val, 0., .9) * palette(color/360.);
}
@ -134,42 +162,44 @@ float gStartTime = 0.;
float gPrevTime = -0.1;
vec4 waveTexture(vec2 uv) {
uv.y = sin(uv.x*16. + time)/32. + uv.y-0.03;
uv.x -= (time-gStartTime)*0.2;
uv.y = sin(uv.x*16. + u_time)/32. + uv.y-0.03;
uv.x -= (u_time-gStartTime)*0.2;
vec4 tex = texture2D(texts, uv);
if (tex.y > 0. && (gPrevTime != gStartTime)) {
gStartTime = time;
gStartTime = u_time;
gPrevTime = gStartTime;
}
return vec4(tex.rgb, 1.0);
}
void TextScroller(out vec4 fragColor, in vec2 fragCoord)
{
// Normalized pixel coordinates (from -1 to 1, origo at 0,0)
vec2 uv = (fragCoord.xy * 2. - resolution.xy) / min(resolution.x, resolution.y);
vec2 uv = (fragCoord.xy * 2. - u_resolution.xy) / min(u_resolution.x, u_resolution.y);
vec3 col = vec3(0., 0.4, 0.6);
col += wave(uv, 0., 1., 3., 1., sin(time+0.3)*90.);
col += wave(uv, sin(time), 0., 3., -1., sin(time-1.2)*120.);
col += wave(uv, -3., 0., 3., 1., sin(time+0.5)*90.);
col += wave(uv, 0., 1., 3., 1., sin(u_time+0.3)*90.);
col += wave(uv, sin(u_time), 0., 3., -1., sin(u_time-1.2)*120.);
col += wave(uv, -3., 0., 3., 1., sin(u_time+0.5)*90.);
vec4 outBuf = waveTexture(uv * 0.1);
fragColor = max(mainImage2(gl_FragCoord.xy)*0.2, vec4(col*outBuf.xyz, 1.0)); // + vec4(random(uv*2.), 1.0);
fragColor = max(mainImage2()*0.2, vec4(col*outBuf.xyz, 1.0)); // + vec4(random(uv*2.), 1.0);
}
void main(void) {
TextScroller(gl_FragColor, gl_FragCoord.xy);
gl_FragColor = mainImage2();
// Get the initial color at this pixel.
// Get the initial color at this pixel.
/*else
{
mainImage2(gl_FragColor, gl_FragCoord.xy);
vec4 l;
vec2 texttop = vec2(0., -.35), pt = (gl_FragCoord.xy / resolution) - texttop;
vec2 texttop = vec2(0., -.35), pt = (gl_FragCoord.xy / u_resolution) - texttop;
if(pt.y > 0.) {
l = gl_FragColor + texture2D(texts, pt);
}
gl_FragColor = l;
} */
}
}
*/