I created this one by accident when I was trying to create a filter that would add cyan and magenta edges to objects in a scene. Like the Far Cry blood-dragon text. Anyway, what happened was I created a filter that automatically generates a normal map for a given frame / image. Think of the potential for automatically normal mapped textures! Actually, I have no idea if it'll work, it just looks like it will. This one's also for HLSL.
/* Normal */ float4 normal(float2 texcoord : TEXCOORD0) { return tex2D(s0, texcoord); } /* Find Edges / Sobel */ float4 sobel(float2 texcoord : TEXCOORD0) { float inv_width = 1.0 / 1920; float inv_height = 1.0 / 1080; float4 top = tex2D(s0, float2(texcoord.x, texcoord.y + inv_height)); float4 bottom = tex2D(s0, float2(texcoord.x, texcoord.y - inv_height)); float4 left = tex2D(s0, float2(texcoord.x - inv_width, texcoord.y)); float4 right = tex2D(s0, float2(texcoord.x + inv_width, texcoord.y)); float4 tl = tex2D(s0, float2(texcoord.x - inv_width, texcoord.y + inv_height)); float4 tr = tex2D(s0, float2(texcoord.x + inv_width, texcoord.y + inv_height)); float4 bl = tex2D(s0, float2(texcoord.x - inv_width, texcoord.y - inv_height)); float4 br = tex2D(s0, float2(texcoord.x + inv_width, texcoord.y - inv_height)); right = right * float4(1.0, 0.0, 1.0, 1.0); left = left * float4(0.0, 1.0, 1.0, 1.0); //This is the main change float4 sx = -tl - 2 * left - bl + tr + 2 * right + br; float4 sy = -tl - 2 * top - tr + bl + 2 * bottom + br; float4 returnCol = sqrt(sx * sx + sy * sy); returnCol.w = 1.0; return returnCol; } float3 CustomPass(float4 position : SV_Position, float2 texcoord : TEXCOORD0) : SV_Target { float4 out_colour = normal(texcoord) * 1.0 / sobel(texcoord); return pow(out_colour, 1.5); }