// Sobel Edge Detector based from ATI Video shader float sampleDist = 1.0f/512.0f; // distance one pixel in u/v sampler2D image : register(s0); static const float2 offsets[8] = { -1, -1, 0, -1, 1, -1, -1, 0, // 0, 0, // no center pixel 1, 0, -1, 1, 0, 1, 1, 1, }; float4 main( float4 Pos : POSITION, float2 texCoord: TEXCOORD0) : COLOR { int i =0; float4 c = .5; float2 texCoords; float4 texSamples[8]; float4 vertGradient; float4 horzGradient; float4 color; color = tex2D( image, texCoord ); for(i =0; i < 8; i++) { texCoords = texCoord + sampleDist * offsets[i]; // add sample offsets stored in c10-c17 (inclusive) // take sample texSamples[i] = tex2D( image, texCoords); // convert to b&w texSamples[i] = dot(texSamples[i], .333333f); } // VERTICAL Gradient vertGradient = -(texSamples[0] + texSamples[5] + 2*texSamples[3]); vertGradient += (texSamples[2] + texSamples[7] + 2*texSamples[4]); // Horizontal Gradient horzGradient = -(texSamples[0] + texSamples[2] + 2*texSamples[1]); horzGradient += (texSamples[5] + texSamples[7] + 2*texSamples[6]); // we could approximate by adding the abs value..but we have the horse power c = 1 - sqrt( horzGradient*horzGradient + vertGradient*vertGradient ); if ( c.r > 0.4f ) color = c; return color; }