How do I undo the interpolation of vertex attributes? I'm using unity shader graph which doesn't support nointerpolation. I assume I need to store 3 float3 with one component of each float3 being 1 and the rest 0, this will give the barycentric coordinate. But I don't know how to actually use them to undo the interpolation.

  • $\begingroup$ do you have access to the barycentric weights? which geometry type are you using (triangles, quads, lines)? what is the shader language (glsl, hlsl)? $\endgroup$
    – Thomas
    Jan 12, 2023 at 15:56
  • $\begingroup$ @Thomas: "what is the shader language (glsl, hlsl)?" The OP said that they're "using unity shader graph", so that's the "shader language". $\endgroup$ Jan 12, 2023 at 16:25
  • $\begingroup$ Unity uses triangles as the primitive type. Shader Graph uses nodes, not code, but shaders can be written in hlsl. But I'm using a render pipeline which makes it hard to write shader code, so I'd rather use Shader Graph. I think to get the barycentric coordinate, we just have 3 float3 attributes (I think they are called varyings), (1,0,0),(0,1,0),(0,0,1), Which automatically get processed in the vertex->frag stage, and those values become the barycentric coordinate in the fragment stage. @Thomas $\endgroup$
    – Shiv-iwnl
    Jan 12, 2023 at 16:32
  • $\begingroup$ Does shader graph have "partial derivatives" (in glsl it is the function dFdx/dFdy) within its fragment stage? If so, I think you can back calculate each vertex value... $\endgroup$
    – Thomas
    Jan 12, 2023 at 19:43
  • 1
    $\begingroup$ This sounds like an xy problem. What is the real problem your trying to solve. $\endgroup$
    – joojaa
    Jan 13, 2023 at 6:22

1 Answer 1


Even with the barycentric coordinates, you cannot "undo" interpolation. Interpolation uses 3 input values and produces one output value: $f(A, B, C) = O$. So to reverse that would mean that you have one equation with three unknowns, ignoring the coordinate itself. You cannot solve for 3 unknowns with one equation.

If Unity's Shader Graph tool doesn't support flat interpolation, then it's probably best to solve the specific problem rather than searching for a general solution. The way to do this will be particular to exactly the effect you're trying to achieve.

  • $\begingroup$ I'm using the UV coordinate for the texture index(u), and texture tilling (v), but the UV gets interpolated which makes a border of textures around different textures (it's ugly!), I've tried setting a single triangle to always only have one texture, but since I'm using shared vertices, it doesn't make a difference. @Nicol Bolas $\endgroup$
    – Shiv-iwnl
    Jan 12, 2023 at 16:39
  • $\begingroup$ Isn't there a way to get the 3 vertices of the triangle the current fragment is in? $\endgroup$
    – Shiv-iwnl
    Jan 12, 2023 at 16:42
  • $\begingroup$ @Shiv-iwnl: "since I'm using shared vertices" Well there's your problem: stop sharing vertices when the vertex data clearly is not the same between the two triangles. Triangles that use two different textures do not share texture coordinates and therefore cannot share vertices, even if the positions at those vertices are the same. "Isn't there a way to get the 3 vertices of the triangle the current fragment is in?" No. $\endgroup$ Jan 12, 2023 at 16:46
  • $\begingroup$ it seems like I can still get good results if I share vertices that have the same texture id, but not share when they have different ids. a hybrid approach. And I can also assign each vertex it's unique id instead of the whole triangle $\endgroup$
    – Shiv-iwnl
    Jan 12, 2023 at 18:35
  • $\begingroup$ @NicolBolas mathematically speaking you are right. But there might be ways to receive more values... And with these values it is solvable. For example: when giving each vertex a 3d vector (1,0,0) (0,1,0) and (0,0,1). Then you receive in the fragment stage the barycentric coordinates. I'm not familiar with shader graph, but if they support "partial derivatives", you can receive the barycentric coordinates of the neighboring pixels and all their varyings... And I bet, than it is calculate able... $\endgroup$
    – Thomas
    Jan 12, 2023 at 20:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.