Skip to content

Instantly share code, notes, and snippets.

@xoppa
Created August 21, 2014 21:58
Show Gist options
  • Save xoppa/b2ec35652c4c2deb72c7 to your computer and use it in GitHub Desktop.
Save xoppa/b2ec35652c4c2deb72c7 to your computer and use it in GitHub Desktop.
outline shader
#ifdef GL_ES
#define LOWP lowp
precision mediump float;
#else
#define LOWP
#endif
const float offset = 1.0 / 128.0;
varying vec2 v_texCoords;
uniform sampler2D u_texture;
void main()
{
vec4 col = texture2D(u_texture, v_texCoords);
if (col.a > 0.5)
gl_FragColor = col;
else {
float a = texture2D(u_texture, vec2(v_texCoords.x + offset, v_texCoords.y)).a +
texture2D(u_texture, vec2(v_texCoords.x, v_texCoords.y - offset)).a +
texture2D(u_texture, vec2(v_texCoords.x - offset, v_texCoords.y)).a +
texture2D(u_texture, vec2(v_texCoords.x, v_texCoords.y + offset)).a;
if (col.a < 1.0 && a > 0.0)
gl_FragColor = vec4(0.0, 0.0, 0.0, 0.8);
else
gl_FragColor = col;
}
}
attribute vec4 a_position;
attribute vec2 a_texCoord0;
uniform mat4 u_projTrans;
varying vec2 v_texCoords;
void main()
{
v_texCoords = a_texCoord0;
gl_Position = u_projTrans * a_position;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment