Hi there,
I am trying to write my first blur shader and at the moment I am not having much luck. I can get the shader to display the texture, however for some unknown reason the blur code that I have implemented is ineffective.
My code is as follows…
Shader "Basic" {
Properties {
_MyTexture ("Texture", 2D) = "white" {}
}
SubShader {
Pass {
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma fragmentoption ARB_fog_exp2
#include "UnityCG.cginc"
sampler2D _MyTexture;
static const int cKernelSize = 13;
//static const half4 samples[9] = {
// -1.0, -1.0, 0, 1.0/16.0,
// -1.0, 1.0, 0, 1.0/16.0,
// 1.0, -1.0, 0, 1.0/16.0,
// 1.0, 1.0, 0, 1.0/16.0,
// -1.0, 0.0, 0, 2.0/16.0,
// 1.0, 0.0, 0, 2.0/16.0,
// 0.0, -1.0, 0, 2.0/16.0,
// 0.0, 1.0, 0, 2.0/16.0,
// 0.0, 0.0, 0, 4.0/16.0
//};
static const 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
};
struct v2f {
float4 vertex : POSITION;
float2 textCoord : TEXCOORD0;
};
v2f vert (appdata_base v) {
v2f o;
o.textCoord = TRANSFORM_UV(0);
o.vertex = mul(glstate.matrix.mvp, v.vertex);
return o;
}
float4 frag (v2f vert) : COLOR {
float4 col = float4(0,0,0,0);
for(int i=0;i<4;i++){
col += samples[i].w*tex2D(_MyTexture, vert.textCoord+ float2(samples[i].x*(1/512),samples[i].x*(1/512)));
}
return col;
// for(int i=0; i<4; i++){
// float2 sampleTexCoords=float2(samples[i].x*(1/512),samples[i].y*(1/512));
// col += samples[i].w*tex2D(_MyTexture,vert.textCoord+sampleTexCoords);
// }
// return col;
}
ENDCG
}
}
}
Any help with my code would be greatly appreciated!
Cheers,
Craig