I know many render target is not compatible with MSAA currently, for example, MRT, FP16 or even FP32 is not possible to use MSAA on some hardware, if not all. Some papers discussing deferred shading is not given good advice either.
I'm thinking about this problem for a morning and get an answer, I don't know if this has been used before or there has been some better way, so I decide to share it here
the procedure is described below:
1: render the scene with MSAA off, and store the color/Z as two textures.
2: turn on FSAA, use the right backbuffer and z/stencil.
3: render all the visible geometry again, with the same shader(described below), texture and state. great batch, doesn't it ?
(in DX10, it's even better with streaming out), you can even use occlusion query, whatever.
4: in the shader:
1) : generate all the texcoord matching the screen space.
2) : simply find the nearest-Z in the Z-texture, for all neighbor 4 texels, compared with the interpolated-Z of the primitive
3) : use the nearest-Z's corresponding color as output.
Now, you get CORRECT MSAA.
The main idea is that(inspired by Alpha-to-Coverage):
1: All the survived AA-Sample will execute the same shader in the pixel, even if there is only one.
2: so the "half covered pixel" will get some AA-Samples to fetch it's "right" color, which are all the same in that pixel.
3: and finally, the HW will solve it ...
I saught there has been some "Smart Shader AA" on the net, but may not get the correct sub-pixel coverage infomation, because it's just post-process the image on texture space and blurring the edge.
PS: i'm from Beijing so excuse for my poor English:smile:
I'm thinking about this problem for a morning and get an answer, I don't know if this has been used before or there has been some better way, so I decide to share it here
the procedure is described below:
1: render the scene with MSAA off, and store the color/Z as two textures.
2: turn on FSAA, use the right backbuffer and z/stencil.
3: render all the visible geometry again, with the same shader(described below), texture and state. great batch, doesn't it ?
(in DX10, it's even better with streaming out), you can even use occlusion query, whatever.
4: in the shader:
1) : generate all the texcoord matching the screen space.
2) : simply find the nearest-Z in the Z-texture, for all neighbor 4 texels, compared with the interpolated-Z of the primitive
3) : use the nearest-Z's corresponding color as output.
Now, you get CORRECT MSAA.
The main idea is that(inspired by Alpha-to-Coverage):
1: All the survived AA-Sample will execute the same shader in the pixel, even if there is only one.
2: so the "half covered pixel" will get some AA-Samples to fetch it's "right" color, which are all the same in that pixel.
3: and finally, the HW will solve it ...
I saught there has been some "Smart Shader AA" on the net, but may not get the correct sub-pixel coverage infomation, because it's just post-process the image on texture space and blurring the edge.
PS: i'm from Beijing so excuse for my poor English:smile: