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

I have vertices and triangles data that contain color for each triangle (face), and not for each vertex. those. one vertex is shared by several faces, each of which has a potentially different color.

How do I approach this issue in GLSL to get a clear color assignment for each face displayed? Calculating and assigning a vertex color buffer by averaging the colors of neighboring vertex policies is quite simple, but this, of course, creates a blurry result where the colors are interpolated in the fragment shader.

What I really need does not have to be interpolated color values ​​at all, I will have about 40k triangles obscured by about 15 possible solid colors as soon as it works as intended.

+5
source share
3 answers

, , GLSL, - . . . . , - O (n). , . . , .

, :

, . ddx (dFdx) ddy (dFdy) . - ! .

+6

OpenGL "per-face". :

OpenGL 3.x?

:

  • , , starmole.
  • . .
  • , , , , , GL_FLAT .
+4

In addition to other answers, you could use a variable gl_PrimitiveIDthat injects a fragment into the shader (I don’t know which version) and implicitly increases for each triangle. Then you can use this to search for color (either from a 40-kilogram texture of a bunch of flowers or color indices into a 15 color color map, or just to directly calculate from a primitive id). But do not ask me about the effectiveness of this approach.

+3
source

All Articles