I have a vertex shader with attributes that may or may not be set in any given frame. How can I check whether or not these attributes have been set?
What I'd 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);
}
}
I have a vertex shader with attributes that may or may not be set in any given frame.
No, you don't. :)
With attributes, it's impossible that an attribute wouldn't be "set". Every vertex shader instance receives valid values from every declared attribute.
If the attribute array is not enabled by glEnableVertexArray, then the default attribute (as specified by glVertexAttrib and its defaults) will be passed.
In your case, you can either:
Pick one.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With