Friday, January 27, 2017

opengl - Can I make color data not render as gradient?


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?



Answer



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: https://stackoverflow.com/questions/27581271/flat-qualifier-in-glsl


No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...