0
\$\begingroup\$

My primary goal is to have a lowpoly rendering style, so that each triangle has its own homogeneous color on all its fragments, meaning color is not interpolated between vertex.

I have my indices buffer with 4 values: 3 integers indicating the vertex index, and one ubyte indicating the color index from a 1D texture, which is just an array of 256 24bits colors in a vec3.

Is it possible to do this with opengl3.3 in core profile?

Do I need glVertexAttribDivisor? I'm not sure I really understand what it does exactly.

I've also heard about flat shading, but I don't know exactly how I could do it. I could also set a color per vertex, but triangles would share vertices, so it doesn't seem like a solution.

\$\endgroup\$
2
  • 1
    \$\begingroup\$ "My primary goal is to have a lowpoly rendering style, so that each triangle has its own proper color." How is that different than what OpenGL already does? \$\endgroup\$ Sep 10, 2018 at 16:28
  • \$\begingroup\$ I edited my question \$\endgroup\$
    – jokoon
    Sep 11, 2018 at 19:12

1 Answer 1

1
\$\begingroup\$

glVertexAttribDivisor wouldn't help you: it is used to specify an attribute per model instance.

If you draw 10 instances of a house model of 1000 vertices, then you can use the divisor to set a value (for tranform, colour, etc.) per instance.

If I were you, I would draw my geometry non-instanced, thus use glDrawArrays() instead of glDrawElements().

You would have to flatten the model by removing the indexing.

Once you have that, you can simply supply the same colour to each of the three vertices of each triangle.

In your case, you would give the same 1D texture coordinate for each vertex, as you are using a texture as your colour palette.

Make sure you set the sampling to GL_NEAREST so that your texture sample doesn't get interpolated.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .