So, I decided to do a 1k webgl version of my JS1K entry I did in 2010, http://js1k.com/2010-first/demo/704. This version also adds reflections, and some fake soft shadows.
_='fL(x in g)g[x[i=0]+x[6]]=g[x];with(g)p=cP(j="attribute 4 a;gl_PosiQn=ak=35633j="pZcision highp f;E Rs;R3 n){Zturn min.x)+%n,n.G+)))-1-n)n+3.);}Rm,l;3 vUMI9)1N,yU|2N,%H+7.,I6|1H)+v,c=v-yx=J%0c$d=c x/x* yJc,x$z,g=.M0)T#7+pow5H.7,g.z=1.-mI0d=Zflect(d,cy=z,l=zT#<2&&abs(l)+3;lL=4(v*g.z,1)--kvA(loY2,5126,eV(ugY$bfX-=67McB($bDX,new F32Ar^y([-3,-3,1]k+82$t=gfY,"s"m=X=funcQ){dr(4,E1f(t,)-m3);ZquestAniWQnF^meX)})();<2)c!~OG-@.xyxyx)$x!(x>?K0O1OK1O0)Wx(z+~$OG/H%G)+,vnLWlize(3(),%if^ct(z/H).(dot(c,y-G +(-1.+2.*Ld.sS(s,jce(saSY,slength(;z=y+d*m;m+=GN001*Date.now(/`height+".loatn(`width+"..5)*void Wi){=)+.2xI.yveccos(s-s*H;}",s=cS(gl_F^gCo1,!=z<-2?#;if(z$)%s@z-gEunifLmGz)H4.I*.Jcross(Kz>?LorM0,N0.O):QtioRf T;m=.1U=%I7WmaX(kY(pZre^ra`"+a.|2N+~M0y@';for(Y in $='~|`^ZYXWUTRQONMLKJIHGE@%$#! ')with(_.split($[Y]))_=join(pop());eval(_)
Xz0nZkwoeCBpbiBnKWdbeFtpPTBdK3hbNl1dPWdbeF07d2l0aChnKXA9Y1AoBWo9ImF0dHJpYnV0ZSAaNCBhOxdnbF9Qb3NpUW49YR1rPTM1NjMzC2o9InBaY2lzaW9uIGhpZ2hwIGYSO0UgUnM7UhMaMyBuKXtadHVybiBtaRMMBAZuLngpKyUFbhksBm4uRysbKSkpLTEVLQYMbikcBW4ZKzMuKTt9F1JtLGw7GjMgdlUFTRtJOSkWMU4seVV8Mk4sJRZIK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bihwb3AoKSk7ZXZhbChfKQ==
//Original source before manual size optimizations
//VERTEX_SHADER
var vs=""+
"attribute vec2 p;"+
"void main(){"+
" gl_Position=vec4(p,0,1);"+
"}";
//FRAGMENT_SHADER
var fs=""+
//"#ifdef GL_ES"+
"precision highp float;"+
//"#endif"+
""+
"uniform float t;"+
"uniform vec2 resolution;"+
""+
"vec2 iRes=vec2("+a.width+","+a.height+");"+
""+
"float stime=sin(t);"+
"float ctime=cos(t);"+
""+
"float inObj(in vec3 p){"+
" float oP=length(p);"+
" p.x=sin(p.x)+stime;"+
" p.z=sin(p.z)+ctime;"+
" return float(min(length(p)-1.5-sin(oP-t*4.0),p.y+3.0));"+
"}"+
""+
"void main(void){"+
" vec2 iRes=vec2(iRes);"+
" vec2 vPos=-1.0+2.0*gl_FragCoord.xy/iRes;"+
""+
" vec3 vuv=vec3(stime,1,0);"+
" vec3 vrp=vec3(sin(t*0.7)*10.0,0,cos(t*0.9)*10.0); "+
" vec3 prp=vec3(sin(t*0.7)*20.0+20.0,stime*4.0+4.0+3.0,cos(t*0.6)*20.0+14.0)+vrp;"+
""+
" vec3 vpn=normalize(vrp-prp);"+
" vec3 u=normalize(cross(vuv,vpn));"+
" vec3 v=cross(vpn,u);"+
" vec3 scrCoord=vpn+vPos.x*u*iRes.x/iRes.y+vPos.y*v;"+
" vec3 scp=normalize(scrCoord);"+
""+
" const vec3 e = vec3(0.1,0,0);"+
" const float maxd=80.0;"+
""+
" float s=0.1;"+
" vec3 c,p,n;"+
""+
" float f=-(prp.y-2.5)/scp.y;"+
" if (f>0.0) p=prp+scp*f;"+
" else f=maxd;"+
""+
" vec3 outc=vec3(0,0,0);"+
""+
" float far=0.0;"+
" for (int ref=0;ref<=1;ref++){"+
" if (ref>0){"+
" scp=reflect(scp,n);"+
" prp=p;"+
" s=0.1;f=0.1;"+
" }"+
""+
" for(int i=0;i<32;i++){"+
" f+=s;"+
" p=prp+scp*f;"+
" s=inObj(p);"+
" if (abs(s)<.01||f>maxd||p.y>2.5||(ref>0&&i>16)) break;"+
" }"+
" "+
" if (f<maxd&&p.y<2.5){"+
" if(p.y<-2.5){"+
" if (fract(p.x/4.0)>.5)"+
" if (fract(p.z/4.0)>.5)"+
" c=vec3(0,0,0);"+
" else"+
" c=vec3(1,1,1);"+
" else"+
" if (fract(p.z/4.0)>.5)"+
" c = vec3(1,1,1);"+
" else"+
" c = vec3(0,0,0);"+
" c=c*max(inObj(vec3(p.x,p.y+1.0,p.z)),0.5);"+
" n=vec3(0,1,0);"+
" }"+
" else{"+
" float d=length(p);"+
" c=vec3((sin(d*.25-t*4.0)+1.0)/2.0,"+
" (stime+1.0)/2.0,"+
" (sin(d-t*4.0)+1.0)/2.0);"+
" n=normalize("+
" vec3(s-inObj(p-e.xyy),"+
" s-inObj(p-e.yxy),"+
" s-inObj(p-e.yyx)));"+
" }"+
" float b=dot(n,normalize(prp-p));"+
" if (ref==0) {"+
" outc=((b+0.2)*c+pow(b,54.0))*0.7;"+
" far=1.0-f*.01;"+
" } else {"+
" if (prp.y>-2.4) outc+=(b+0.2)*c*0.3;"+
" }"+
" }"+
" else break;"+
" }"+
" gl_FragColor=vec4(outc*far,1.0);"+
"}";
function compileShader(g, shaderSource, shaderType) {
var shader=g.createShader(shaderType);
g.shaderSource(shader, shaderSource);
g.compileShader(shader);
//******** DEBUG ****************
var ok = g.getShaderParameter(shader,g.COMPILE_STATUS);
if (!ok) {throw "Shader Compile Error:" + g.getShaderInfoLog(shader);}
//******** DEBUG ****************
return shader;
}
function createProgram(vertexShaderSource,fragmentShaderSource){
var p=g.createProgram();
g.attachShader(p,compileShader(g,vs,g.VERTEX_SHADER));
g.attachShader(p,compileShader(g,fs,g.FRAGMENT_SHADER));
g.linkProgram(p);
//******** DEBUG ****************
var ok= g.getProgramParameter(p,g.LINK_STATUS);
if (!ok){throw ("Shader Link Error:" +g.getProgramInfoLog(p));}
//******** DEBUG ****************
g.useProgram(p);
return p;
}
//Create Shader
var p=createProgram(vs,fs);
//Set Shader vertex data
var pLocation=g.getAttribLocation(p,"p");
g.bindBuffer(g.ARRAY_BUFFER,g.createBuffer());
g.bufferData(g.ARRAY_BUFFER,new Float32Array(
[-1,-1,
1,-1,
-1, 1,
-1, 1,
1,-1,
1, 1]),g.STATIC_DRAW);
g.enableVertexAttribArray(pLocation);
g.vertexAttribPointer(pLocation,2,g.FLOAT,false,0,0);
//Set Shader time variable t
var tLocation=g.getUniformLocation(p,"t");
//Get Inicial Time
var initTime=Date.now();
//Render Frame loop
function draw(){
//Set time
g.uniform1f(tLocation,(Date.now()-initTime)*0.001);
//Draw
g.drawArrays(g.TRIANGLES,0,6);
requestAnimationFrame(draw);
}
draw();