Can you please explain this? (Multi-Sampling artifacts)

pinkfish

Newcomer
I need your help to explain something to me:

I am using XNA studio and C#.
I have a very simple shader that does very simple diffuse lighting (per pixel).
It works perfectly when I have multi-sampling disabled.

Code:
graphics = new GraphicsDeviceManager(this);
 graphics.PreferMultiSampling = false;

The problem is that if enable multi-sampling I get sparkling atrifacts (at Polygon edges I suspect).

Here is a screenshot of the problem with a zoomed in view using Pix.



If in Pix I accept to disable multi sampling to debug the pixels, the artifacts disappear as well.

And even if I tell Pix to keep multi-sampling and click on a white sparkle pixel to debug it, it shows as black and value of it's color in pixel shader is 0.

The Shader source is extremely simple:
Code:
VSO_Diffuse VS_Diffuse(VSI_Diffuse input)
{
	VSO_Diffuse output;
	
	output.position = mul(input.position, WvpXf);
	float4 worldPos = mul(input.position, WXf);
	output.N = mul(input.normal, WXf);
	output.L = normalize(LightPos.xyz - worldPos.xyz);

    return output;
}	

PSO_Diffuse PS_Diffuse(VSO_Diffuse input)
{
	PSO_Diffuse output;
	
	float kd = saturate(dot(input.N, input.L));
	output.color = /*Ambient +*/ float4(kd * Diffuse.xyz, 1);

    return output;
}

I have a cube and a sphere as well, they exhibit no sparkling at all ...
The models come from Blender.

I can't really understand how this has to do with enabling/disabling multi-sampling...
Can you help explain it?

Thank you...
 
Your shader doesn't look like it would have problems with sampling outside the primitive, but you may want to try using centroid sampling. In DX9 you simply declare your texture coordinates as TEXCOORD0_centroid for this. In DX10 you add the centroid keyword to the interpolator.

Another thing you may want to verify is that the model doesn't contain any T-junctions.
 
Hi guru!

thx a lot for the reply!

No the shader does not really sample anything ..
I was going to try the centroid to see if it makes any difference I will try it ASAP.

As I mentioned, the model comes directly from Blender ... I will have to look for this T-junctions, but why would they cause such a problem?

And is there a way to debug such situations ? It is impossible in Pix ...
 
About the T-junction ... you probably mean that the white pixels come from the edge of some 'hidden' triangle with its normal pointing in such a way as to receive maximum light?
 
T-junction is when you have for example a line from (-1,0) to (1,0) and another line from (0,1) to (0,0). To make stuff "the way it should be done" you should make 3 lines one from (-1,0) to (0,0) another from (1,0) to (0,0) and a third from (0,1) to (0,0).
It's a 2D description but it should translate to 3D easily.

The fact that the shader doesn't actually sample anything doesn't mean you're immune from such problems... If triangles on the border are thin enough and your input.L changes fast enough then input.L could change significantly from sample position to pixel center. Or if you get close to division by 0 in that normalize...
 
I understand thank you! but then, what is the standard way to deal with such problems?

And also, is there any way to debug them ? (e.g: Pix debug pixel + anti aliasing on? (which is not allowed) )
 
For centroid sampling problems the standard approach is to simply try and see if the problem goes away.
For T-junctions you can simply enable wireframe mode and see if you have any T-junctions there.

I suppose you could also use the isfinite() function in HLSL to test your values and output some debug color in case any of the values are broken.
 
Back
Top