- Home /
Shader graph equivelent of Unreal's StaticBool?
In Unreal's material editor (shader editor) there is the ability to define a StaticBool parameter that allows you to set a per-"material instance" (what unity calls materials) boolean that you can branch on without any performance impact as it's compile-time.
Is there any way we can do this with shader graph so that we can switch on and off features per-material without having to create a new shader soley for that purpose?
Answer by Bunny83 · Jun 03, 2020 at 12:05 AM
What you are looking for is called a shader variant in Unity. I was never in need of this feature and haven't used ShaderGraph a lot. However according to this forum thread the current Unity version should support keywords and shader variants in shader graph.
Answer by ADiSiN · Jun 02, 2020 at 06:26 PM
Hi!
I am not sure if I got you right, but if did then you want to create Branch node where you can connect any created Boolean in shadergraph to Predicate field and by switching the Boolean state it will enable/disable related features connected with True and False fields.
The only thing that you should keep in mind that in order to switch the Boolean through script you must treat it as float, not boolean. Like this:
material.SetFloat("Boolean name", 1f);
Code above will switch Boolean to true.
If you change 1f to 0f then it will be switched to false.
I hope it helps.
This isnt really what I'm looking for as the branch isn't compile time like in Unreal as far as I know. Or if it is they dont mention it anywhere. Branches in shader code are incredibly slow so I'm essentially looking for the stader graph equivelent of:
#if GLOW_ENABLED
// shader code
#endif
Oh, I really did misunderstand your question, sorry about that.
Sadly I don't have knowledge of it, but according to answer from @Bunny83 this link might be helpful for you: https://docs.unity3d.com/Packages/com.unity.shadergraph@9.0/manual/Keywords.html
However, I can be wrong with the provided link, since wasn't in necesserity of this yet.
Your answer

Follow this Question
Related Questions
Silhouette overlay shader 0 Answers
Why doesn't clip shader work with shadows? 0 Answers
Modifying the depth buffer of an image effect? 0 Answers
Porting from ShaderToy(GLSL) to shaderlab(HLSL/CG) unity not giving me the desired result. 2 Answers
Why are there stretch marks using my triplanar shader? 2 Answers