//http://www.smart-page.net/blog/2009/08/27/smart-normal-map-goes-silverlight/ //Generates a normalmap using condensed or sobel-edge. float width : register(C0); float soft_sobel : register(C1); float amount : register(C2); float invert_red : register(C3); float invert_green : register(C4); sampler2D Input : register(S0); float4 main(float2 uv:TEXCOORD) : COLOR { float dx; float dy; float texel = 1.0f / width; if (soft_sobel!=0.0) { //condensed dx = abs(tex2D (Input, uv + texel *float2(1, 0)).x).r - abs(tex2D (Input, uv + texel *float2(-1, 0)).x).r; dy = abs(tex2D (Input, uv + texel *float2(0, -1)).x).r - abs(tex2D (Input, uv + texel *float2( 0, 1)).x).r; } else { //sobel dx = abs(tex2D (Input, uv + texel *float2(-1, -1)).x).r /-1.0f; dx += abs(tex2D (Input, uv + texel *float2(-1, 0)).x).r /-2.0f; dx += abs(tex2D (Input, uv + texel *float2(-1, 1)).x).r /-1.0f; dx += abs(tex2D (Input, uv + texel *float2( 1, -1)).x).r / 1.0f; dx += abs(tex2D (Input, uv + texel *float2( 1, 0)).x).r / 2.0f; dx += abs(tex2D (Input, uv + texel *float2( 1, 1)).x).r / 1.0f; dy = abs(tex2D (Input, uv + texel *float2(-1, 1)).x).r /-1.0f; dy += abs(tex2D (Input, uv + texel *float2( 0, 1)).x).r /-2.0f; dy += abs(tex2D (Input, uv + texel *float2( 1, 1)).x).r /-1.0f; dy += abs(tex2D (Input, uv + texel *float2(-1, -1)).x).r / 1.0f; dy += abs(tex2D (Input, uv + texel *float2( 0, -1)).x).r / 2.0f; dy += abs(tex2D (Input, uv + texel *float2( 1, -1)).x).r / 1.0f; } float3 normal = float3(dx * (invert_red) * (amount / (1.0 + float(soft_sobel))), - (dy*invert_green) * (amount / (1.0 + float(soft_sobel))), 1.0); normal = ((normal+1.0) / 2.0 ); float4 N = float4(normal.r, normal.g, normal.b, 1.0f); return N; }