Gaussian Blur Shader strange results

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
The_Glitch
Competition winner
Posts: 523
Joined: Tue Jan 15, 2013 6:36 pm

Gaussian Blur Shader strange results

Post by The_Glitch »

I'm using a 2 pass Gaussian blur shader on a render target texture and I have these strange pixelated issue. I tried yesterday to figure out the problem but I wasn't able to figure out anything it only happens when I use the shader in Irrlicht but not else where which throws me of a bit.

Code: Select all

 
 
#define RADIUS  7
#define KERNEL_SIZE (RADIUS * 2 + 1)
 
float weightX[KERNEL_SIZE];
float weightY[KERNEL_SIZE];
float2 offsetH[KERNEL_SIZE];
float2 offsetV[KERNEL_SIZE];
 
texture colorMapTexture;
 
sampler TextureSampler : register(s0);
 
void BlurH(inout float4 color : COLOR0, float2 texCoord : TEXCOORD0)
{
    float4 c = float4(0.0f, 0.0f, 0.0f, 0.0f);
 
    for (int i = 0; i < KERNEL_SIZE; ++i)
        c += tex2D(TextureSampler, texCoord + offsetH[i]) * weightX[i];
 
        color = c;
}
 
void BlurV(inout float4 color : COLOR0, float2 texCoord : TEXCOORD0)
{
    float4 c = float4(0.0f, 0.0f, 0.0f, 0.0f);
 
    for (int i = 0; i < KERNEL_SIZE; ++i)
        c += tex2D(TextureSampler, texCoord + offsetV[i]) * weightY[i];
 
        color = c;
}
 
technique GaussianBlur
{
    pass
    {
        PixelShader = compile ps_2_0 BlurH();
    }
    pass
    {
        PixelShader = compile ps_2_0 BlurV();
    }
}
 
 

Image
Image
Foaly
Posts: 142
Joined: Tue Apr 15, 2014 8:45 am
Location: Germany

Re: Gaussian Blur Shader strange results

Post by Foaly »

You should post the code, how you use the shader in Irrlicht, as that's probably the problem.
Maybe you didn't set values to the arrays weightX, weightY, offsetH and offsetV?
The_Glitch
Competition winner
Posts: 523
Joined: Tue Jan 15, 2013 6:36 pm

Re: Gaussian Blur Shader strange results

Post by The_Glitch »

Okay I will when I get a chance post the shader callback.
The_Glitch
Competition winner
Posts: 523
Joined: Tue Jan 15, 2013 6:36 pm

Re: Gaussian Blur Shader strange results

Post by The_Glitch »

Here's a different shader I tried everything is provided in the shader compiles fine in Irrlicht but doesn't have any effect. I've been able to get blur shaders to work fine in the past, only ones that don't work for me are Gaussian Blurs.

Code: Select all

 
sampler2D input : register(s0); 
 
 
 
 
#define WEIGHT_COUNT 6
 
 
 
 
float weight[WEIGHT_COUNT] = {
 
 0.9,
 
    0.85,
 
    0.70,
 
    0.50,
 
    0.25,
 
 0.10
 
 };
 
 
 
 
float colorIntensity = 1.0f;
 
float intensity = 1.0f;
 
float2 pixelAspect = {1.0/1280, 1.0/768};
 
 
 
 
float4 PS_BlurHorizontal(in float2 uv : TEXCOORD) : COLOR 
 
{ 
 
    float4 Color = tex2D(input, uv);
 
 float mult = 1;
 
 for(int i=0; i<WEIGHT_COUNT; i++)
 
 {
 
 Color += tex2D(input, float2(uv.x-(intensity*pixelAspect.x*mult), uv.y)) * weight[i];
 
 Color += tex2D(input, float2(uv.x+(intensity*pixelAspect.x*mult), uv.y)) * weight[i];
 
 mult = mult + 4;
 
 }
 
 Color /= WEIGHT_COUNT;
 
 return Color * colorIntensity; 
 
}
 
 
 
 
float4 PS_BlurVertical(in float2 uv : TEXCOORD) : COLOR
 
{ 
 
 float4 Color = tex2D(input, uv);
 
  float mult = 1;
 
 for(int i=0; i<WEIGHT_COUNT; i++)
 
 {
 
 Color += tex2D(input, float2(uv.x, uv.y-(intensity*pixelAspect.y*mult))) * weight[i];
 
 Color += tex2D(input, float2(uv.x, uv.y+(intensity*pixelAspect.y*mult))) * weight[i];
 
 mult = mult + 4;
 
 }
 
 Color /= WEIGHT_COUNT;
 
 return Color * colorIntensity;
 
}
 
 
 
 
technique FunkyBlur
 
{
 
 pass Pass1
 
 {
 
 // A post process shader only needs a pixel shader.
 
 PixelShader = compile ps_2_0 PS_BlurHorizontal();
 
 }
 
 pass Pass2
 
 {
 
 // A post process shader only needs a pixel shader.
 
 PixelShader = compile ps_2_0 PS_BlurVertical();
 
 }
 
}
 
thanhle
Posts: 325
Joined: Wed Jun 12, 2013 8:09 am

Re: Gaussian Blur Shader strange results

Post by thanhle »

Hi
I think Foaly asking how you pass the information to the shader from Irrlicht, not the shader code.

Regards
thanh
The_Glitch
Competition winner
Posts: 523
Joined: Tue Jan 15, 2013 6:36 pm

Re: Gaussian Blur Shader strange results

Post by The_Glitch »

I know what he means I'm no longer using the first shader I'm attempting to use the second shader I posted as the Information is provided in the shader.
Post Reply