I am trying to do a convolution shader but I cannot find the way on how to find the neighbours pixels value. the code is:
sampler2D _MainTex;
float filter[25] = {
-4.0, -1.0, 0.0, -1.0, -4.0,
-1.0, 2.0, 3.0, 2.0, -1.0,
0.0, 3.0, 4.0, 3.0, 0.0,
-1.0, 2.0, 3.0, 2.0, -1.0,
-4.0, -1.0, 0.0, -1.0, -4.0
};
struct Input {
float2 uv_MainTex;
};
void surf (Input IN, inout SurfaceOutput o)
{
half4 c = half4( 1, 0, 0, 1);
int x,y,i=0;
int xx = 0, yy = 0;
for (x=0;x<5;x++)
{
xx = x - 2;
for (y=0;y<5;y++)
{
yy = y - 2;
c.rgb += filter[i++] * tex2D (_MainTex, IN.uv_MainTex + float2(xx, yy)).rgb;
}
}
o.Albedo = c.rgb;
o.Alpha = c.a;
}
This throws an error:
Program 'frag_surf', Temporary register limit of 12 exceeded; 26 registers needed to compile program at line 8
Any ideas on how to solve the error and how to access neighbours values?