Search Unity

Question Shader Graph, using own CustomShaderGUI?

Discussion in 'Shader Graph' started by FranFndz, Apr 17, 2020.

  1. FranFndz

    FranFndz

    Joined:
    Sep 20, 2018
    Posts:
    178
    In my previous projects we use ShaderGUI on almost all our shaders.

    why;
    Create easy to undesrtand properties, sliders and organize by blocks.
    Activate render features by toggle buttons, if is is not used hide all properties in inspector.
    Code that identiy the texture parameters to give alpha properties in material inspector or validate assets.
    Bake textures, material inspector receive 4 textures that are saved inside meta file, those texture are baked real time (everytime i insert a texture we bake it) so the shader just have one sample image.

    Using shader graph, how can i costumize the material inspector? Is there an option to select my own CustomEditor "CustomShaderGUI"??

    For example this is our weapon shader that have Toggle Buttons to activate features, also bake Curve animations in textures.

    upload_2020-4-17_11-26-16.png
     
  2. alexandral_unity

    alexandral_unity

    Unity Technologies

    Joined:
    Jun 18, 2018
    Posts:
    163
    This functionality was recently added, it should be available in pacakge version 7.4 and higher, 8.1 and higher, and latest 9.0 preview releases. I don't have an ETA for the release of thse packages right now, but it will be available soon. c:
     
    chrismarch and alexanderameye like this.
  3. FranFndz

    FranFndz

    Joined:
    Sep 20, 2018
    Posts:
    178
    great to hear that~

    thank you!
     
  4. Horus_Sungod42

    Horus_Sungod42

    Joined:
    Oct 30, 2014
    Posts:
    99
    That's great news!

    Is there information on how to use it? Not a full tutorial, just a couple notes, in say, a blog post?

    I've tried 9.0.0 and did not find an obvious options to create custom editor. Perhaps I'm blind or it's not released just yet?

    Thank you
     
    chrismarch likes this.
  5. alexanderameye

    alexanderameye

    Joined:
    Nov 27, 2013
    Posts:
    1,383
    On the master node, click on the little cog and then you can enable a custom GUI.



    You need to provide the name of the class of your custom shader gui.

    For the custom shaderGUI you will need to use the shaderGUI api.

    https://docs.unity3d.com/ScriptReference/ShaderGUI.html
     
  6. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,195
    I'm having trouble getting this to work.

    Just to keep things simple, I created a trivial custom shader gui, based on the example:

    Code (CSharp):
    1.     public class ABCDE : ShaderGUI
    2.     {
    3.         override public void OnGUI(MaterialEditor materialEditor, MaterialProperty[] properties)
    4.         {
    5.             // render the shader properties using the default GUI
    6.             base.OnGUI(materialEditor, properties);
    7.         }
    8.     }
    Everything compiles fine. The class is placed in an Editor directory within the project:
    upload_2020-7-19_15-11-39.png

    But if I try to use this on a shader, it tells me it can't find the class:

    upload_2020-7-19_15-10-50.png


    I tried to specify a "full" path to the class, because I saw some documentation that implied I should. However, it doesn't seem possible to enter "/" or "\" into the ShaderGUI input. They just get removed.
     
  7. alexanderameye

    alexanderameye

    Joined:
    Nov 27, 2013
    Posts:
    1,383
    Weird, I do exactly the same.

    Code (CSharp):
    1. public class testGUI : ShaderGUI
    2. {
    3.     override public void OnGUI(MaterialEditor materialEditor, MaterialProperty[] properties)
    4.     {
    5.         EditorGUILayout.LabelField("My Properties");
    6.         base.OnGUI(materialEditor, properties);
    7.     }
    8. }
    And it seems to work.



    What shadergraph version are you on? Maybe there is a bug with the version you are on. I tried putting my testGUI class in the same folder as my shader, but it also worked when I put it in an Editor folder somewhere else like you did.
     
  8. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,195
    Thanks for confirming it works for you. I looked more closely, and discovered the issue is that I had my ShaderGUI class inside of a namespace. (I add namespaces to all of my scripts.) The ShaderGUI property needs a full path to the class. In this case, "path" means the namespace-qualified path, not the physics path to the class. So, if I put my ABCDE script into the namespace "NS1", and I enter a ShaderGUI path of "NS1.ABCDE", it seems to resolve the path correctly. This all seems fine, I just misinterpretted what I needed to enter here.

    Thanks again.
     
    EricWilliams and alexanderameye like this.
  9. alexanderameye

    alexanderameye

    Joined:
    Nov 27, 2013
    Posts:
    1,383
    Good to know!
     
  10. Deleted User

    Deleted User

    Guest

    How to expose double sided property?!
     
  11. XRA

    XRA

    Joined:
    Aug 26, 2010
    Posts:
    265
    @EagleG it is hidden away in Library/PackageCache/com.unity.render-pipelines.high-definition@10.2.2/Editor/Material/UIBlocks/SurfaceOptionUIBlock.cs

    DrawDoubleSidedGUI() it is possible to replicate the code in your own custom GUI

    But, Unity really needs to expose these UIBlock classes (making them non-internal, non-private) so that users can create proper ShaderGraph material inspectors for real-world production use that extend the HDRP inspectors...

     
    Deleted User likes this.
  12. FranFndz

    FranFndz

    Joined:
    Sep 20, 2018
    Posts:
    178
    I'm just writing all by hand. Using Shader Graph only for prototype
     
  13. alexanderameye

    alexanderameye

    Joined:
    Nov 27, 2013
    Posts:
    1,383
    I tend to do the same sadly, but I do love the rapid iteration of shadergraph and it's great for prototyping.

    For custom shader GUI, I've made some, it looks like this:

    https://twitter.com/i/status/1343937317652852737 (code here: https://pastebin.com/iXHzQC8r)

    You should also take a look at this

    https://github.com/needle-tools/shadergraph-markdown

    It's a tool that will auto-generate a nice shader UI for you, based on your shadergraph.
     
    matias_unity13 and JamesArndt like this.
  14. Hugo-ElectricMonkeys

    Hugo-ElectricMonkeys

    Joined:
    Aug 25, 2016
    Posts:
    7
    Is it possible to use a Scene GUI to control the values of a shader, let's say the direction of an effect using a Gizmo?
     
  15. alexanderameye

    alexanderameye

    Joined:
    Nov 27, 2013
    Posts:
    1,383
    Definitely! You can get a reference to a material by having a public field somewhere for it and assigning it there and then can set the properties using C# with code like Material.SetFloat. You just need to pass the shader property ID's so they should match with the variable names you set in the shader.

    For example in this example, instead of setting the 3D position of a game object you could set a vector property in the shader.

    https://docs.unity3d.com/ScriptReference/Handles.PositionHandle.html