Skip to content

Instantly share code, notes, and snippets.

@numinit
Last active February 23, 2016 04:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save numinit/737562256f6d3934fa50 to your computer and use it in GitHub Desktop.
Save numinit/737562256f6d3934fa50 to your computer and use it in GitHub Desktop.
// The swirly XM stuff, such as the inner part of a resonator.
#ifdef FRAGMENT
precision mediump float;
#endif
#pragma optimize full
varying vec4 v_texCoord0And1;
#ifdef VERTEX
uniform mat4 u_modelViewProject;
uniform float u_elapsedTime;
attribute vec3 a_position; // {x,y,z}
attribute vec2 a_texCoord0; // {u,v}
void main() {
// Compute two texture coordinates xy and zw with different animated offsets for y and w.
// Slightly scale the second coordinate pair to increase the appearance of randomness
// when textures are blended together.
v_texCoord0And1 = vec4(a_texCoord0, a_texCoord0 * 1.35);
v_texCoord0And1 += vec4(0, u_elapsedTime * 0.6, u_elapsedTime * 0.6, u_elapsedTime * 0.45);
gl_Position = u_modelViewProject * vec4(a_position.xyz, 1.0);
}
#endif
#ifdef FRAGMENT
uniform sampler2D u_texture;
uniform vec4 u_teamColor; // {color RGBA}
uniform vec4 u_altColor; // {color RGBA}
void main() {
vec4 base = texture2D(u_texture, v_texCoord0And1.xy);
vec4 scrolled = texture2D(u_texture, v_texCoord0And1.zw * 1.35);
float blend_mask = ((base.g * scrolled.g) + (base.r * scrolled.r)) * 2.0;
// create a 2-hue blend with some color shift adjustment
vec4 colorTint = mix(u_altColor, u_teamColor, blend_mask - 0.25);
// 'linear burn' blending between target color and blend mask
gl_FragColor = colorTint + vec4(blend_mask) - vec4(1.0);
gl_FragColor.a = u_teamColor.a;
}
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment