Advertisement

MSAA in Deferred shading

Started by July 25, 2014 08:37 PM
6 comments, last by MJP 10 years, 4 months ago

Hello .

What is special about DX 10.1 and further that enable us to have MSAA in a deferred shading pipeline ?

Does it enable us to have hardware MSAA ?

How should this be done ?

Thanks in advance

You piqued my interest and I found this article.

It sounds like 10.1 you have the ability to access the AA'ed samples, so you can reconstruct your values based on the knowledge of whether you're on an edge or not within your geometry. From a cursory look it seems to work when constructing depth samples, but I don't know how well it would work with the other parameters of a deferred shading pipeline like normals, since you would have an averaged sample, but they seemed to have gotten it to work. I'd love to know how that works if someone smarter than me understands it.

Perception is when one imagination clashes with another
Advertisement
Yeah with deferred and MSAA, traditionally you'd either end up using the average value of the samples, or just picking the first sample and ignoring the rest.
The first results in horrible arts facts instead of AA, and the second does nothing!

Once you can selectively read each and every sample, you can compute lghting per-sample instead of per-pixel.

The downside is that, e.g. With MSAA-4x, per sample lighting will be 4x more expensive than per pixel lighting... So it's also important to use a technique that lets you selectively switch between the two techniques per pixel -- only doing per sample lighting in areas where it's required.

Thanks . How can I acsess to samples and not pixels ? I mean what is the syntax for doing this ?

When you create your render target and depth stencil view - you must make sure the samples are the same and can be made for that format. In my deferred shading I use 8x MSAA. In your question how do you access the samples? I got the deferred shading from Rastertek and sadly it's down for now :(

Maybe a sniplette will help or an basic idea:


ID3D11_Texture2D_Desc texDesc;

//... fill in the required texture2D for the render target you're creating. 
texDesc.format = DXGI_FORMAT_R32G32B32A32_FLOAT;
texDesc.Samples.Count = 8;
texDesc.Samples.Quality = 32;
... - Normally how you'll create the texture2D. 

... create new Texture2D Description for depth Stencil View - just same as above BUT. 

depthTexDesc.format = DXGI_FORMAT_D24_UNORM_S8_UINT;
depthTexDesc.Bindflags = D3D11_BIND_DEPTH_STENCIL;

-- Create the depth stencil  view with the newly created depth stencil 2D Texture.

If you want to test to see if that format supports or what quality that format supports you can use ID3D11Device::CheckMultiSampleQualityLevels upon directx device creation

Game Engine's WIP Videos - http://www.youtube.com/sicgames88
SIC Games @ GitHub - https://github.com/SICGames?tab=repositories
Simple D2D1 Font Wrapper for D3D11 - https://github.com/SICGames/D2DFontX

Thanks but I meant in shader , Look at this please :



cbuffer Constants
{
     float2 PixelSize;
}

// For MSAA-4x

float4 PixelShader(float2 uv):SV_TARGET0
{
	if(edge)
	{
		float2 SampleSize = PixelSize*0.5f;
		float3 col1 = DoShading(uv+float2(SampleSize .x,0));
		float3 col2 = DoShading(uv+float2(-SampleSize .x,0));
		float3 col3 = DoShading(uv+float2(0,SampleSize .y));
		float3 col4 = DoShading(uv+float2(0,-SampleSize .y));
		return float4(  (col1+col2+col3+col4)/4 ,1);
	}
	else
	{
		return float4( DoShading(uv),1 );
	}
}

Is this how should I do the job ?

What if it was MSAA-8x ? How should I take the samples?

Advertisement
Instead of using a Texture2d, declare yor input textures as Texture2dMS. The Load function then lets you specify which sample number you want (0,1,2,3...) along with the texel u,v coordinate.

You may want to take a look at this presentation, although it's a little older and some of the advice is out-of-date for the most recent GPU's. This one also talks about MSAA + deferred rendering. This presentation and sample code demonstrates a more "modern" way of handing deferred rendering and MSAA using a compute shader, so you should definitely have a look at that as well.

This topic is closed to new replies.

Advertisement