How does a fragment shader determine the number of fragments from the vertex shader output?

I'm familiar with vertex and fragment shaders but am still confused about how the fragment shader determines the number of fragments from the vertex shader output.

If I have 3 vertices and I draw a triangle primitive in GLSL, then the vertex shader will run three times for each vertex, and then the fragment shader will execute many times (depending on the number of fragments, once for each fragment).

I want to know how fragment shader defines fragments? Does this use gl_Position? If I don't set gl_Position in my vertex shader, will the fragment shader still be able to generate fragments or not?

Do I have to set gl_Position every time in the vertex shader?

+3


source to share


1 answer


You are talking about a step in rasterization known as scan-conversion. The GPU takes the positions created by your vertex shader and interpolates their attributes to create fragments, which are passed to your fragment shader. So yes, it is very important for you to set gl_Position in the vertex shader.

After converting triangle coordinates to window coordinates, the scan transform takes the triangle and splits it based on the position of the window pixels over the output image that covers the triangle. Source



scan conversion of a triangle

+10


source







All Articles