/LWGUI

A Lightweight, Flexible, Powerful Shader GUI System for Unity.

Primary LanguageC#MIT LicenseMIT

LWGUI (Light Weight Shader GUI)

中文 | English

A Lightweight, Flexible, Powerful Unity Shader GUI system.

Use simple MaterialProperty Drawer syntax to achieve complex Shader GUI, save a lot of development time, easy to use and expand, effectively improve the user experience of artists.

809c4a1c-ce80-48b1-b415-7e8d4bea716e

LWGUI

Installation

  1. Make sure your environment is compatible with LWGUI: Unity 2017+
  2. Open your project
  3. Window > Package Manager > Add > Add package from git URL , enter: https://github.com/JasonMa0012/LWGUI.git
    • You can also choose to manually download the Zip from Github,then: Package Manager > Add package from disk

Usage

Getting Started

  1. Create a newer or use the existing Shader
  2. Open the Shader in the code editor
  3. At the bottom of the Shader, before the last large bracket, add line:CustomEditor "LWGUI.LWGUI"
  4. Completed! Start using the following powerful Drawer to easily draw your Shader GUI

LWGUI Drawers

Main & Sub

/// Create a Folding Group
/// group:group name (Default: Property Name)
/// keyword:keyword used for toggle, "_" = ignore, none or "__" = Property Name +  "_ON", always Upper (Default: none)
/// default Folding State: "on" or "off" (Default: off)
/// default Toggle Displayed: "on" or "off" (Default: on)
/// Target Property Type: FLoat, express Toggle value
MainDrawer(string group, string keyword, string defaultFoldingState, string defaultToggleDisplayed)
/// Draw a property with default style in the folding group
/// group:father group name, support suffix keyword for conditional display (Default: none)
/// Target Property Type: Any
SubDrawer(string group)

Example:

[Title(Main Samples)]
[Main(GroupName)]
_group ("Group", float) = 0
[Sub(GroupName)] _float ("Float", float) = 0


[Main(Group1, _KEYWORD, on)] _group1 ("Group - Default Open", float) = 1
[Sub(Group1)] _float1 ("Sub Float", float) = 0
[Sub(Group1)] _vector1 ("Sub Vector", vector) = (1, 1, 1, 1)
[Sub(Group1)] [HDR] _color1 ("Sub HDR Color", color) = (0.7, 0.7, 1, 1)

[Title(Group1, Conditional Display Samples       Enum)]
[KWEnum(Group1, Name 1, _KEY1, Name 2, _KEY2, Name 3, _KEY3)]
_enum ("KWEnum", float) = 0

// Display when the keyword ("group name + keyword") is activated
[Sub(Group1_KEY1)] _key1_Float1 ("Key1 Float", float) = 0
[Sub(Group1_KEY2)] _key2_Float2 ("Key2 Float", float) = 0
[Sub(Group1_KEY3)] _key3_Float3_Range ("Key3 Float Range", Range(0, 1)) = 0
[SubPowerSlider(Group1_KEY3, 10)] _key3_Float4_PowerSlider ("Key3 Power Slider", Range(0, 1)) = 0

[Title(Group1, Conditional Display Samples       Toggle)]
[SubToggle(Group1, _TOGGLE_KEYWORD)] _toggle ("SubToggle", float) = 0
[Tex(Group1_TOGGLE_KEYWORD)][Normal] _normal ("Normal Keyword", 2D) = "bump" { }
[Sub(Group1_TOGGLE_KEYWORD)] _float2 ("Float Keyword", float) = 0


[Main(Group2, _, off, off)] _group2 ("Group - Without Toggle", float) = 0
[Sub(Group2)] _float3 ("Float 2", float) = 0

Default result:

image-20220828003026556

Then change values:

image-20220828003129588

SubToggle

/// Similar to builtin Toggle()
/// group:father group name, support suffix keyword for conditional display (Default: none)
/// keyword:keyword used for toggle, "_" = ignore, none or "__" = Property Name +  "_ON", always Upper (Default: none)
/// Target Property Type: FLoat
SubToggleDrawer(string group, string keyWord)

For usage, please refer to the Main & Sub example

SubPower

/// Similar to builtin PowerSlider()
/// group:father group name, support suffix keyword for conditional display (Default: none)
/// power: power of slider (Default: 1)
/// Target Property Type: Range
SubPowerSliderDrawer(string group, float power)

For usage, please refer to the Main & Sub example

KWEnum

/// Similar to builtin Enum()
/// group:father group name, support suffix keyword for conditional display (Default: none)
/// n(s): display name
/// k(s): keyword
/// Target Property Type: FLoat, express current keyword index
KWEnumDrawer(string group, string n1, string k1, string n2, string k2, string n3, string k3, string n4, string k4, string n5, string k5)

For usage, please refer to the Main & Sub example

Tex & Color

/// Draw a Texture property in single line with a extra property
/// group:father group name, support suffix keyword for conditional display (Default: none)
/// extraPropName: extra property name (Unity 2019.2+ only) (Default: none)
/// Target Property Type: Texture
/// Extra Property Type: Any, except Texture
TexDrawer(string group, string extraPropName)
/// Display up to 4 colors in a single line
/// group:father group name, support suffix keyword for conditional display (Default: none)
/// color2-4: extra color property name (Unity 2019.2+ only)
/// Target Property Type: Color
ColorDrawer(string group, string color2, string color3, string color4)

Example:

