Why don't slices necessarily match pixels one-to-one?

Here's a good explanation of what a snippet is:

https://gamedev.stackexchange.com/questions/8977/what-is-a-fragment/8981#8981

But here (and not only here) I read that "I want to emphasize the fact that one pixel is not necessarily one fragment, you can combine several fragments to make one pixel ...". But I don't understand what slices are and why do they not necessarily match pixels one to one?

EDIT: When multiple fragments form one pixel, does this only happen if they overlap after projection, or because the pixel is larger than the fragment, so you need to collect multiple fragments next to each other with the same color to form the pixel?

+3


source to share


2 answers


A snippet has a location that can be requested via an inline variable gl_FragCoord

where the components x

and y

directly correspond to the pixels on your screen. This way you can tell that the fragment is actually pixel-perfect.

However, the fragment outputs the color and stores that color in the color buffer at its coordinates. This does not mean that this color is the actual color of the pixel that is displayed to the viewer.

Since a fragment shader is run for each object, it may happen that other objects are drawn after the first object, which also display a fragment with the same screen coordinate. When depth testing, pattern testing and blending are performed, the resulting color value in the color buffer can be overwritten and / or combined with new colors.



Think of it this way:

Object 1 gets drawn and draws the color purple at screen coordinate (200, 300);
Object 2 gets drawn and draws the color red at same coordinate, overwriting it.
Object 3 (is blue) has transparency of 50% at same coordinate, and merges colors.
Final fragment color output is then combination of red and blue (50%).

      

The final resulting pixel can then be a color from a single striping run, a color that is overwritten by many other fragment shader entries, or a combination of colors through blending.

+5


source


Fragment is not equal to a pixel when multisamping with multiple examples (MSAA) or any other mode that changes the ratio of displayed pixels to screen pixels is activated.



In the case of 4x MSAA, each screen pixel will be represented by 4 (2x2) tiles in the display buffer. The fragment shader for a specific polygon will only run once for a screen pixel, regardless of how many fragments the polygon covers. Since the polygon may not cover all the tiles within a pixel, it will only store color in the tiles it covers. This is repeated for each polygon that can cover one or more tiles. Then, in the final display, all 4 fragments are blended to produce the final screen pixel.

0


source







All Articles