Force PixelShader to write into given SubSamples of MSAA RT

Started by
3 comments, last by MJP 5 years, 2 months ago

Hi,

is there any way to force a pixelshader (while rendering a FullScreenQuad) to write into a given SubSample of a MSAA rendertarget? By my understanding this actually depends on the coverage of the current primitive, which are in case of a FS Quad just two triangles.. So is there any way to tell the pipeline todo multisampling for all fragments?

 

Advertisement
32 minutes ago, thmfrnk said:

So is there any way to tell the pipeline todo multisampling for all fragments?

If you just want to run your pixel shader for every sample of the RT, then adding an input with SV_SampleIndex should do the trick. It forces the evaluation of the shader for every sample, instead of every pixel.

You are sure, that he will do this for every fragment of a Fullscreen Quad?

Using SV_SampleIndex in your pixel shader (or alternatively using the "sample" modifer on a pixel shader input attribute) will cause the PS stage to run at "sample rate" instead of "pixel rate" (note that it actually has to be used by the shader, and not optimized away).  When running at sample rate, the pixel shader will be run for every sub-sample in the pixel. So if you have 4xMSAA enabled, you will end up with at least VPWidth * VPHeight * 4 pixel shader invocations. This allows you to output a unique value to every sub-sample, suitable for things like 4x super-sampling. Otherwise the pixel shader will be run once for every pixel regardless of the MSAA mode, and will output the same value to all sub-samples covered by the coverage mask (which is determined by testing if the triangle covers the sub-sample position).

Another related feature is SV_Coverage, which lets you specify the bitwise coverage mask that should be used when outputting the pixel shader value to MSAA sub-samples. The value of SV_Coverage is AND'd with the coverage mask produced by the rasterizer before writing the PS output to the render target, which as an example can be used to only write a value to the first sub-sample of each pixel.

This topic is closed to new replies.

Advertisement