Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by MissEmbyr · Jun 02, 2020 at 04:50 PM · shadersshader programming

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?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

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.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image MissEmbyr · Jun 03, 2020 at 03:25 AM 0
Share

Thanks! This is exactly what I was looking for.

avatar image
0

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.alt text


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.


ex-1.png (12.6 kB)
Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image MissEmbyr · Jun 02, 2020 at 09:04 PM 0
Share

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
avatar image ADiSiN MissEmbyr · Jun 03, 2020 at 01:36 AM 1
Share

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

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

142 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges