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

Question Remap for MaskMap

Discussion in 'Shader Graph' started by KYL3R, Jun 16, 2022.

  1. KYL3R

    KYL3R

    Joined:
    Nov 16, 2012
    Posts:
    128
    I want this for my MaskMaps in ShaderGraph:



    There are different Texture Types, that don't help with that:


    Though the "Use Tiling and Offset" checkbox will create the well known GUI part:


    I cannot do the Remapping on my own, there is a "Remap" Node, but you can't convert to property and expose that.
    You can create Float sliders, but no min-max sliders so you need 2 Sliders (min + max) per Attribute (metallic, smoothness, AO)

    The Lit Shader simply defines 6 floats, but the GUI handles it elegantly,
    Code (CSharp):
    1. _MetallicRemapMin("MetallicRemapMin", Float) = 0.0
    2. _MetallicRemapMax("MetallicRemapMax", Float) = 1.0
    3. _SmoothnessRemapMin("SmoothnessRemapMin", Float) = 0.0
    4. _SmoothnessRemapMax("SmoothnessRemapMax", Float) = 1.0
    5. _AORemapMin("AORemapMin", Float) = 0.0
    6. _AORemapMax("AORemapMax", Float) = 1.0
    which is because the LIT shader uses CustomEditor "Rendering.HighDefinition.LitGUI".

    But even creating "_SmoothnessRemapMin" and "_SmoothnessRemapMax" as floats does not help, no matter if exposed or not. The DualSliders do not appear :(

    Is there a way? Or do you think this would be a nice suggestion?

    I need RangeSliders, or the Texture Mode "MaskMap" with a checkbox "Use Remap Sliders" to enable the gui for that.
     
    Last edited: Jun 16, 2022
  2. Misaki_eKU

    Misaki_eKU

    Joined:
    May 3, 2018
    Posts:
    53
    you can use custom gui
     
    KYL3R likes this.
  3. KYL3R

    KYL3R

    Joined:
    Nov 16, 2012
    Posts:
    128
    That worked.



    The UI is quite clean now, but the amount of code required was high. I'd still welcome a checkbox to handle the creation of these sliders like the "use tiling and offset".


    For my triplanar Shader, I needed 3 Textures, with each 3 remap sliders.

    MyShaderGui.cs

    Code (CSharp):
    1.  
    2.  
    3. using System.Collections.Generic;
    4. using UnityEngine;
    5. using UnityEditor;
    6. using System.Linq;
    7.  
    8. public class MyShaderGui : ShaderGUI
    9. {
    10.     override public void OnGUI(MaterialEditor materialEditor, MaterialProperty[] properties)
    11.     {
    12.         Material targetMat = materialEditor.target as Material;
    13.  
    14.         Vector2 _TopMetallicRemap = targetMat.GetVector("_TopMetallicRemap");
    15.         Vector2 _TopSmoothnessRemap = targetMat.GetVector("_TopSmoothnessRemap");
    16.         Vector2 _TopOcclusionRemap = targetMat.GetVector("_TopOcclusionRemap");
    17.  
    18.         Vector2 _SidesMetallicRemap = targetMat.GetVector("_SidesMetallicRemap");
    19.         Vector2 _SidesSmoothnessRemap = targetMat.GetVector("_SidesSmoothnessRemap");
    20.         Vector2 _SidesOcclusionRemap = targetMat.GetVector("_SidesOcclusionRemap");
    21.  
    22.         Vector2 _ExtraMetallicRemap = targetMat.GetVector("_ExtraMetallicRemap");
    23.         Vector2 _ExtraSmoothnessRemap = targetMat.GetVector("_ExtraSmoothnessRemap");
    24.         Vector2 _ExtraOcclusionRemap = targetMat.GetVector("_ExtraOcclusionRemap");
    25.  
    26.         string[] sliderProps = { "_TopMetallicRemap", "_TopSmoothnessRemap", "_TopOcclusionRemap",
    27.                                 "_SidesMetallicRemap", "_SidesSmoothnessRemap", "_SidesOcclusionRemap",
    28.                                 "_ExtraMetallicRemap", "_ExtraSmoothnessRemap", "_ExtraOcclusionRemap",};
    29.      
    30.         EditorGUI.BeginChangeCheck();
    31.  
    32.         foreach (MaterialProperty property in properties)
    33.         {
    34.             if(!property.flags.HasFlag(MaterialProperty.PropFlags.HideInInspector) && !sliderProps.Contains(property.name))
    35.             {
    36.                 materialEditor.ShaderProperty(property, property.displayName);
    37.                 if (property.name == "_Top_MaskMap")
    38.                 {
    39.                     EditorGUILayout.MinMaxSlider("Top_MetallicRemap", ref _TopMetallicRemap.x, ref _TopMetallicRemap.y, 0f, 1f);
    40.                     EditorGUILayout.MinMaxSlider("Top_SmoothnessRemap", ref _TopSmoothnessRemap.x, ref _TopSmoothnessRemap.y, 0f, 1f);
    41.                     EditorGUILayout.MinMaxSlider("Top_OcclusionRemap", ref _TopOcclusionRemap.x, ref _TopOcclusionRemap.y, 0f, 1f);
    42.                 }
    43.                 if (property.name == "_Sides_MaskMap")
    44.                 {
    45.                     EditorGUILayout.MinMaxSlider("Sides_MetallicRemap", ref _SidesMetallicRemap.x, ref _SidesMetallicRemap.y, 0f, 1f);
    46.                     EditorGUILayout.MinMaxSlider("Sides_SmoothnessRemap", ref _SidesSmoothnessRemap.x, ref _SidesSmoothnessRemap.y, 0f, 1f);
    47.                     EditorGUILayout.MinMaxSlider("Sides_OcclusionRemap", ref _SidesOcclusionRemap.x, ref _SidesOcclusionRemap.y, 0f, 1f);
    48.                 }
    49.                 if (property.name == "_Extra_MaskMap")
    50.                 {
    51.                     EditorGUILayout.MinMaxSlider("Extra_MetallicRemap", ref _ExtraMetallicRemap.x, ref _ExtraMetallicRemap.y, 0f, 1f);
    52.                     EditorGUILayout.MinMaxSlider("Extra_SmoothnessRemap", ref _ExtraSmoothnessRemap.x, ref _ExtraSmoothnessRemap.y, 0f, 1f);
    53.                     EditorGUILayout.MinMaxSlider("Extra_OcclusionRemap", ref _ExtraOcclusionRemap.x, ref _ExtraOcclusionRemap.y, 0f, 1f);
    54.                 }
    55.             }
    56.         }
    57.      
    58.         // if (EditorGUI.EndChangeCheck())
    59.         {
    60.             targetMat.SetVector("_TopMetallicRemap", _TopMetallicRemap);
    61.             targetMat.SetVector("_TopSmoothnessRemap", _TopSmoothnessRemap);
    62.             targetMat.SetVector("_TopOcclusionRemap", _TopOcclusionRemap);
    63.  
    64.             targetMat.SetVector("_SidesMetallicRemap", _SidesMetallicRemap);
    65.             targetMat.SetVector("_SidesSmoothnessRemap", _SidesSmoothnessRemap);
    66.             targetMat.SetVector("_SidesOcclusionRemap", _SidesOcclusionRemap);
    67.  
    68.             targetMat.SetVector("_ExtraMetallicRemap", _ExtraMetallicRemap);
    69.             targetMat.SetVector("_ExtraSmoothnessRemap", _ExtraSmoothnessRemap);
    70.             targetMat.SetVector("_ExtraOcclusionRemap", _ExtraOcclusionRemap);
    71.  
    72.             EditorUtility.SetDirty(targetMat);
    73.         }
    74.     }
    75. }
    76.  
    77.  
    78.  
    And then you need some variables in the blackboard:


    I had to make these "Exposed" - otherwise Unity would throw errors when trying to get the Vectors from the material, so I added the "sliderProps" array to exclude them from rendering in the GUI, because I draw them as MinMaxSliders anyway.

    And of course you need to set the "Custom Inspector GUI" Name in ShaderGraph:
     
    As_day likes this.
  4. Misaki_eKU

    Misaki_eKU

    Joined:
    May 3, 2018
    Posts:
    53