GLSL - verification of set attributes

I have a vertex shader with attributes that may or may not be set in any given frame. How to check if these attributes are set?

What I would like to do:

attribute vec3 position; attribute vec3 normal; attribute vec4 color; attribute vec2 textureCoord; uniform mat4 perspective; uniform mat4 modelview; uniform mat4 camera; uniform sampler2D textureSampler; varying lowp vec4 vColor; void main() { gl_Position = perspective * camera * modelview * vec4(position, 1.0); if ((bool)textureCoord) { // syntax error vColor = texture2D(textureSampler, textureCoord); } else { vColor = (bool)color ? color : vec4((normal.xyz + 1.0)/2.0 , 1.0); } } 
+4
source share
1 answer

I have a vertex shader with attributes that may or may not be set in any given frame.

No no.:)

With attributes, it is not possible for an attribute to not be "set." Each vertex shader instance receives valid values ​​from each declared attribute.

If the attribute array is not included glEnableVertexArray , then the default attribute will be passed (as indicated by glVertexAttrib and its default values).


In your case, you can:

  • compile your shader in different versions with or without texture (conditional compilation is your friend, google for UberShader),
  • use a single variable of type "useTexturing" to save on shader switches.

Choose one.

+9
source

All Articles