Approach for writing a GLSL fragment shader with a solid color per triangle/face

后端 未结 3 703
盖世英雄少女心
盖世英雄少女心 2021-02-10 02:36

I have vertex and triangle data which contains a color for each triangle (face), not for each vertex. i.e. A single vertex is shared by multiple faces, each face poten

3条回答
  •  情话喂你
    2021-02-10 03:11

    In addition to the other answers, you could maybe employ the gl_PrimitiveID variable, that's an input to the fragment shader (don't know since which version) and is incremented implicitly for each triangle. You could then use this to lookup the color (either from a 40k buffer texture of colors or color indices into a 15 color color map, or just some direct computation from the primitive id). But don't ask me about the performance of this approach.

提交回复
热议问题