swwmgz_m/shaders/glsl/NewLogoAnimated.fp

83 lines
2.1 KiB
GLSL

// 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;
}
vec3 GradientMap( in vec3 color )
{
float gray = dot(color,vec3(.333333));
vec2 pos = vec2(gray/2.+.25,0.);
return textureLod(gradtex,pos,0.).rgb;
}
void SetupMaterial( inout Material mat )
{
// 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 *= texture(Layer1,warpcoord(uv),-.5).x;
// first layer, multiply green
base.rgb *= texture(Layer1,uv,-.5).y;
// first layer, add blue
base.rgb += texture(Layer1,uv,-.5).zzz;
// multiply by red fade
base.rgb *= textureLod(fadetex,vec2(.5),0.).x;
// gradient map result
base.rgb = GradientMap(base.rgb);
// color to alpha
base = blacktoalpha(base);
// second layer, alpha blend
vec4 tmp = texture(Layer2,uv,-.5);
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 = texture(Layer3,uv,-.5).xy;
tmp.z = textureLod(fadetex,vec2(.5),0.).y;
tmp.y *= texture(Layer3,clamp(uv+vec2(1.-tmp.z*2.,0.),vec2(0.),vec2(1.)),-.5).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;
}