How to setup static branching in a shader?

How do I setup static branching in a shader? I’m unsure how to pass a bool value using setShaderInput. Is there a boolean equivalent to float4 such as

in uniform bool k_value

so later on in the shader I can do

if (k_value) {
blah blah blah
}

?

You can use a float comparison. But you really shouldn’t use conditionals in a shader, as they are extremely slow.

In theory, this should be a static branch, not a dynamic branch. It’s evaluation should be the same across every fragment and so ideally should be optimized by the GPU (or better optimized).

But most examples of static branching that I read about use a boolean variable. I’m unsure of a float comparison like if (val.x > 0.4) still classifies as a static comparison, even if the float initially came from a uniform value such as

in uniform float4 val

I’d like to try the static branching as a compromise to using #ifdefs which would require a slow shader context switch.

Try declaring a uniform boolean variable and computing it using one of the float4 shader inputs. It thats legal, theres a good chance using it in an if will do a static branch.

Also, theres is supposed to be a way to pass more types to shaders now, though I haven’t tried it yet.