Sobel Edge Detection Shader Example
uniform mat4 worldViewProjection; attribute vec4 position; attribute vec2 texCoord0; varying vec2 v_imageCoord; void main() { gl_Position = worldViewProjection * position; v_imageCoord = texCoord0; } // #o3d SplitMarker uniform sampler2D image; uniform vec2 imageIncrement; varying vec2 v_imageCoord; float lum(vec4 c) { return dot(c.xyz, vec3(0.3, 0.59, 0.11)); } void main() { vec2 imageCoord = v_imageCoord; float t00 = lum(texture2D(image, imageCoord + imageIncrement * vec2(-1, -1))); float t10 = lum(texture2D(image, imageCoord + imageIncrement * vec2( 0, -1))); float t20 = lum(texture2D(image, imageCoord + imageIncrement * vec2( 1, -1))); float t01 = lum(texture2D(image, imageCoord + imageIncrement * vec2(-1, 0))); float t21 = lum(texture2D(image, imageCoord + imageIncrement * vec2( 1, 0))); float t02 = lum(texture2D(image, imageCoord + imageIncrement * vec2(-1, 1))); float t12 = lum(texture2D(image, imageCoord + imageIncrement * vec2( 0, 1))); float t22 = lum(texture2D(image, imageCoord + imageIncrement * vec2( 1, 1))); vec2 grad; grad.x = t00 + 2.0 * t01 + t02 - t20 - 2.0 * t21 - t22; grad.y = t00 + 2.0 * t10 + t20 - t02 - 2.0 * t12 - t22; float len = length(grad); gl_FragColor = vec4(len, len, len, 1.0); } // #o3d MatrixLoadOrder RowMajor