precision highp float; uniform vec2 resolution; uniform vec2 mouse; uniform float time; uniform sampler2D backbuffer; out vec4 outColor; #define PI 3.1415926535897932384626433832795 #define TAU 6.283185307179586476925286766559 #define tv_ID 1 #define tumami_ID 2 #define screen_ID 3 #define floor_ID 4 #define light_ID 5 //Scene Time float worldTime = 0.0; float TIME = 0.0,SAM = 0.0; int ID = -1; #define S(a) TIME=max(TIME,step(worldTime,SAM+a-0.01)*(worldTime-SAM));ID+=int(step(SAM,worldTime));SAM+=a; //main_camera vec3 mainCameraP = vec3(0.0); vec3 mainCameraD = vec3(0.0); vec2 mainCameraUV = vec2(0.0); //main_object vec3 mainObjectP = vec3(0.0); int objID = 0; //sub object vec3 subObjectP = vec3(-10.0); //Debug float debugfactor = 0.0; //------------------------------- //Debug //-------------------------------- //------------------------------- //Math //------------------------------- //Rotate vec2 rotate(vec2 v, float a) { float s = sin(a); float c = cos(a); mat2 m = mat2(c, -s, s, c); return m * v; } //point simetric vec2 point_symmetric(vec2 p) { vec2 n = normalize(vec2(-1, 1)); return (p.x + p.y > 0.0) ? p : p - 2.0 * n * dot(p,n); } //tangent space void tangentSpaceBasis(vec3 normal,inout vec3 t,inout vec3 b){ if (abs(normal.y) < 0.9) { t = cross(normal, vec3(0, 1, 0)); } else { t = cross(normal, vec3(0, 0, -1)); } t = normalize(t); b = cross(t, normal); b = normalize(b); } //basis transformation vec3 worldtoLoacal(vec3 v,vec3 lx, vec3 ly,vec3 lz){ return vec3(v.x * lx.x + v.y* lx.y + v.z * lx.z, v.x * ly.x + v.y * ly.y + v.z * ly.z, v.x * lz.x + v.y * lz.y + v.z * lz.z); } vec3 localToWorld(const vec3 v, const vec3 lx, const vec3 ly, const vec3 lz) { return vec3(v.x * lx.x + v.y * ly.x + v.z * lz.x, v.x * lx.y + v.y * ly.y + v.z * lz.y, v.x * lx.z + v.y * ly.z + v.z * lz.z); } bool is_inside(float t, float a, float b){ return (t >= a && t <= b); } vec2 kaleido_pmod(vec2 p, float r) { float a = atan(-p.x, -p.y) + PI; float n = TAU / r; float ID = floor(a / n); p.x *= (int(ID) % 2 == 0) ? 1.0 : -1.0; float b = atan(-p.x, -p.y) + PI; ID = floor(b/n); b = ID*n; return rotate(p,-b); } float saturate(float t){ return clamp(t,0.0,1.0); } //-------------------------------- //Hash //-------------------------------- //Blue Noise #define hash(p) fract(sin(mod(dot(p, vec2(12.9898, 78.233)),6.283)) * 43758.5453) //hash float hash11(float s) { return fract(sin(s) * 43758.5453123); } float hash21(vec2 s) { return fract(sin(dot(s, vec2(12.9898, 78.233))) * 43758.5453123); } float hash31(vec3 s) { return fract(sin(dot(s, vec3(12.9898, 78.233, 45.164))) * 43758.5453123); } vec2 hash12(float s) { return fract(sin(vec2(s * 194.2, s * 293.2)) * 43758.5453123); } vec2 hash22(vec2 s) { return fract(sin(vec2(dot(s, vec2(12.9898, 78.233)), dot(s, vec2(45.164, 39.645)))) * 43758.5453123); } vec2 hash32(vec3 s) { return fract(sin(vec2(dot(s, vec3(12.9898, 78.233, 45.164)), dot(s, vec3(39.645, 45.164, 12.9898)))) * 43758.5453123); } vec3 hash13(float s) { return fract(sin(vec3(s * 194.2, s * 293.2, s * 394.2)) * 43758.5453123); } vec3 hash23(vec2 s) { return fract(sin(vec3(dot(s, vec2(12.9898, 78.233)), dot(s, vec2(45.164, 39.645)), dot(s, vec2(39.645, 45.164)))) * 43758.5453123); } vec3 hash33(vec3 s) { return fract(sin(vec3(dot(s, vec3(12.9898, 78.233, 45.164)), dot(s, vec3(39.645, 45.164, 12.9898)), dot(s, vec3(45.164, 12.9898, 78.233)))) * 43758.5453123); } //------------------------------- //Font //------------------------------- #define FontWidth 8 #define FontHeight 8 #define LineMaxLength 40 #define FontSize 37.0 ivec2 font_data[37] = ivec2[]( ivec2(0x00000000,0x00000000), //space ivec2(0x7e91897e,0x00000000), //0 ivec2(0x01ff4121,0x00000000), //1 ivec2(0x71898543,0x00000000), //2 ivec2(0x6e919142,0x00000000), //3 ivec2(0x08ff4838,0x00000000), //4 ivec2(0x8e9191f2,0x00000000), //5 ivec2(0x0e91916e,0x00000000), //6 ivec2(0xc0b08f80,0x00000000), //7 ivec2(0x6e91916e,0x00000000), //8 ivec2(0x6e919162,0x00000000), //9 ivec2(0x7f88887f,0x00000000), //A ivec2(0x6e9191ff,0x00000000), //B ivec2(0x4281817e,0x00000000), //C ivec2(0x7e8181ff,0x00000000), //D ivec2(0x919191ff,0x00000000), //E ivec2(0x909090ff,0x00000000), //F ivec2(0x4685817e,0x00000000), //G ivec2(0xff1010ff,0x00000000), //H ivec2(0x0081ff81,0x00000000), //I ivec2(0x80fe8182,0x00000000), //J ivec2(0x413608ff,0x00000000), //K ivec2(0x010101ff,0x00000000), //L ivec2(0x601060ff,0x000000ff), //M ivec2(0x0c1060ff,0x000000ff), //N ivec2(0x7e81817e,0x00000000), //O ivec2(0x609090ff,0x00000000), //P ivec2(0x7f83817e,0x00000001), //Q ivec2(0x619698ff,0x00000000), //R ivec2(0x4e919162,0x00000000), //S ivec2(0x80ff8080,0x00000080), //T ivec2(0xfe0101fe,0x00000000), //U ivec2(0x0e010ef0,0x000000f0), //V ivec2(0x031c03fc,0x000000fc), //W ivec2(0x340834c3,0x000000c3), //X ivec2(0x300f30c0,0x000000c0), //Y ivec2(0xe1918d83,0x00000081) //Z ); vec3 font(vec2 uv,int id){ vec2 uv1 = uv; uv = uv * 8.0; ivec2 texel = ivec2(uv); int bit_offset = texel.x * FontWidth + texel.y; int s,t; s = font_data[id].x; t = font_data[id].y; int tex = 0; if(bit_offset <= 31){ s = s >> bit_offset; s = s & 0x00000001; tex = s; } else{ t = t >> (bit_offset - 32); t = t & 0x00000001; tex = t; } tex = (abs(uv1.x - 0.5) < 0.5 && abs(uv1.y - 0.5) < 0.5) ? tex : 0; return vec3(tex); } //------------------------------- //SDF //------------------------------- float sdf_union(float d1, float d2) { return min(d1, d2); } float sdf_substract(float d1, float d2) { return max(-d1, d2); } float sdf_intersect(float d1, float d2) { return max(d1, d2); } //box float sdf_box(vec3 p, vec3 b) { vec3 d = abs(p) - b; return min(max(d.x, max(d.y, d.z)), 0.0) + length(max(d, 0.0)); } //sphere float sdf_sphere(vec3 p, float r) { return length(p) - r; } //cylinder float sdf_cylinder(vec3 p, float h, float r) { vec2 d = abs(vec2(length(p.xz), p.y)) - vec2(r, h); return min(max(d.x, d.y), 0.0) + length(max(d, 0.0)); } //ellipsoid float sdf_ellipsoid(vec3 p, vec3 r) { float k1 = length(p / r); float k2 = length(p / (r * r)); return k1 * (k1 - 1.0) / k2; } //plane float sdf_plane(vec3 p, vec3 n, float h) { return dot(p, n) + h; } //BoxFrame float sdf_boxframe( vec3 p, vec3 b, float e ) { p = abs(p )-b; vec3 q = abs(p+e)-e; return min(min( length(max(vec3(p.x,q.y,q.z),0.0))+min(max(p.x,max(q.y,q.z)),0.0), length(max(vec3(q.x,p.y,q.z),0.0))+min(max(q.x,max(p.y,q.z)),0.0)), length(max(vec3(q.x,q.y,p.z),0.0))+min(max(q.x,max(q.y,p.z)),0.0)); } float sdf_cylinder_ana(vec3 p, float h,float r,float thin){ float d1 = sdf_cylinder(p,h,r); float d2 = sdf_cylinder(p,h + 1.0,r - thin); return sdf_substract(d2,d1); } //-------------------------------- //2D SDF //-------------------------------- float d2_sdf_box(vec2 p, vec2 b) { vec2 d = abs(p) - b; return min(max(d.x, d.y), 0.0) + length(max(d, 0.0)); } float d2_sdf_sphere(vec2 p, float r) { return length(p) - r; } float d2_sdf_arc(vec2 p,vec2 sc,float ra, float rb ) { p.x = abs(p.x); return ((sc.y*p.x>sc.x*p.y) ? length(p-sc*ra) : abs(length(p)-ra)) - rb; } float ndot(vec2 a, vec2 b ) { return a.x*b.x - a.y*b.y; } float d2_sdf_rhombus( in vec2 p, in vec2 b ) { p = abs(p); float h = clamp( ndot(b-2.0*p,b)/dot(b,b), -1.0, 1.0 ); float d = length( p-0.5*b*vec2(1.0-h,1.0+h) ); return d * sign( p.x*b.y + p.y*b.x - b.x*b.y ); } float d2_sdf_EquilateralTriangle( in vec2 p ) { const float k = sqrt(3.0); p.x = abs(p.x) - 1.0; p.y = p.y + 1.0/k; if( p.x+k*p.y>0.0 ) p = vec2(p.x-k*p.y,-k*p.x-p.y)/2.0; p.x -= clamp( p.x, -2.0, 0.0 ); return -length(p)*sign(p.y); } //------------------------------- //Struct //------------------------------- struct material_data { int id; vec2 uv; vec3 pos; vec3 normal; vec3 c_pos; vec3 c_dir; float d; vec2 screen_uv; vec3 light_col; float light_dist; }; //------------------------------- //easing //------------------------------- float beat(float t, float e){ float s = sin(t * PI * 2.0 / e); return pow(s,8.0); } float easeInSine(float t){ t = saturate(t); return 1.0 - cos(t * PI * 0.5); } float easeOutSine(float t){ t = saturate(t); return sin(t * PI * 0.5); } float easeInOutSine(float t){ t = saturate(t); return -(cos(PI * t) - 1.0) / 2.0; } float easeInQuad(float t){ t = saturate(t); return t*t; } float easeOutQuad(float t){ t = saturate(t); return 1.0 - (1.0 - t)*(1.0 - t); } float easeInOutQuad(float t){ t = saturate(t); return (t < 0.5) ? 2.0*t*t : 1.0 - pow(-2.0*t + 2.0, 2.0) / 2.0; } float easeOutCubic(float t){ t = saturate(t); return 1.0 - pow(1.0 - t, 3.0); } float easeOutBounce(float t){ const float n1 = 7.5625; const float d1 = 2.75; t = saturate(t); if (t < 1.0/d1) { return n1*t*t; } else if (t < 2.0/d1) { return n1*(t-=(1.5/d1))*t + 0.75; } else if (t < 2.5/d1) { return n1*(t-=(2.25/d1))*t + 0.9375; } else { return n1*(t-=(2.625/d1))*t + 0.984375; } } float easeOutBack(float t){ const float c1 = 1.70158; const float c3 = c1 + 1.0; t = saturate(t); return 1.0 + c3 * pow(t - 1.0, 3.0) + c1 * pow(t - 1.0, 2.0); } float easeInOutJump(float t){ t = saturate(t); return (t - t * t) / 0.25; } float easeInBack(float t){ t = saturate(t); const float c1 = 1.70158; const float c3 = c1 + 1.0; return c3 * t * t * t - c1 * t * t; } //-------------------------------- //Texture //-------------------------------- float voronoi3d(vec3 p,inout float d1,inout float d2){ vec3 sr_i = floor(p); vec3 sr_f = fract(p); d1 = 2.0; d2 = 2.0; for(int i = -1; i <= 1; i++){ for(int j = -1; j <= 1; j++){ for(int k = -1; k <= 1; k++){ vec3 cell_idx = vec3(i,j,k); vec3 cell_offset = cell_idx + hash33(cell_idx + sr_i); vec3 point_dist = abs(sr_f - cell_offset); float dist = max(max(point_dist.x,point_dist.y),point_dist.z); if(dist < d1){ d2 = d1; d1 = dist; } else if(dist < d2){ d2 = dist; } } } } return d1; } vec3 circuit(vec3 pos,vec3 circuit_color){ float d1,d2,d3,d4; vec3 offset = vec3(1) + vec3(0,worldTime * 2.0,0); vec3 scale = vec3(1); voronoi3d(pos,d1,d2); voronoi3d(pos * scale+offset ,d3,d4); float clack_1 = d2 - d1; float clack_2 = d4 - d3; float line_width = 0.04; vec3 col = vec3(0); col = (clack_2 < line_width && clack_1 < 0.01) ? circuit_color : col; col = (abs(clack_1 - 0.02) < 0.005) ? circuit_color : col; return col; } //------------------------------- //sequence //-------------------------------- float time_normalize(float time, float a ,float b){ return saturate((time - a) / (b - a)); } void counter(float t,float a,inout int ID){ ID += (t > a) ? 1 : 0; } //------------------------------- //Map //------------------------------- float brownTV(vec3 p, inout material_data mat) { vec2 screen_size = vec2(0.9, 0.8); vec3 screen_offset = vec3(0.0, -0.2, 1.5); vec3 p1 = p; float scale = 1.0 + 0.2 * abs(p.z + 1.0); p1.xy *= scale; float d1 = sdf_box(p1, vec3(1.0, 1.0, 0.8)) / scale; vec3 p2 = p + vec3(0, 0, 1.0); float d2 = sdf_box(p2, vec3(1.0, 1.0, 0.4)); //screen_box vec3 p3 = p + screen_offset; float d3 = sdf_box(p3, vec3(screen_size, 0.4)); //tumami vec3 tumami_p = p; tumami_p += vec3(-0.7, 0.75, 1.37); tumami_p.yz = rotate(tumami_p.yz, PI * 0.5); float tumami_d1 = sdf_cylinder(tumami_p, 0.1, 0.1); float tumami_d2 = sdf_cylinder(tumami_p + vec3(0.4, 0.0, 0.0), 0.1, 0.1); float tumami_d = sdf_union(tumami_d1, tumami_d2); //screen vec3 p5 = p + vec3(0.0, -screen_offset.y, 0.9); float d5 = sdf_ellipsoid(p5, vec3(2.0, 2.0, 0.5)); float screen_d = sdf_intersect(d5, d3); //material ID int tv_id = tv_ID; int tumami_id = tumami_ID; int screen_id = screen_ID; //uv float r_m = max(screen_size.x, screen_size.y); vec2 r_of = p.xy + screen_offset.xy; mat.uv = r_of / r_m; float d = sdf_union(d1, d2); d = sdf_substract(d3, d); mat.id = tv_id; mat.id = (tumami_d < d) ? tumami_id : mat.id; d = sdf_union(tumami_d, d); mat.id = (screen_d < d) ? screen_id : mat.id; d = sdf_union(screen_d, d); d -= 0.02; return d; } float point_box(vec3 p,float s1,float s2,vec2 b,float rot){ float dif = s1 - s2; vec3 p1 = p - vec3(0,dif + s2,0.); p1.xz = rotate(p1.xz,p.y * rot); float d = sdf_box(p1,vec3(b.x,dif,b.y)); return d; } float ifs_box(vec3 p,float time){ float d = 1000.0; vec3 p1 = p; p1 -= vec3(0.0,0.0,0.0); p1.xy = rotate(p1.xy,time); p1.yz = rotate(p1.yz,time); p1 = abs(p1) - vec3(1.0,0.0,0.1); p1.xy = rotate(p1.xy,time); p1.yz = rotate(p1.yz,time * 2.0 + 2.1); for(int i = 0; i < 4; i++){ float dt = sdf_box(p1,vec3(0.2,2.0,0.5)); p1 = abs(p1) - vec3(1.0,0.0,0.1); p1.xy = rotate(p1.xy,time); p1.yz = rotate(p1.yz,time * 2.0 + 2.1); d = min(dt,d); } return d; } float convergence(float x,float a){ float x1 = x - a; return (step(0.0,x1) * ( - exp(-x1) + 1.0) + step(x1,0.0) * x1) + a; } float light_sdf(vec3 p,inout vec3 light_col){ float d = 100.0; vec3 p1; vec3 centralP = p - mainObjectP; light_col = vec3(1.0); float beat_ = beat(worldTime,1.0) * 0.5 + 0.5; if(ID == 0){ p1 = centralP; d = sdf_sphere(p1,1.0); return d; } else if(ID == 1){ p1 = centralP; d = sdf_sphere(p1,1.0); return d; } else if(ID == 2){ p1 = centralP; d = sdf_sphere(p1,1.0); return d; } else if(ID == 3){ vec3 mainObj_light1 = vec3(1.0,1.0,1.0); //-------------------------------- float normal_time31 = time_normalize(TIME,13.0,14.5); float normal_time32 = time_normalize(TIME,14.0,15.5); float size31 = (1.0 + beat(worldTime,1.0) * 0.1) / (1.001 - easeInQuad(normal_time31)); float size32 = (1.0 + beat(worldTime,1.0) * 0.1) / (easeInQuad(normal_time32) + 0.001); size31 = (1.0 + beat(worldTime,1.0) * 0.1); centralP.y -= -4.0 * (easeInQuad(time_normalize(TIME,39.0,40.0))); centralP.xy = rotate(centralP.xy,PI + TIME); centralP.yz = rotate(centralP.yz,PI + TIME); vec3 p311 = centralP; p311 *= size31; vec3 p312 = centralP; p312 *= size32; float main_d31 = sdf_sphere(p311,1.0) / size31; float main_d32 = sdf_box(p312,vec3(1.0)) / size32; float main_d311; if(objID == 0){ mainObj_light1 = vec3(1.0); main_d311 = sdf_sphere(p311,1.0) / size31; } else if(objID == 1){ mainObj_light1 = vec3(0.1,0.1,1.0); main_d311 = sdf_boxframe(p311,vec3(1.0),0.1) / size31; } else{ mainObj_light1 = vec3(0.1,0.1,1.0); float d331 = sdf_box(p311,vec3(1.0)) / size31; float d332 = sdf_box(abs(p311) - 0.7,vec3(0.6)) / size31; mainObj_light1 = (d331 > d332) ? vec3(0.0) : mainObj_light1; main_d311 = min(d331,d332); } d = main_d311; light_col = mainObj_light1; //-------------------------------- //Pole vec3 p32 = p; p32.x = mod(p32.x, 12.0) - 6.0; p32.z += 10.0; float cycle31 = 4.0; float localTime31 = time_normalize(mod(TIME, cycle31),1.0,2.0); float count_cycle31 = float(int(floor((TIME / cycle31))) % 2); float s31 = mix(-3.0,10.0,easeInOutQuad(time_normalize(mod(TIME, cycle31),1.0,2.0))); float s32 = mix(-3.0,10.0,easeInOutQuad(time_normalize(mod(TIME - 0.5, cycle31),1.0,2.0))); float move_box = point_box(p32,s31,s32,vec2(1.0,1.0),count_cycle31); //Sphere float offset_mask = float(is_inside(TIME,20.0,40.0)); float offset_mask1 = float(is_inside(TIME,18.5,20.0) || bool(offset_mask)); float ring_mask = float(is_inside(TIME,19.0,40.0)); float local_time3 = mod(TIME,2.0); float local_time31 = time_normalize(local_time3,0.0,1.0); float ease31 = easeInOutJump(local_time31); float offset31 = ease31 * 2.5; offset31 -= 3.0; float size_offset31 = 0.1 * easeInOutJump(time_normalize(local_time3,1.0,2.0)); vec3 size331 = vec3(0.5) + vec3(size_offset31,-size_offset31,size_offset31) * offset_mask1; vec3 p33 = p - subObjectP; //Loop { p33.y -= offset31 * offset_mask1; p33.y -= size331.y * offset_mask1; p33.x -= easeInOutQuad(local_time31)* 4.0 * offset_mask; } vec3 ring_p3 = p - subObjectP; float ring_dis; { float local_time33 = mod(TIME-1.0,2.0); float ease_33 = easeOutCubic(local_time33 * 2.0); float radius = 3.0 * ease_33; float thin = 0.2 * (1.0 - ease_33); float fade = ease_33 * 0.3; ring_p3.x = mod(ring_p3.x,4.0) - 2.0; ring_p3.y -= -4.0; ring_p3.y += fade; float ring_d1 = sdf_cylinder_ana(ring_p3,1.0,radius,thin); float ring_d2 = sdf_cylinder_ana(ring_p3 - vec3(4.0,0.0,0.0),1.0,radius,thin); float ring_d3 = sdf_cylinder_ana(ring_p3 + vec3(4.0,0.0,0.0),1.0,radius,thin); ring_dis = min(ring_d1,ring_d2); ring_dis = min(ring_dis,ring_d3); } p33.x = mod(p33.x, 4.0) - 2.0; { p33.xy = rotate(p33.xy,-PI * 4.0 * easeInOutQuad(local_time31) * offset_mask); } vec3 p331 = p33 * size31; vec3 p332 = p33 * size32; float subObj_d; vec3 subObj_col; if(objID == 0){ subObj_col = vec3(1.0); subObj_d = sdf_sphere(p331,0.5) / size31; } else if(objID == 1){ subObj_col = vec3(0.1,0.1,1.0); subObj_d = sdf_box(size331,size331) / size32; } else{ subObj_col = vec3(1.0); subObj_d = sdf_box(p331,size331) / size32; } light_col = (move_box < d) ? vec3(0.0,0.0,0.0) : light_col; d = sdf_union(d,move_box); light_col = (subObj_d < d) ? subObj_col : light_col; d = sdf_union(d,subObj_d); d = bool(ring_mask) ? sdf_union(d,ring_dis) : d; light_col *= beat_; return d; } else if(ID == 4){ float frequent = 4.0; float local_time41 = mod(TIME,4.0); vec3 p41 = centralP; vec3 p42 = p; float mask_pole1 = float(is_inside(local_time41,2.0,3.0)); float mask_pole2 = float(is_inside(local_time41,3.0,4.0)); float mask_light = float(is_inside(local_time41,1.0,2.0)); vec3 object_light = vec3(1.0) * mask_light; vec3 pole_light1 = vec3(0.2,0.2,0.8) * mask_light; vec3 pole_light2 = vec3(0.8,0.2,0.2) * mask_light; //Main Object { float d4_obj = 1000.0; float size1 = 1.0 + beat(worldTime,1.0) * 0.1; p41 *=size1; //lastOffset d4_obj = ifs_box(p41,TIME); light_col = (d < d4_obj) ? vec3(1.0) : light_col; d = min(d,d4_obj / size1); } vec3 pole_color = vec3(1.0); float pole_dist = 10000.0; //pole { float local_pole_time = time_normalize(mod(local_time41,1.0),0.0,1.0); p42.x -= 1.0; p42.x = mod(p42.x, 14.0) - 7.0; p42.z += 2.0 * mask_pole1; p42.z = mod(p42.z, 4.0) - 2.0; float y_up = 10.0; float y_down = -8.0; float ease_1 = easeInOutQuad(local_pole_time); float point_y1; float point_y2; point_y1 = (bool(mask_pole1)) ? y_down + ease_1 * (y_up - y_down) : y_up; point_y2 = (bool(mask_pole1)) ? y_down : y_up + ease_1 * (y_down - y_up) ; float d4_pole = point_box(p42,point_y1,point_y2,vec2(0.3,0.3),0.0); pole_dist =(is_inside(local_time41,2.0,4.0)) ? d4_pole : pole_dist; pole_color = mask_pole1 * pole_light1 + mask_pole2 * pole_light2; } light_col = (pole_dist < d) ? pole_color : object_light; d = sdf_union(d,pole_dist); light_col *= beat_; return d; } else if(ID == 5){ float local_time51 = convergence(TIME,5.0); float local_time52 = time_normalize(TIME,8.0,8.0); float local_time53 = time_normalize(TIME,8.0,12.0); vec3 p51 = centralP; float size51 = 1.0 + beat(local_time51,1.0) * 0.1; p51.z -= 30.0 * easeInBack(local_time53); float offset51 = -20.0; float x5 = p51.z - offset51; size51 += 1.0 / (1.001 - local_time53) - 1.0; p51.xy = rotate(p51.xy,p51.z * local_time53 * PI); p51.xy *=size51; float main_d51 = ifs_box(p51,local_time51); light_col = vec3(1.0); d = main_d51; return d; } } float map(vec3 p, inout material_data mat) { float d; vec3 tvp = p; float loop = 2.0; tvp.xy = mod(tvp.xy, loop) - loop * 0.5; d = brownTV(tvp, mat); vec3 plane_p = p; float p_d1 = sdf_plane(plane_p, vec3(0, 1, 0), 2.0); float p_d2 = sdf_plane(plane_p, vec3(0, -1, 0), 6.0); mat.id = (p_d1 < d) ? floor_ID : mat.id; mat.id = (p_d2 < d) ? floor_ID : mat.id; d = sdf_union(d, p_d1); d = sdf_union(d, p_d2); vec3 light_col = vec3(0.0); float light_d = light_sdf(p,light_col); mat.id = (light_d < d) ? light_ID : mat.id; mat.light_col = light_col; mat.light_dist = light_d; d = sdf_union(d, light_d); return d; } float screen2_map(vec3 p, inout material_data mat) { return sdf_sphere(p - mainObjectP, 0.85); } vec3 get_normal(vec3 p) { vec2 epsiron = vec2(0.001, 0.0); material_data dammy; return normalize(vec3(map(p + epsiron.xyy, dammy) - map(p - epsiron.xyy, dammy), map(p + epsiron.yxy, dammy) - map(p - epsiron.yxy, dammy), map(p + epsiron.yyx, dammy) - map(p - epsiron.yyx, dammy))); } vec3 get_normal2(vec3 p) { vec2 epsiron = vec2(0.001, 0.0); material_data dammy; return normalize(vec3(screen2_map(p + epsiron.xyy, dammy) - screen2_map(p - epsiron.xyy, dammy), screen2_map(p + epsiron.yxy, dammy) - screen2_map(p - epsiron.yxy, dammy), screen2_map(p + epsiron.yyx, dammy) - screen2_map(p - epsiron.yyx, dammy))); } //-------------------------------- //Screens //-------------------------------- vec3 white_noise(vec2 uv, float offset) { return vec3(hash21(uv + TIME + offset * 10.0)); } vec3 screen_sphere(vec2 uv, float offset) { vec3 col = vec3(0.0); vec3 ro = mainCameraP; vec3 rd = normalize(vec3(mainCameraUV, 2.0)); float t; float d = 0.0; material_data dammy; for(int i = 0; i < 20; i++) { t = screen2_map(ro + rd * d, dammy); d += t; if(i < -1) break; } if(t < 0.01) { vec3 normal = get_normal2(ro + rd * d); col = normal * 0.5 + 0.5; } return col; } vec3 screen_hacking(vec2 uv, float offset) { uv = uv * 0.5 + 0.5; vec2 uv1 = uv * 40.0; uv1.y -= floor(TIME) * 1.2; ivec2 index = ivec2(uv1 / vec2(0.8,1.2)); uv1.x = mod(uv1.x,0.8); uv1.y = mod(uv1.y,1.2); int isLine = 10 - int(floor(worldTime)) + int((hash11(offset) - 0.5) * 3.0); bool line_mask = (float(LineMaxLength) * fract(TIME) > float(index.x)) ? true : false; vec2 rnd_index = vec2(hash11(float(index.y) + offset),hash21(vec2(index) + offset)); int max_char = int(rnd_index.x * float(LineMaxLength)); int char_index = int(rnd_index.y * 37.0); //int char_index = int(rnd_index.y * 100.0); //Bug char_index = (index.x < max_char) ? char_index : 0; vec3 col = vec3(font(uv1,char_index)); if(isLine == index.y) { col *= float(line_mask); } else{ col *= float(index.x < LineMaxLength); col *= float(index.y > isLine); } return col * vec3(0.1,1.0,0.1); } vec3 palette( in float t, in vec3 a, in vec3 b, in vec3 c, in vec3 d ) { return a + b*cos( 6.28318*(c*t+d) ); } vec3 screen_kaleidoscope(vec2 uv){ uv *= 10.0; uv = kaleido_pmod(uv,8.0); uv += vec2(1.0) * sin(TIME); uv = rotate(uv,PI*0.25 * TIME); float sum_size = 1.0; float size =1.1; float d = 100.0; float sum = 0.0; for(float i = 0.; i < 9.0; i++){ float td = d2_sdf_rhombus(uv,vec2(0.1 / sum_size,1.0 * sum_size)) / sum_size; float td1 = d2_sdf_box(mod(uv,5.0) - 2.5,vec2(0.03 / sum_size,1.0 * sum_size)) / sum_size; td = min(td,td1); uv = abs(uv) - vec2(1.0,1.0 + 0.7 * sin(floor(TIME))); uv = kaleido_pmod(uv,2.0); d = min(td,d); uv = rotate(uv,PI*0.25 * floor(TIME)); uv *= size; sum_size *= size; sum += (1.0 - d) / 10.0; } vec3 col = palette(sum,vec3(0.5),vec3(0.5),vec3(1.0),vec3(0.0,0.1,0.2)); return col; } vec3 start_stop(vec2 p,int id){ float d_start = d2_sdf_EquilateralTriangle(rotate(p * 2.5,PI * 1.5)) / 2.5 - 0.01; vec2 p1 = abs(p) - vec2(0.15,0.0); float d_stop = d2_sdf_box(p1,vec2(0.05,0.3)); p.x *= -1.0; float d1 = d2_sdf_EquilateralTriangle(rotate((p-vec2(0.3,0.0)) * 2.5,PI * 1.5)) / 2.5; float d2 = d2_sdf_EquilateralTriangle(rotate((p+vec2(0.3,0.0)) * 2.5,PI * 1.5)) / 2.5; float d_hayaokuri = sdf_union(d1,d2); int ID_test = id; float d = d_start; d = (ID_test == 1) ? d_stop : d; d = (ID_test == 2) ? d_hayaokuri : d; return (d < 0.01) ? vec3(1.0) : vec3(0.0); } //color bar vec3 color_bar(vec2 uv){ vec3 col = vec3(1.0); uv = uv * 0.5 + 0.5; int index = int(floor(uv.x * 6.0)); uv.x = (floor(uv.y * 3.0) >= 1.0 ) ? uv.x : ((int(floor(uv.x * 8.0)) % 2 == 0) ? 0.95 : - uv.x); float R = (int(floor(uv.x * 4.0)) % 2 == 0) ? 0.8 : 0.0; float G = (int(floor(uv.x * 2.0)) % 2 == 0) ? 0.8 : 0.0; float B = (int(floor(uv.x * 8.0)) % 2 == 0) ? 0.8 : 0.0; vec3 col1 = vec3(0.0); col1 = (index == 1) ? vec3(0.8) : vec3(0.0); col1 = (index == 0) ? vec3(0.002,0.012,0.05) : col1; col1 = (index == 2) ? vec3(0.025,0.00,0.107) : col1; col = (floor(uv.y * 12.0) >= 3.0 ) ? vec3(R,G,B): col1; return col; } //Logos float logo_sdf_S(vec2 p, float thin){ vec3 col = vec3(0.0); float angle = 4.2; vec2 uv1 = p; uv1.y -= 0.2 + thin; uv1 = rotate(uv1,angle); float d1 = d2_sdf_arc(uv1,vec2(sin(angle),cos(angle)),0.3,thin); vec2 uv2 = p; uv2.y += 0.2 + thin; uv2 = rotate(uv2,angle + PI); float d2 = d2_sdf_arc(uv2,vec2(sin(angle),cos(angle)),0.3,thin); return min(d1,d2); } float logo_sdf_E(vec2 p,float thin){ vec2 uv1 = vec2(p.x,abs(p.y)); float d1 = d2_sdf_box(uv1,vec2(0.4,thin)); uv1.y += -0.7 + thin; float d2 = d2_sdf_box(uv1,vec2(0.4,thin)); float d = min(d1,d2); vec2 uv2 = p; float d3 = d2_sdf_box(uv2 + vec2(0.3,0.0),vec2(thin,0.7)); d = min(d,d3); return d; } float logo_sdf_N(vec2 p,float thin){ vec2 uv1 = abs(p); uv1 += vec2(-0.482,0.0); float d1 = d2_sdf_box(uv1,vec2(thin,0.7)); vec2 uv2 = p; uv2 = rotate(uv2,PI * 0.2); float d2 = d2_sdf_box(uv2,vec2(thin,0.79)); return min(d1,d2); } float logo_sdf_I(vec2 p, float thin){ return d2_sdf_box(p,vec2(thin,0.7)); } float logo_sdf_O(vec2 p, float thin){ vec2 uv1 = p; float d1 = d2_sdf_sphere(uv1,0.7); float d2 = d2_sdf_sphere(uv1,0.7 - thin * 2.0); return sdf_substract(d2,d1); } float stripe_sdf_I(vec2 p,float thin){ vec2 uv3 = p; float d3 = d2_sdf_box(uv3,vec2(thin,0.7)); vec2 uv4 = p + 0.27; uv4 = rotate(uv4,PI * 0.75); uv4.y = mod(uv4.y,0.20) - 0.1; float d4 = d2_sdf_box(uv4,vec2(100.0,0.045)); d3 = sdf_substract(d4,d3); return d3; } vec3 sessions_logo(vec2 uv){ vec3 col = vec3(0.0); float thin = 0.1; float d1 = logo_sdf_S(uv - vec2(0.35,0.0),thin); float d2 = stripe_sdf_I(uv + vec2(0.35,0.0),thin); float d = min(d1,d2); col = (d < 0.0) ? vec3(1.0,1.0,1.0) : vec3(0.0); return col; } vec3 sessions_title(vec2 uv){ vec3 col = vec3(0.0); float thin = 0.1; uv *= 10.0; uv.x += 3.0; float d1 = logo_sdf_S(uv + vec2(1.0,0.0),thin); float d2 = logo_sdf_E(uv,thin); float d3 = logo_sdf_S(uv + vec2(-1.0,0.0),thin); float d4 = logo_sdf_S(uv + vec2(-2.0,0.0),thin); float d5 = logo_sdf_I(uv + vec2(-2.85,0.0),thin); float d6 = logo_sdf_O(uv + vec2(-4.0,0.0),thin); float d7 = logo_sdf_N(uv + vec2(-5.5,0.0),thin); float d8 = logo_sdf_S(uv + vec2(-6.7,0.0),thin); float d = d1; d = min(d,d2); d = min(d,d3); d = min(d,d4); d = min(d,d5); d = min(d,d6); d = min(d,d7); d = min(d,d8); col = (d < 0.01) ? vec3(1.0) : vec3(0.0); return col; } //------------------------------- //Materialing //------------------------------- //blinn-phong inportance sampling vec3 bp_IS(vec2 rnd,float n){ float theta = acos(pow(1.0 - rnd.x,1.0 / (1.0 + n))); float phi = 2.0 * PI * rnd.y; return vec3(sin(theta) * cos(phi), cos(theta),sin(theta) * sin(phi)); } vec3 screen_color(material_data mat){ bool s = false; vec2 index = floor(mat.pos.xy * 0.5); vec2 uv = mat.uv; uv *= 1.0 + length(mat.uv)*length(mat.uv) * 0.05; vec3 screen_col = vec3(0.0); float offset = hash21(index); //White_Noise vec3 noise = white_noise(uv,offset); switch(ID){ case 0: screen_col = color_bar(uv); break; case 1: vec3 logo = sessions_logo(uv); vec3 hacking = screen_hacking(uv,offset); float noise_mask = step(-sin((TIME - 0.0)* TIME),-0.2); bool logo_mask = TIME > 10.0; vec3 logo_col = mix(vec3(0.0),logo,TIME - 13.0); bool logo_mask2 = TIME < 15.0; screen_col = mix(hacking,noise,noise_mask); screen_col = (logo_mask) ? logo_col : screen_col; break; case 2: screen_col = noise; screen_col = (index.x == 0.0 && index.y == 0.0 && TIME < 10.0) ? screen_sphere(uv,offset) : screen_col; screen_col = (TIME < 2.0) ? noise : screen_col; break; case 3: vec3 hacking_3 = screen_hacking(uv,offset); vec3 colorbar = color_bar(uv); float mask_31 = TIME * 10.0 - 30.0; bool mask_32 = is_inside(TIME,3.0,9.0); bool mask_sub = bool(int(index.x + 1.0)%2 == 0 && index.y == 0.0); screen_col = (index.x < mask_31) ? hacking_3 : noise; screen_col = (mask_32 && mask_sub) ? colorbar : screen_col; break; case 4: float local_time4 = mod(TIME,4.0); vec3 kaleido_scope = screen_kaleidoscope((mat.pos.xy - vec2(1.0)) * 0.5 ); screen_col = vec3(0.0); screen_col = (local_time4 > 2.0) ? kaleido_scope : screen_col; break; case 5: screen_col = vec3(0.0); screen_col = mix(screen_col,start_stop((mat.pos.xy - vec2(1.0,2.0) )* 0.2,1),step(4.0,TIME)); screen_col = mix(screen_col,start_stop((mat.pos.xy - vec2(1.0,2.0)) * 0.2,2),step(6.0,TIME)); screen_col = mix(screen_col,noise,step(13.0,TIME)); screen_col = mix(screen_col,sessions_title(mainCameraUV * 0.33),step(15.0,TIME)); break; default: screen_col = vec3(1.0); break; }; return screen_col; } //Anbient Occulusion vec3 randomSphereDir(vec2 rnd) { float s = rnd.x*PI*2.; float t = rnd.y*2.-1.; return vec3(sin(s), cos(s), t) / sqrt(1.0 + t * t); } vec3 randomHemisphereDir(vec3 dir, float i) { vec3 v = randomSphereDir( vec2(hash11(i+1.), hash11(i+2.)) ); return v * sign(dot(v, dir)); } float ambientOcclusion(vec3 p, vec3 n) { float maxDist = 1.0; float falloff = 1.0; const int nbIte = 32; const float nbIteInv = 1./float(nbIte); const float rad = 1.-1.*nbIteInv; //Hemispherical factor (self occlusion correction) float ao = 0.0; for( int i=0; i 0.33 && floor_x < 0.66, floor_x > 0.66); vec3 ro = vec3(1., 1.5, -10.0); vec3 rd = normalize(vec3(uv, 2.0)); float rtime = PI * 0.0; rd.xz = rotate(rd.xz, rtime); float debug_t = 0.0; //------------------------------- //MainObject and Camera Move { if(ID == 0){ mainObjectP = vec3(0.0,0.0,0.0); } else if(ID == 1){ mainObjectP = vec3(0.0,0.0,0.0); } else if(ID == 2){ ro = vec3(1.0,1.0,-10.0); mainObjectP = vec3(1.0,1.0,10.0); float st[6] = float[]( 3.0,5.0,7.0,9.0,11.0,12.0 ); int shot_ID = 0; counter(TIME,st[0],shot_ID); counter(TIME,st[1],shot_ID); counter(TIME,st[2],shot_ID); counter(TIME,st[3],shot_ID); counter(TIME,st[4],shot_ID); vec3 offset = vec3(0.0); if(shot_ID == 1){ float offset_bounce = easeOutBounce(time_normalize(TIME,st[0],st[1])) * 10.0; offset = vec3(0.0,0.0,-offset_bounce); mainObjectP += offset; } else if(shot_ID == 2){ float offset_charge = (1.0 - smoothstep(0.0,1.0,time_normalize(TIME,st[1],st[2]))) * 10.0; offset = vec3(0.0,0.0,-offset_charge); mainObjectP += offset; } else if(shot_ID == 3){ float n_time3 = time_normalize(TIME,st[2],st[3]); offset = (hash13(TIME) * 2.0 - 1.0) * 0.05; n_time3 = smoothstep(0.0,1.0,n_time3); ro.z += n_time3 * 0.4; rd = normalize(vec3(uv,2.0 + n_time3 * 0.5)); mainObjectP += offset; } else if(shot_ID == 4){ float n_time4 = time_normalize(TIME,st[3],st[4]); vec3 pos_end = vec3(1.0,1.0,-20.0); vec3 camera_end = vec3(1.0,1.0,-30.0); float offset_shot = mix(0.0,-20.0,easeOutBack(n_time4)); mainObjectP = mix(mainObjectP,pos_end,easeOutBack(n_time4)); ro = mix(ro,camera_end,easeOutBack(n_time4)); } } else if(ID == 3){ mainObjectP = vec3(1.0,1.0,-20.0); vec3 sub_basis3 = vec3(1.0,1.0,20.0); ro = vec3(1.0,1.0,-30); float st3[5] = float[]( 3.0,10.0,40.0,50.0,80.0 ); int shot_ID3 = 0; counter(TIME,st3[0],shot_ID3); counter(TIME,st3[1],shot_ID3); float time_offset = worldTime - 37.0; float local_time_31 = time_normalize(TIME - suv.y,16.0,18.0); objID = 0; objID = (local_time_31 > 0.33) ? 1 : objID; objID = (local_time_31 > 0.66) ? 2 : objID; debug_t = local_time_31; if(shot_ID3 == 0){ mainObjectP.x += time_offset; ro = mainObjectP + vec3(0.0,0.0,-10.0); } else if(shot_ID3 == 1){ mainObjectP.x += time_offset; ro = mainObjectP + vec3(0.0,0.0,-10.0); float n_time32 = time_normalize(TIME,st3[0],10.0); subObjectP = vec3(1.0,1.0,-smoothstep(0.0,1.0,n_time32) * 15.0); } else if(shot_ID3 == 2){ mainObjectP.x += time_offset; ro = mainObjectP + vec3(0.0,0.0,-10.0); subObjectP = vec3(1.0,1.0,-15.0); } } else if(ID == 4){ mainObjectP = vec3(1.0,1.0,-10.0); ro = vec3(1.0,1.0,-30.0); } else if(ID == 5){ mainObjectP = vec3(1.0,1.0,-10.0); ro = vec3(1.0,1.0,-30.0); rd = normalize(vec3(uv,2.0)); } } mainCameraP = ro; mainCameraD = rd; mainCameraUV = uv; vec3 col = Raymarching(ro, rd, uv); col = tone_mapping(col); col = gamma_correction(col); col *= hash21(uv + TIME) * 0.2 + 0.8; float viggnet_power = 0.2; col *= 1.0 - viggnet * viggnet_power; col = liftGammaGain(col,LIFT,GAMMA,GAIN); texuv = texuv * 2.0 - 1.0; vec2 uvR = texuv * (1.0 + length(texuv) * 0.01); vec2 uvG = texuv * (1.0 + length(uvR) * 0.005); vec2 uvB = texuv * (1.0 + length(uvR) * 0.000); float R = texture(backbuffer,uvR * 0.5 + 0.5).x; float G = texture(backbuffer,uvG * 0.5 + 0.5).y; float B = texture(backbuffer,uvB * 0.5 + 0.5).z; col = mix(vec3(R,G,B),col,0.7); //FadeIn Out col = mix(vec3(0.0),col,time_normalize(worldTime,0.0,4.0)); col = mix(col,sessions_title(mainCameraUV * 0.33),time_normalize(worldTime,134.0,137.0)); outColor = vec4(col.xyz,1); }