Can I use an OpenGL shader to solve a layered texture?

My application maps the first scene to a texture bound to the FBO, then the compute shader does some processing on the texture image and writes it to another texture, which I then use to render the second scene. All perfectly.

Now I would like the first scene to be anti-aliased, so I create a multisampled texture and bind it to the FBO before rendering. In the compute shader, I use imageLoad(buf, pos, sample)

read from image2DMS

(not imageLoad(buf, pos)

from image2D

) to read all samples and calculate the average for the chunk, but it looks like all samples have the same value.

Before pulling out the relevant bits of code and concatenating them into a simple test program, I would like to know if I understand the multi-sample model, and if what I'm trying to do is even possible. I was running nVidia GTX 660 with OpenGL 4.3 on Windows 7, driver 9.18.13.4052, July 2014.

+3


source to share


1 answer


I think you should look at the difference between multisampling (MSAA) and supersampling (SSAA).

Multisampling uses mutlisampled depth and color target. When your geometry primitive is rasterized, it is checked against all of your selections that define its coverage. Subsequently, the fragment shader is called only once per pixel, and the result is copied to each covered sample. This way you only have one instance of the fragment shader, where your primitive spans all the samples inside the pixel. On the other hand, when the primitive spans only part of a pixel, the fragment shader color is copied only for that sample. Thus, you can only collect n-shaped different colors in one pixel when the primitives cover their specific pattern in that pixel.

Supersampling is much easier to understand and requires much more processing power. Superfetch calls one instance of the fragment shader for each example. This way you end up with different colors, even if the same primitive covers all samples in one pixel.



In OpenGL, you can easily switch from MSAA to SSAA with the glMinSampleShading option. This parameter describes how many instances of the fragment shader should execute at least per pixel. The value is a factor (0.0-1.0) for your number of samples. So if you choose a factor of 1.0, you get a super sample.

Due to the fact that MSAA only includes additional fragment shading pieces based on different primitives, it can be considered AA with pure geometry. So, for example, aliasing based on alpha textures is not allowed. This is why some sites also refer to the glMinSampleShading parameter as transparency patterns for MSAA.

I recommend this well-described and illustrated AA review for further reading: https://mynameismjp.wordpress.com/2012/10/24/msaa-overview/

+1


source







All Articles