1
votes

I am working on a project for my school and cannot for the life of me figure it out. I need to get the barycentric Coords of a point in a triangle inside of my pixel shader in order to interpolate between the triangle vertex colors and get a final pixel output color. Is there a way I can get the vertex positions of the triangle that I am drawing in from inside of my pixel shader or do I need a different shader? How Should I go about this?

1

1 Answers

2
votes

Store barycentric corner values on each vertex in a triangle:

     v1
      x
     / \         v0=[1,0,0]
    /   \        v1=[0,1,0]
   /     \       v2=[0,0,1]
  x-------x
v0         v2

Pass the vertex attribute from your vertex shader to your pixel shader using linear interpolation(default) and you have per pixel barycentric coordinates. Note that if you're using indexed rendering(using an index buffer) you'll most likely need to deindex your data.