一副数字图像可以看作一个二维空间的离散函数可以表示为f(x, y), 假设有对于二维卷积操
作函数C(u, v) ,则会产生输出图像g(x, y) = f(x, y) *C(u,v), 利用卷积可以实现对图像模糊处理,边缘检测,产生轧花效果的图像。(引自lanbing510)
float4 MainPS_Screen( VS_OUTPUT In ):COLOR { // 临近像素点的颜色 float s00 = tex2D( ColorMapSamplerIn , In.tex + float2( -off, -off)).r; float s01 = tex2D( ColorMapSamplerIn , In.tex + float2( 0, -off)).r; float s02 = tex2D( ColorMapSamplerIn , In.tex + float2( off, -off)).r; float s10 = tex2D( ColorMapSamplerIn , In.tex + float2( -off, 0)).r; float s12 = tex2D( ColorMapSamplerIn , In.tex + float2( off, 0)).r; float s20 = tex2D( ColorMapSamplerIn , In.tex + float2( -off, off)).r; float s21 = tex2D( ColorMapSamplerIn , In.tex + float2( 0, off)).r; float s22 = tex2D( ColorMapSamplerIn , In.tex + float2( off, off)).r; // Sobel filter计算在X轴的方向 float sobelX = s00 + 2 * s10 + s20 - s02 - 2 * s12 - s22; // Sobel filter 计算在Y轴的方向 float sobelY = s00 + 2 * s01 + s02 - s20 - 2 * s21 - s22; // 计算边缘 float edgeSqr = ( sobelX * sobelX + sobelY * sobelY ); // ... and threshold against a squared value instead. float4 Color = float4( 0.0 , 0.0 , 0.0 , 0.0 ); if( edgeSqr > 0.00999 ) { Color = float4( 1.0 , 1.0 , 1.0 , 1.0 ); } else { Color = Color; } return Color ; }