before which version, there is not uniform bool so must use uniform float(0.0/1.0) to use instead? how to avoid the float precision when compare the bool value with 0.0 or 1.0? use epsilon? or compare with another middle value such as 0.5
and how about the latest version?
Every version of GLSL has had bool
as a discrete type.
Thanks. But why many ppl use float instead of bool uniform.
I cannot speak to what “many ppl” are doing. Maybe you’re looking at old resources.
The OP in that stackoverflow article was using a vertex attribute not a uniform as a bool. The answer correctly says to use a uniform, which avoids the normalization problem the OP had because of using a vertex attribute, but uses a float uniform, seemingly unaware of the existence of a bool type in GLSL. You can set bool uniforms via either glUniform*i{v} or glUniform*f{v}
. OpenGL does the type conversion.
nothing about efficiency?
how about use float instead of bool then pack this float into a vec4, will this faster? esp. on Mobile
Thanks!
… why are you citing stuff from over a decade ago?
there are many old project and code
The GLSL specs specifically says w.r.t bool “there is no expectation that hardware directly supports variables of this type.” In other words the hardware will do whatever is best for itself. There is no need to second guess it. Just indicate your intent by using bool
. By the way you can declare bvec4
if you want a 4 component vector of booleans.
Unity does its own thing with shaders partly because it can run on various backends. Whether or not it has booleans I have no idea but their choice is irrelevant to your original question which is about OpenGL.
there is not only unity did like this but also some other project(commercial or open source), do you know why they all did this?
thanks
I have no idea and if you are using OpenGL {,ES} it doesn’t matter. Instead of worrying about it, use bool
, so the driver knows what you want. This lets the driver choose the best implementation for itself. Therefore you will get the best performance on each driver/GPU. Second guessing may result on good performance on some drivers but will almost certainly be bad on others.
OK, I’m curious: what is your intent here?
Is the idea that every time someone tells you how things are, you will post some tangentially-related and outdated information from over a decade ago to refute it? Because I don’t know what exactly it is you expect to learn by doing this.
You asked for information, and answers were provided. Do you not trust those answers? Do you think we’re trying to trick you? Do you think that bool
s are some kind of noob-trap and we’re attempting to keep your shaders slow by telling you to use them?
Because you seem surprisingly invested in what is ultimately a completely irrelevant thing that will have zero bearing on the performance of your shader. You have spent more time looking up ancient information than you could ever possibly have saved across all executions of your shader in every program you use it in.
It doesn’t matter. It never mattered. Even on hardware that couldn’t handle integers, the driver would just use float
s behind the scenes for you.