[Main(Group3, _, on)] _group3 ("Group - Tex and Color Samples", float) = 0
[Tex(Group3, _color)] _tex_color ("Tex with Color", 2D) = "white" { }
[HideInInspector] _color (" ", Color) = (1, 0, 0, 1)
[Tex(Group3, _float4)] _tex_float ("Tex with Float", 2D) = "white" { }
[HideInInspector] _float4 (" ", float) = 0
[Tex(Group3, _range)] _tex_range ("Tex with Range", 2D) = "white" { }
[HideInInspector] _range (" ", Range(0,1)) = 0
[Tex(Group3, _textureChannelMask1)] _tex_channel ("Tex with Channel", 2D) = "white" { }
[HideInInspector] _textureChannelMask1(" ", Vector) = (0,0,0,1)

// Display up to 4 colors in a single line (Unity 2019.2+)
[Color(Group3, _mColor1, _mColor2, _mColor3)]
_mColor ("Multi Color", Color) = (1, 1, 1, 1)
[HideInInspector] _mColor1 (" ", Color) = (1, 0, 0, 1)
[HideInInspector] _mColor2 (" ", Color) = (0, 1, 0, 1)
[HideInInspector] [HDR] _mColor3 (" ", Color) = (0, 0, 1, 1)

Result:

image-20220828003507825

Channel

/// Draw a R/G/B/A drop menu
/// group:father group name, support suffix keyword for conditional display (Default: none)
/// Target Property Type: Vector, used to dot() with Texture Sample Value
ChannelDrawer(string group)

Example:

[Title(_, Channel Samples)]
[Channel(_)]_textureChannelMask("Texture Channel Mask (Default G)", Vector) = (0,1,0,0)

......

float selectedChannelValue = dot(tex2D(_Tex, uv), _textureChannelMask);

image-20220822010511978

Ramp

/// Draw a Ramp Map Editor (Defaulf Ramp Map Resolution: 512 * 2)
/// group:father group name, support suffix keyword for conditional display (Default: none)
/// defaultFileName: default Ramp Map file name when create a new one (Default: RampMap)
/// defaultWidth: default Ramp Width (Default: 512)
/// Target Property Type: Texture2D
RampDrawer(string group, string defaultFileName, float defaultWidth)

Example:

[Space(50)]
[Title(_, Ramp Samples)]
[Ramp] _Ramp ("Ramp Map", 2D) = "white" { }

Result:

image-20220821234224093

New a Ramp Map and edit:

image-20220821234658509

You must manually Save the edit results, if there are unsaved changes, the Save button will display yellow.

When you move or copy the Ramp Map, remember to move together with the .meta file, otherwise you will not be able to edit it again!

MinMaxSlider

/// Draw a min max slider (Unity 2019.2+ only)
/// group:father group name, support suffix keyword for conditional display (Default: none)
/// minPropName: Output Min Property Name
/// maxPropName: Output Max Property Name
/// Target Property Type: Range, range limits express the MinMaxSlider value range
/// Output Min/Max Property Type: Range, it's value is limited by it's range
MinMaxSliderDrawer(string group, string minPropName, string maxPropName)

Example:

[Title(MinMaxSlider Samples)]
[MinMaxSlider(_rangeStart, _rangeEnd)] _minMaxSlider("Min Max Slider (0 - 1)", Range(0.0, 1.0)) = 1.0
_rangeStart("Range Start", Range(0.0, 0.5)) = 0.0
[PowerSlider(10)] _rangeEnd("Range End PowerSlider", Range(0.5, 1.0)) = 1.0

Result:

image-20220828003810353

Title

/// Similar to Header()
/// group:father group name, support suffix keyword for conditional display (Default: none)
/// header: string to display
TitleDecorator(string group, string header)

Unity Builtin Drawers

Space

MaterialSpaceDecorator(float height)

Header

MaterialHeaderDecorator(string header)

Enum

MaterialEnumDrawer(string n1, float v1, string n2, float v2, string n3, float v3, string n4, float v4, string n5, float v5, string n6, float v6, string n7, float v7)

IntRange

MaterialIntRangeDrawer()

KeywordEnum

MaterialKeywordEnumDrawer(string kw1, string kw2, string kw3, string kw4, string kw5, string kw6, string kw7, string kw8, string kw9)

PowerSlider

MaterialPowerSliderDrawer(float power)

Toggle

MaterialToggleUIDrawer(string keyword)

Tips

  1. Drawer's first parameter is always Group, so when there is only one parameter, the behavior of different Drawers may be different. Therefore, if you want to use Drawers outside the Folding Group, the first parameter is best to give “_”.
  2. It is best to use Title() instead of the built-in Header() , otherwise there will be misplaced.
  3. If you change the Shader but the GUI is not updated, manually change the Shader to throw an error, and then change it back to refresh the GUI.

TODO

  • Per material save the Folding Group open state
  • Support for Unreal Style Revertable GUI
  • Support for HelpBox
  • Support for Tooltip, displays default values and custom content
  • Support for upper-right menu, can be all expanded or collapsed
  • Support for ShaderGraph or ASE
  • Support for change text format
  • Support for Pass switch
  • Support for Curve
  • Support for search properties

Contribution

  1. Create multiple empty projects using different versions of Unity
  2. Pull this repo
  3. Use symbolic links to place this repo in the Assets or Packages directory of all projects
  4. Inherit the Subdrawer in shadeerdrawer.cs to start developing your custom Drawer
  5. Check whether the functionality works in different Unity versions
  6. Pull requests

Tips

todo