How to declare boolean in shader script?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By shifitzel

In shader script when I try to declare a bool (outside of a function), the debugger says "expected ‘const’ keyword before constant. How can I declare a non-const boolean?

:bust_in_silhouette: Reply From: aXu_AP

Values declared outside of functions must be either const, uniform (parameter exposed to the editor) or varying (shared between vertex, frac and light functions). Varying is likely the behaviour that you want, here’s docs. For other functions, IIRC you need to pass all the variables as parameters to that function (correct me if I’m wrong!).

It doesn’t allow for varying to be boolean.

shifitzel | 2022-10-04 19:47

Sorry, my bad. It seems that only float-based variables are allowed to be varying. In that case next best solution is to save the results into a float (1.0 if true, 0.0 if false) if you need to pass the value from vertex to frac. As a bonus, this value gets interpolated per pixel.

I think docs should tell about this behaviour, I’ll open issue/pr about it when I’ll have more time.

aXu_AP | 2022-10-07 08:44