1
votes

The vertex shader is executed once for each vertex of the polygons of the object, returning its corresponding v2f. Therefore, it means that the vertex shader won’t run for every pixel.

As the fragment shader takes as input a v2f object, how is it supposed to run for every pixel, if the v2fs are only generated for a few pixels that correspond to screen positions of vertices of the model?

1

1 Answers

2
votes

The fragment shader does not "receives only vertex input"

The vertex shader is executed for each vertex coordinate and it's input are the vertices and its attributes.
Some vertices form a Primitive (e.g 3 for a triangle). The outputs of the vertex shader are interpolated for each fragment which is covered by the primitive by the Rasterization process.
If the fragment shader stage follows the vertex shader stage, then the interpolated outputs of the vertex sahder are the inputs to the fragment shader. So the fragment shader is executed for each fragment.