// animated DEMOLITIONIST logo #define PI 3.14159265 vec2 warpcoord( in vec2 uv ) { vec2 offset; offset.y = sin(PI*2.*(uv.x*8.+timer*.25))*.005; offset.x = cos(PI*2.*(uv.y*4.+timer*.25))*.005; return uv+offset; } float hardlight( in float a, in float b ) { if ( 2.*a < 1. ) return clamp(2.*a*b,0.,1.); return clamp(1.-2.*(1.-b)*(1.-a),0.,1.); } // based on gimp color to alpha, but simplified vec4 blacktoalpha( in vec4 src ) { vec4 dst = src; float alpha = 0.; float a; a = clamp(dst.r,0.,1.); if ( a > alpha ) alpha = a; a = clamp(dst.g,0.,1.); if ( a > alpha ) alpha = a; a = clamp(dst.b,0.,1.); if ( a > alpha ) alpha = a; if ( alpha > 0. ) { float ainv = 1./alpha; dst.rgb *= ainv; } dst.a *= alpha; return dst; } vec4 BilinearSample( in sampler2D tex, in vec2 pos, in vec2 size, in vec2 pxsize ) { vec2 f = fract(pos*size); pos += (.5-f)*pxsize; vec4 p0q0 = texture(tex,pos); vec4 p1q0 = texture(tex,pos+vec2(pxsize.x,0)); vec4 p0q1 = texture(tex,pos+vec2(0,pxsize.y)); vec4 p1q1 = texture(tex,pos+vec2(pxsize.x,pxsize.y)); vec4 pInterp_q0 = mix(p0q0,p1q0,f.x); vec4 pInterp_q1 = mix(p0q1,p1q1,f.x); return mix(pInterp_q0,pInterp_q1,f.y); } vec3 GradientMap( in vec3 color ) { float gray = dot(color,vec3(.333333)); vec2 size = vec2(512.,8.); vec2 pxsize = 1./size; return BilinearSample(gradtex,vec2(gray/2.+.25,0.),size,pxsize).rgb; } void SetupMaterial( inout Material mat ) { // store these to save some time vec2 size = vec2(textureSize(Layer1,0)); vec2 pxsize = 1./size; // y'all ready for this multilayered madness? vec2 uv = vTexCoord.st; // base blank layer vec4 base = vec4(1.); // first layer, warp then multiply red base.rgb *= BilinearSample(Layer1,warpcoord(uv),size,pxsize).x; // first layer, multiply green base.rgb *= BilinearSample(Layer1,uv,size,pxsize).y; // first layer, add blue base.rgb += BilinearSample(Layer1,uv,size,pxsize).zzz; // multiply by red fade base.rgb *= texture(fadetex,vec2(.5)).x; // gradient map result base.rgb = GradientMap(base.rgb); // color to alpha base = blacktoalpha(base); // second layer, alpha blend vec4 tmp = BilinearSample(Layer2,uv,size,pxsize); vec4 tmp2; tmp2.a = tmp.a+base.a*(1.-tmp.a); tmp2.rgb = (tmp.rgb*tmp.a+base.rgb*base.a*(1.-tmp.a))/tmp2.a; base = tmp2; // third layer, hard light with two multiplied masks tmp.xy = BilinearSample(Layer3,uv,size,pxsize).xy; tmp.z = texture(fadetex,vec2(.5)).y; tmp.y *= BilinearSample(Layer3,clamp(uv+vec2(1.-tmp.z*2.,0.),vec2(0.),vec2(1.)),size,pxsize).z; tmp2.r = hardlight(base.r,tmp.x); tmp2.g = hardlight(base.g,tmp.x); tmp2.b = hardlight(base.b,tmp.x); base.rgb = mix(base.rgb,tmp2.rgb,tmp.y); // clamp base = clamp(base,vec4(0.),vec4(1.)); // ding, logo's done mat.Base = base; }