3乘3卷积着色器的UE4版本
int Kernel[9]= {
0,-1,0,
-1,5,-1,
0,-1,0
};
//UVOffset由参数提供
float2 Offset[9];
Offset[0] = float2(-UVOffset,-UVOffset);
Offset[1] = float2(0,-UVOffset);
Offset[2] = float2(UVOffset,-UVOffset);
Offset[3] = float2(-UVOffset,0);
Offset[4] = float2(0,0);
Offset[5] = float2(UVOffset,0);
Offset[6] = float2(-UVOffset,UVOffset);
Offset[7] = float2(0,UVOffset);
Offset[8] = float2(UVOffset,UVOffset);
float3 sum = 0;
float scale = -1-1+5-1-1;
for(int i = 0; i < 9; ++i){
sum += Kernel[i] * scale * Texture2DSample(Tex, TexSampler, UV + Offset[i]);
}
return sum;