Blur

Started by
4 comments, last by Nathan Drake 8 years, 2 months ago

hi guys, i've implemented a blur effect which works fine :

[SPOILER]

d730c81d42.jpg

[/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]

26f21da900.jpg

[/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?

Advertisement
In general you should check out gaussian-bilateral filters: https://en.wikipedia.org/wiki/Bilateral_filter ... but in your case it seems, that you have bound the shadowmap (=depth map of light source) instead of the depthmap of your camera to the sampler.

In general you should check out gaussian-bilateral filters: https://en.wikipedia.org/wiki/Bilateral_filter ... but in your case it seems, that you have bound the shadowmap (=depth map of light source) instead of the depthmap of your camera to the sampler.

thanks for your comment,

but this is actually what i want. i want to know the depth of points from light source.

what i have made in this scene is Indirect illumination with shadow maps that has been rendered.

[SPOILER]

927827d60c.jpg

[/SPOILER]

the reason of applying depth-aware blur is to smooth my indirect illumination effect more than what it has.

You seem to sample the light depth map with the same texture coords with which you sample the screen depth map. You need to transform these coords into light space first, much like sampling the depth map for the shadows.

You seem to sample the light depth map with the same texture coords with which you sample the screen depth map. You need to transform these coords into light space first, much like sampling the depth map for the shadows.

actually your first post was correct, he needs to sample the depth from the camera view, not the shadow map

thanks guys, problem solved

This topic is closed to new replies.

Advertisement