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

后端 未结 3 701
盖世英雄少女心
盖世英雄少女心 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:00

    OpenGL does not have "per-face" attributes. See:

    How can I specify per-face colors when using indexed vertex arrays in OpenGL 3.x?

    Here are a few possible options I see:

    1. Ditch the index arrays and use separate vertices for each face like starmole suggested
    2. Create an index array for each color used. Use materials instead of vertex colors and change the material after drawing the triangles from the index array for each color.
    3. If the geometry allows it, you can make sure the last vertex specified by the index array has the correct vertex color for the face, and then use GL_FLAT shading, or have the fragment shader only use at the last vertex color.

提交回复
热议问题