Search code examples
c++glslfragment-shadervertex-shader

GLSL can't compile a shader without interpolation (flat)


I'm drawing a complete object with mutiple meshes from a single vertex/index buffer, and they have different textures. Thus, I thought of passing ID of texture along with the vertices from vertex shader to fragments in the fragment shader. The problem is disabling the interpolation. I'm using GLSL ver 3.3 with SDL2 and glew on MingW.

I've tried flat out uint frag_MeshID; instead of out uint frag_MeshID; in the vertex shader, but still I get this error while compiling the fragment shader:

'frag_MeshID' : int/uint varying in is not flat interpolated

This is my corresponding fragment shader snippet: in uint frag_MeshID;

Am I missing something?


Solution

  • Ok, so this appears to be a wrong assumption I made. The fragment shader also needs the flat keyword. (I thought the vertex shader flat attribute will make the uint flat for next level)

    So, this as fragment shader works: flat in uint frag_MeshID; (with vertex shader: flat out uint frag_MeshID;)