I'm trying to pass a boolean into my vertex shader for the first time; I've only been using floats until now.
The boolean in question is primitive-specific so cannot be passed as a uniform. However it has the same value for all vertices of any given primitive.
It seems from the Khronos spec that 'varying' is the only way to pass data into the fragment shader, but unsurprisingly declaring 'varying bool my_bool;' causes a parser error when defined in my vertex shader.
I'm passing the boolean into my vertex shader as:
attribute bool a_my_bool;
I define a varying in an attempt to pass to the fragment shader:
varying bool v_my_bool;
void main() {
// ...
v_my_bool = a_my_bool;
}
Could someone please tell me how I can achieve what I intend?
Best Answer
From §4.3.5 of The OpenGL® ES Shading Language version 1.0.17 (PDF):
And from §4.3.3:
So you can't have an
attribute bool
, let alone avarying bool
, according to the spec.If you really need a boolean value per vertex you could use 0.0 for false and 1.0 for true. When testing, check for
x > 0.5
. eg:As long as all vertices in each triangle have the same value this should work. If they aren't consistent, then you'll end up with different fragments for the same triangle behaving differently. (If you stick to 0.0 and 1.0 the quarter of the triangle closest to the "odd" corner will behave differently from the rest.)