Skip to content

Instantly share code, notes, and snippets.

@AaronMeyers
Created January 17, 2014 16:54
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 AaronMeyers/6ffafda801d886475c64 to your computer and use it in GitHub Desktop.
Save AaronMeyers/6ffafda801d886475c64 to your computer and use it in GitHub Desktop.
precision highp float;
varying vec2 texCoordVarying;
uniform sampler2D tex0;
uniform vec2 texCoordScale;
uniform vec2 texStep;
uniform float texStepScale;
void main() {
vec2 uv = texCoordVarying * texCoordScale;
vec2 stepSize = texStep * texStepScale;
float center = texture2D( tex0, uv ).r;
float topLeft = texture2D( tex0, uv + vec2( -1.0, -1.0 ) * stepSize ).r;
float left = texture2D( tex0, uv + vec2( -1.0, 0.0 ) * stepSize ).r;
float bottomLeft = texture2D( tex0, uv + vec2( -1.0, 1.0 ) * stepSize ).r;
float top = texture2D( tex0, uv + vec2( 0.0, -1.0 ) * stepSize ).r;
float bottom = texture2D( tex0, uv + vec2( 0.0, 1.0 ) * stepSize ).r;
float topRight = texture2D( tex0, uv + vec2( 1.0, -1.0 ) * stepSize ).r;
float right = texture2D( tex0, uv + vec2( 1.0, 0.0 ) * stepSize ).r;
float bottomRight = texture2D( tex0, uv + vec2( 1.0, 1.0 ) * stepSize ).r;
float dX = topRight + 2.0 * right + bottomRight - topLeft - 2.0 * left - bottomLeft;
float dY = bottomLeft + 2.0 * bottom + bottomRight - topLeft - 2.0 * top - topRight;
vec3 N = normalize( vec3( dX, dY, 0.01 ) );
N *= 0.5;
N += 0.5;
gl_FragColor.rgb = N;
gl_FragColor.a = 1.0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment