When doing GPU programming, it’s sometimes useful to determine the positions of the vertices of the current triangle primitive in a fragment shader. It turns out, though, that there is a relatively straightforward solution without any extra shader stages using the standard derivative functions dFdx and dFdy.

Full article at: https://pcwalton.github.io/2018/02/14/determining-triangle-geometry-in-fragment-shaders.html