Can you tell if a vertex attribute is enabled from within a vertex shader?

人盡茶涼 提交于 2019-11-28 07:31:52

问题


I was wondering if there was a way to tell if a vertex attribute is enabled from within a vertex shader? I know that if the vertex attribute is disabled all the values will be treated as 0.0, so I could do a test like the following:

if (attribute == 0)
{
    // Do something different to normal.
}
else
{
    // Use the attribute.
}

But this has the obvious problem for the case that the attribute is enabled and the value is just set to 0 (it will be treated as if it's disabled)!

The other solution would be to just use a uniform variable that states whether or not to use the attribute, but I wondered if there was anything built into GLSL that would do that?


回答1:


No there isn't.

Pass a boolean uniform yourself to emulate it.




回答2:


FYI:

I know that if the vertex attribute is disabled all the values will be treated as 0.0, so I could do a test like the following:

That is not true. If an attribute is disabled, its value comes from regular OpenGL state. Namely, the state set by the glVertexAttrib functions. So it is perfectly legal to have these kinds of "constant attributes" sent to shaders.

That's why the API doesn't have a way for a shader to tell if an attribute is "disabled". A "disabled" attribute may still have meaningful data.



来源:https://stackoverflow.com/questions/9402457/can-you-tell-if-a-vertex-attribute-is-enabled-from-within-a-vertex-shader

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!