texugo
1
Hi Buddies
I Try to make a blur shader, but without sucess by now. Someone can tell me what’ s wrong with my shader?
The code:
//Cg
const float4 samples[4]={
float4(-1.0, 0.0, 0.0, 0.25),
float4(1.0, 0.0, 0.0, 0.25),
float4(0.0, 1.0, 0.0, 0.25),
float4(0.0, -1.0, 0.0, 0.25)
};
void vshader(
uniform float4x4 mat_modelproj,
in float4 vtx_position:POSITION,
in float4 vtx_texcoord0:TEXCOORD0,
out float4 l_position:POSITION,
out float4 l_my:TEXCOORD0
)
{
l_position=mul(mat_modelproj, vtx_position);
l_my=vtx_texcoord0;
}
void fshader(
uniform sampler2D tex_0:TEXUNIT0,
in float2 l_my:TEXCOORD0,
out float4 o_color:COLOR
)
{
o_color=float4(0,0,0,0);
for (int i=0;i<4;i++)
o_color+=samples[i].w*tex2D(tex_0, float2(l_my.x+samples[i].x, l_my.y+samples[i].y));
}
Thanx
T.
Are you using FilterManager ? If so, you can follow this one:
[basically a blur filter in demomaster => Compositor demo]
void vshader(float4 vtx_position : POSITION,
float2 vtx_texcoord0 : TEXCOORD0,
out float4 l_position : POSITION,
out float2 l_texcoord0 : TEXCOORD0,
uniform float4 texpad_src,
uniform float4x4 mat_modelproj)
{
l_position=mul(mat_modelproj, vtx_position);
l_texcoord0 = vtx_position.xz * texpad_src.xy + texpad_src.xy;
}
float2 samples[12] = {
-0.326212, -0.405805,
-0.840144, -0.073580,
-0.695914, 0.457137,
-0.203345, 0.620716,
0.962340, -0.194983,
0.473434, -0.480026,
0.519456, 0.767022,
0.185461, -0.893124,
0.507431, 0.064425,
0.896420, 0.412458,
-0.321940, -0.932615,
-0.791559, -0.597705,
};
void fshader(float2 l_texcoord0 : TEXCOORD0,
out float4 o_color : COLOR,
uniform float4 k_param1,
uniform sampler2D k_src : TEXUNIT0)
{
float4 c = tex2D(k_src, l_texcoord0);
// Sample the neighbor pixels
for (int i = 0; i < 12; i++){
c += tex2D(k_src, l_texcoord0 + k_param1.x * samples[i]);
}
o_color = c/13;
}