Search Unity

Question _SpecularHighlights - 0 is true and 1 is false

Discussion in 'Universal Render Pipeline' started by lclemens, Aug 30, 2022.

  1. lclemens

    lclemens

    Joined:
    Feb 15, 2020
    Posts:
    761
    So if I use this code:

    Code (CSharp):
    1.  
    2. float specularHighlights = bakeResult.skin.sharedMaterial.GetFloat("_SpecularHighlights");
    3. UnityEngine.Debug.Log($"_SpecularHighlights is {specularHighlights}");
    4.  
    And then the box for specular highlights...

    upload_2022-8-30_1-57-1.png

    and then run my script... I get this:

    upload_2022-8-30_1-58-37.png

    If I uncheck the box - the opposite happens... It says

    upload_2022-8-30_1-59-27.png

    So 0 is true and 1 is false. It seems like it should be the other way around. What's up with that?

    Unity 2021.3.8 with URP 12.1.7 with URP/SimpleLit shader.

    I am attempting to get these values in an editor script.

    On a side-note, I just spent 4 hours researching (via experimentation, looking through shader source code, and internet research) how to detect if that box was checked via using IsKeywordEnabled(), and wasn't able to come up with a solution. Fortunately now that I know true is 0 and false is 1, I can use _SpecularHighlights.

    if (bakeResult.skin.sharedMaterial.IsKeywordEnabled("_SpecularHighlights")) {
    UnityEngine.Debug.Log($"_SpecularHighlights is enabled");
    } else {
    UnityEngine.Debug.Log($"_SpecularHighlights is disabled");
    }
    if (bakeResult.skin.sharedMaterial.IsKeywordEnabled("_SPECULAR_COLOR")) {
    UnityEngine.Debug.Log($"_SPECULAR_COLOR is enabled");
    } else {
    UnityEngine.Debug.Log($"_SPECULAR_COLOR is disabled");
    }
    if (bakeResult.skin.sharedMaterial.IsKeywordEnabled("SPECULAR_COLOR")) {
    UnityEngine.Debug.Log($"SPECULAR_COLOR is enabled");
    } else {
    UnityEngine.Debug.Log($"SPECULAR_COLOR is disabled");
    }
    if (bakeResult.skin.sharedMaterial.IsKeywordEnabled("_SPECULARHIGHLIGHTS_OFF")) {
    UnityEngine.Debug.Log($"_SPECULARHIGHLIGHTS_OFF is enabled");
    } else {
    UnityEngine.Debug.Log($"_SPECULARHIGHLIGHTS_OFF is disabled");
    }
    if (bakeResult.skin.sharedMaterial.IsKeywordEnabled("_SPECULARHIGHLIGHTS_ON")) {
    UnityEngine.Debug.Log($"_SPECULARHIGHLIGHTS_ON is enabled");
    } else {
    UnityEngine.Debug.Log($"_SPECULARHIGHLIGHTS_ON is disabled");
    }
    if (bakeResult.skin.sharedMaterial.IsKeywordEnabled("_SPECULAR_HIGHLIGHTS")) {
    UnityEngine.Debug.Log($"_SPECULAR_HIGHLIGHTS is enabled");
    } else {
    UnityEngine.Debug.Log($"_SPECULAR_HIGHLIGHTS is disabled");
    }
    if (bakeResult.skin.sharedMaterial.IsKeywordEnabled("_GLOSSINESS_FROM_BASE_ALPHA")) {
    UnityEngine.Debug.Log($"_GLOSSINESS_FROM_BASE_ALPHA is enabled");
    } else {
    UnityEngine.Debug.Log($"_GLOSSINESS_FROM_BASE_ALPHA is disabled");
    }