Generic attributes state in shaders

Hello,

I was wondering if it was possible in a shader to get the status of a generic vertex attribute.
That is, can we know in a GLSL program, if an attribute has been enabled or disabled (via gl{Enable, Disable}VertexAttribArray).

My problem is that I would like to display meshes that share some points, but some of these meshes don’t have explicit normals and I would like some flat shading on them.

So I figured I could compute the normal in the geometry shader if the “in_normal” vertex attribute was disabled, and do nothing if enabled.
I guess I could just pass a boolean uniform if it was not the case anyway :slight_smile:

You could use latched vertex attributes in combination with a special value encoding “no normals”.

Something like


...
// disable per-vertex normals
glDisableVertexAttribArray(normal_attrib_idx);
// set latched normal attrib to "have no normals" special value
glVertexAttrib1f(normal_attrib_idx, 0.0f);
...

then in the shader do:


if (dot(normal, normal)==0.0f)
{
  // have no valid normal, generat it somehow
}

But in general, I would not recommend this approach. You better write a special shader for the case no vertex normals are present.

Alright, thanks :slight_smile:

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.