I know that perspective interpolation of vertex attributes is automatically handled in the rendering pipeline, but I want to verify whether my understanding of perspective interpolation is correct, so I want to perform perspective interpolation of texture coordinates, but I found that I can’t get the parameters necessary for interpolation in the fragment shader, so I want to know if I can control this process manually.
You can get linearly-interpolated vertex attributes by declaring the corresponding fragment shader input with the noperspective qualifier. If you add binary attributes (i.e. (1,0,0,0), (0,1,0,0) etc) to the vertices, the interpolated value will be the barycentric coordinates of the sample location.
But to perform perspective interpolation in the fragment shader, it would need access to the original attributes for all three vertices. So you’d have to pass that information in somehow, e.g. via a UBO or texture which you would index with gl_PrimitiveID in the fragment shader. Or a geometry shader which copies the values for the three vertices to each of the vertices.