Can you indicate if the vertex attribute of the vertex shader is enabled?

I was wondering if there is a way to find out if the vertex attribute is enabled from the vertex shader? I know that if the vertex attribute is disabled, all values ​​will be treated as 0.0, so I could run the test as follows:

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

But this has an obvious problem for the case when the attribute is enabled and the value is simply set to 0 (it will be processed as if it were disabled)!

Another solution would be to simply use a single variable that states whether or not to use this attribute, but I wondered if there was something built into GLSL that would do this?

+4
source share
2 answers

Not. Not.

Swipe the boolean to imitate it.

+5
source

FYI:

I know that if the vertex attribute is disabled, all values ​​will be treated as 0.0, so I could run the test as follows:

This is not true. If the attribute is disabled, its value comes from the normal state of OpenGL. Namely, the state specified by glVertexAttrib functions. Thus, it is completely legal to have such "persistent attributes" sent to shaders.

This is why the API has no way for the shader to determine if an attribute is disabled. The disabled attribute may still have meaningful data.

+13
source

Source: https://habr.com/ru/post/1397886/


All Articles