I need help understanding a fundamental concept in Apple’s Metal pipeline.
Let’s assume I have a single triangle I am going to render, made of three points R, G and B. Let’s also assume that each point has a colour associated with it – corresponding to its name. We set up the vertex shader to simply pass the vertex position and colour without modification.
The pipeline now rasterises the triangle – let say that it covers 10 pixels on screen. Now here’s where my confusion lies – the fragment shader…
If my fragment shader just returns the vertex’s colour then Metal will interpolate between the colours of each corner. My naive assumption was that Metal would call the fragment shader once for each vertex, and then use the resulting colours to interpolate the values for each pixel.
However, if I sample a texture in my fragment shader then it would need to be passed the position of each pixel, not the original vertices, so I can look up / sample the correct colour from in the texture in the shader.
I suppose a daft way to ask the same question is: How often is the fragment shader called 3, 10, 30 or some other number of times? Or even more daft – what is a fragment: an individual pixel, or a structure that comprises the 3 vertices and pixels that need to be coloured?