Skip to content

Instantly share code, notes, and snippets.

@ErikHellman
Created July 22, 2013 17:17
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 ErikHellman/6055718 to your computer and use it in GitHub Desktop.
Save ErikHellman/6055718 to your computer and use it in GitHub Desktop.
GLES Shader for edge detection
#extension GL_OES_EGL_image_external : require
precision mediump float;
varying vec2 vTextureCoord;
uniform samplerExternalOES sTexture;
uniform float uResS;
uniform float uResT;
void main() {
vec3 irgb = texture2D(sTexture, vTextureCoord).rgb;
float ResS = uResS;
float ResT = uResT;
vec2 stp0 = vec2(1./ResS, 0.);
vec2 st0p = vec2(0., 1./ResT);
vec2 stpp = vec2(1./ResS, 1./ResT);
vec2 stpm = vec2(1./ResS, -1./ResT);
const vec3 W = vec3(0.2125, 0.7154, 0.0721);
float i00 = dot(texture2D(sTexture, vTextureCoord).rgb, W);
float im1m1 = dot(texture2D(sTexture, vTextureCoord-stpp).rgb, W);
float ip1p1 = dot(texture2D(sTexture, vTextureCoord+stpp).rgb, W);
float im1p1 = dot(texture2D(sTexture, vTextureCoord-stpm).rgb, W);
float ip1m1 = dot(texture2D(sTexture, vTextureCoord+stpm).rgb, W);
float im10 = dot(texture2D(sTexture, vTextureCoord-stp0).rgb, W);
float ip10 = dot(texture2D(sTexture, vTextureCoord+stp0).rgb, W);
float i0m1 = dot(texture2D(sTexture, vTextureCoord-st0p).rgb, W);
float i0p1 = dot(texture2D(sTexture, vTextureCoord+st0p).rgb, W);
float h = -1.*im1p1 - 2.*i0p1 - 1.*ip1p1 + 1.*im1m1 + 2.*i0m1 + 1.*ip1m1;
float v = -1.*im1m1 - 2.*im10 - 1.*im1p1 + 1.*ip1m1 + 2.*ip10 + 1.*ip1p1;
float mag = length(vec2(h, v));
vec3 target = vec3(mag, mag, mag);
gl_FragColor = vec4(mix(irgb, target, 1.0),1.);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment