hi guys, i've implemented a blur effect which works fine :
[SPOILER]
[/SPOILER]
now i want to implement depth-aware blur which means if the depth of neighbor points were in the threshold of the center depth point, then add that color of point, but if not, just skip that point.
for example, this is what we have done for normal blur in pixel shader :
[SPOILER]
float4 HorizontalBlurPixelShader(VS_OUTPUT input) : SV_TARGET
{
float weight0, weight1, weight2, weight3, weight4;
float normalization;
float4 color;
// Create the weights that each neighbor pixel will contribute to the blur.
weight0 = 1.0f;
weight1 = 0.9f;
weight2 = 0.55f;
weight3 = 0.18f;
weight4 = 0.1f;
// Create a normalized value to average the weights out a bit.
normalization = (weight0 + 2.0f * (weight1 + weight2));
// Normalize the weights.
weight0 = weight0 / normalization;
weight1 = weight1 / normalization;
weight2 = weight2 / normalization;
// Initialize the color to black.
color = float4(0.0f, 0.0f, 0.0f, 0.0f);
color += IIM.Sample(ObjSamplerStateClamp, input.texCoord1) * weight2;
color += IIM.Sample(ObjSamplerStateClamp, input.texCoord2) * weight1;
color += IIM.Sample(ObjSamplerStateClamp, input.texCoord3) * weight0;
color += IIM.Sample(ObjSamplerStateClamp, input.texCoord4) * weight1;
color += IIM.Sample(ObjSamplerStateClamp, input.texCoord5) * weight2;
// Set the alpha channel to one.
color.a = 1.0f;
return color;
}
[/SPOILER]
what i want to do is to check if (abs(depthNeighbor - depthCenter) < threshold) then add that color to the colorValue. so for each of those samples that i had, i'll add one if statement to check whether that abs(depthNeighbor - depthCenter) is less than a threshold or not.
[SPOILER]
if (abs(depthMapTexture.Sample(ObjSamplerStateClamp, input.texCoord1).r - depthMapTexture.Sample(ObjSamplerStateClamp, input.texCoord3).r) < 0.5 / 1000)
color += IIM.Sample(ObjSamplerStateClamp, input.texCoord1) * weight2;
if (abs(depthMapTexture.Sample(ObjSamplerStateClamp, input.texCoord2).r - depthMapTexture.Sample(ObjSamplerStateClamp, input.texCoord3).r) < 0.5 / 1000)
color += IIM.Sample(ObjSamplerStateClamp, input.texCoord2) * weight1;
if (abs(depthMapTexture.Sample(ObjSamplerStateClamp, input.texCoord3).r - depthMapTexture.Sample(ObjSamplerStateClamp, input.texCoord3).r) < 0.5 / 1000)
color += IIM.Sample(ObjSamplerStateClamp, input.texCoord3) * weight0;
if (abs(depthMapTexture.Sample(ObjSamplerStateClamp, input.texCoord4).r - depthMapTexture.Sample(ObjSamplerStateClamp, input.texCoord3).r) < 0.5 / 1000)
color += IIM.Sample(ObjSamplerStateClamp, input.texCoord4) * weight1;
if (abs(depthMapTexture.Sample(ObjSamplerStateClamp, input.texCoord5).r - depthMapTexture.Sample(ObjSamplerStateClamp, input.texCoord3).r) < 0.5 / 1000)
color += IIM.Sample(ObjSamplerStateClamp, input.texCoord5) * weight2;
[/SPOILER]
and unfortunately, instead of having depth-aware blur, it will draw the depthMapTexture (from view of light) on the screen :
[SPOILER]
[/SPOILER]
i don't know why it happens, and why it is only because of those if statements.
i also wrote those if statements like :
float threshold = 0.5 / 1000;
d1 = depthMapTexture.Sample(ObjSamplerStateClamp, input.texCoord1).r;
d2 = depthMapTexture.Sample(ObjSamplerStateClamp, input.texCoord3).r;
if (abs(d1 - d2) < threshold)
color += IIM.Sample(ObjSamplerStateClamp, input.texCoord1) * weight2;
but nothing changed.
do you have any idea about what is the reason of drawing light view on the screen and how can i solve this problem?