Размер текстуры (1024х1024) захардкодил в коде шейдера, и надеюсь нигде не накосячил .
Синтаксис:
Используется glsl
Shader "ImageProc BoxFilter" {
Properties {
_MainTex ("Texture", 2D) = "white" {}
}
SubShader {
Tags { "RenderType" = "Opaque" }
CGPROGRAM
#pragma surface surf Lambert
struct Input {
float2 uv_MainTex;
};
sampler2D _MainTex;
void surf (Input IN, inout SurfaceOutput o) {
float4 col = float4(0,0,0,0);
//сам фильтр
float4 samples[4] = {
-1.0, 0.0, 0, 0.25,
1.0, 0.0, 0, 0.25,
0.0, 1.0, 0, 0.25,
0.0, -1.0, 0, 0.25
};
// Sample and output the box averaged colors
for(int i=0;i<4;i++)
{
col += samples[i].w*tex2D(_MainTex, IN.uv_MainTex + float2(samples[i].x/1024, samples[i].y/1024));
}
o.Albedo = col;
}
ENDCG
}
Fallback "Diffuse"
}
Properties {
_MainTex ("Texture", 2D) = "white" {}
}
SubShader {
Tags { "RenderType" = "Opaque" }
CGPROGRAM
#pragma surface surf Lambert
struct Input {
float2 uv_MainTex;
};
sampler2D _MainTex;
void surf (Input IN, inout SurfaceOutput o) {
float4 col = float4(0,0,0,0);
//сам фильтр
float4 samples[4] = {
-1.0, 0.0, 0, 0.25,
1.0, 0.0, 0, 0.25,
0.0, 1.0, 0, 0.25,
0.0, -1.0, 0, 0.25
};
// Sample and output the box averaged colors
for(int i=0;i<4;i++)
{
col += samples[i].w*tex2D(_MainTex, IN.uv_MainTex + float2(samples[i].x/1024, samples[i].y/1024));
}
o.Albedo = col;
}
ENDCG
}
Fallback "Diffuse"
}