Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Resolved DOTS ShaderGraph MaterialProperty Bool

Discussion in 'Entity Component System' started by charleshendry, May 16, 2022.

  1. charleshendry

    charleshendry

    Joined:
    Jan 7, 2018
    Posts:
    95
    Hi,

    I'm struggling to set a bool value in Shadergraph from C#. I have several others where I set float values and those all work fine.

    As shadergraph treats all bools as floats and there is no bool type for MaterialPropertyFormat, I'm assuming I have to define the corresponding component as a float as below:

    [MaterialProperty("_ShowProgress", MaterialPropertyFormat.Float)]
    public struct ShowProgressBar : IComponentData
    {
    public float Value;
    }


    The "_ShowProgress" property in the shadergraph is a bool type as that's what the Branch node type reads. Any suggestions much appreciated.
     
  2. scottjdaley

    scottjdaley

    Joined:
    Aug 1, 2013
    Posts:
    152
    One common way to represent a boolean as a float is by storing 0 for false and 1 for true. Then in shader graph you can use a "Comparison" node to compare the float value to something like 0.5. This will give you a bool type in shader graph to then plug into a Branch node or anything else that takes a bool type.

    upload_2022-5-16_9-34-19.png
     
  3. charleshendry

    charleshendry

    Joined:
    Jan 7, 2018
    Posts:
    95
    That makes sense. That's working now, thanks! I'd read somewhere that floats are automatically interpreted as bools when needed, but that's only when not using shadergraph I think.