Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I would like for the color between my vertices to not be rendered as a gradient, but as a hard break. Is there any way to accomplish this in OpenGL/GLSL?

share|improve this question
up vote 4 down vote accepted

You can try doing this with flat attribute qualifier in shaders, like so:

flat vec3 surfColor;

It tells GLSL to pass values from vertex to fragment without interpolation.

From GLSL Interpolation qualifiers:

Interpolation qualifiers control how interpolation of values happens across a triangle or other primitive. There are three basic interpolation qualifiers.

flat​ The value will not be interpolated. The value given to the fragment shader is the value from the Provoking Vertex for that primitive.
...

Additional read on SO: http://stackoverflow.com/questions/27581271/flat-qualifier-in-glsl

share|improve this answer

These are two options I know:

  1. Define each triangle seperate with the color you want in each vertex. Usually vertices are shared between neighboring triangles. If you make each triangle unique you can set the color of each vertex to the color you want the triangle to be. It increases the number of vertices, but unless you have a huge number of objects this is likely not a issue.
  2. Texture it: make the texturemap of solid colors line up with the vertices and edges. Adds the benefit that you can recolor the model simply by changing the texture.

Both are often used in the 'flatshaded' look.

share|improve this answer
    
I have a huge number of objects (trying to create a large procedurally generated map). Creating textures seems like a pain. Especially if I want to experiment with the color scheme. Thanks though. – GodProbablyExists Oct 7 at 17:49

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.