Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between a sample, a pixel and a fragment?

Tags:

opengl

shader

I still can't wrap my head around what differences are there between a sample/pixel/fragment.

Since the fragment shader executes per pixel, I think a fragment just refers to a pixel, is this correct? Can anybody give me an example and definition of each one?

like image 659
Jeff Avatar asked Jul 01 '15 22:07

Jeff


1 Answers

A fragment shader executes per fragment and emits pixels. They are very similar, but not the same.

A Fragment is a collection of values produced by the Rasterizer. Each fragment represents a sample-sized segment of a rasterized Primitive. The size covered by a fragment is related to the pixel area, but rasterization can produce multiple fragments from the same triangle per-pixel, depending on various multisampling parameters and OpenGL state. There will be at least one fragment produced for every pixel area covered by the primitive being rasterized. Source

So, if you disable multisampling / antialiasing completely, each fragment should map to one pixel. But if you enable it, multiple fragments will be interpolated to form a single pixel.

The differentiation can also be seen in the Rendering Pipelines of OpenGL here: https://openglinsights.com/pipeline.html

like image 110
maja Avatar answered Oct 10 '22 03:10

maja