Page 1 of 1

add multiple subshaders in one shader using the editor?

PostPosted: Fri Nov 23, 2018 10:59 pm
by DarrenR
I asked this a year ago and it was said that it was going to be implemented soon so I'm hoping the answer is a positive one.

Is there any way to add multiple subshaders in one shader using the editor? I have replacement shaders on a couple cameras rendering masks and would like to edit them with Amplify.

I'm guessing shader templates might do the job but the wiki is a wall of text with examples that make very little sense to me with no obvious mention of multiple subshaders.

Re: add multiple subshaders in one shader using the editor?

PostPosted: Sat Nov 24, 2018 2:31 am
by cAyou
So far I've seen on templates a list of subshaders, with a possibility to add any subshaders you want on it. Don't know how it works behind, but it looks straight forward.

Re: add multiple subshaders in one shader using the editor?

PostPosted: Sat Nov 24, 2018 12:18 pm
by DarrenR
Thats cool to hear.
Annoyingly I still need an example, as the Wiki doesn't give any and the manual doesn't mention this from what i can see.
I can't see any way to add Subshaders in the actual interface.

The actual coding of the shader was simpler than this haha!

Re: add multiple subshaders in one shader using the editor?

PostPosted: Mon Nov 26, 2018 2:20 pm
by Amplify_Borba
Hello, although we don't support doing this through the editor, the templates already account for any sub-shaders that users manually add to the shader code, there should be no further requirements such as adding any ASE specific shader tags.

It's definitely in our plans to improve the UX in terms of using and editing Shader Templates, so all feedback is welcome.
Unfortunately we don't have any ETA to offer regarding these changes, as we've been focused on fixes and supporting the HD and LW SRPs, which consumes a great deal of our resources since Unity has been updating them quite frequently.

Sadly, we don't have any sample that makes use of multiple subshaders to offer at this time, but in the eventuality that you come across any sort of issue while using multiple subshaders through our templates, please let us know, we'll be happy to assist!

Re: add multiple subshaders in one shader using the editor?

PostPosted: Tue Nov 27, 2018 6:04 pm
by DarrenR
Thanks for the reply, it wasn't a huge help unfortunately.

Without any examples or syntax for Sub shaders after a day of trying I gave up. I'm not a shader coder and trying to get a template to work has beaten me.

It would be really nice in the future to have the ability to add/edit sub shaders in the editor. As it is now I have a few really big shaders that I have to edit manually in a text editor.

Even just adding an ase_name breaks the editor when trying to make a template with my shader. (I deleted a bunch of my sub shaders to make it more readable)

Code: Select all
Shader /*ase_name*/ "ASESampleTemplates/MATTETemplateGOGO" /*end*/
{
   Properties
   {
      [HideInInspector] __dirty( "", Int ) = 1
   }

   SubShader
   {
      Tags{ "Matte" = "Cave" "RenderType" = "Opaque"  "Queue" = "Geometry+0" "IsEmissive" = "true"  }
      Cull Back
      CGPROGRAM
      #pragma target 3.0
      #pragma surface surf Unlit keepalpha  noshadow
      struct Input
      {
         fixed filler;
      };

      inline fixed4 LightingUnlit( SurfaceOutput s, half3 lightDir, half atten )
      {
         return fixed4 ( s.Emission, s.Alpha );
      }

      void surf( Input i , inout SurfaceOutput o )
      {
         o.Emission = float4(1,1,1,0).rgb;
         o.Alpha = 1;
      }

      ENDCG
   }
   
   SubShader
   {
      Tags{ "Matte" = "Chasm" "RenderType" = "Opaque"  "Queue" = "Geometry+0" "IsEmissive" = "true"  }
      Cull Back
      CGPROGRAM
      #pragma target 3.0
      #pragma surface surf Unlit keepalpha  noshadow
      struct Input
      {
         fixed filler;
      };

      inline fixed4 LightingUnlit( SurfaceOutput s, half3 lightDir, half atten )
      {
         return fixed4 ( s.Emission, s.Alpha );
      }

      void surf( Input i , inout SurfaceOutput o )
      {
         o.Emission = float4(0,0,0,0).rgb;
         o.Alpha = 1;
      }

      ENDCG
   }
}


ERROR:
ArgumentOutOfRangeException: Argument is out of range.
Parameter name: index
System.Collections.Generic.List`1[AmplifyShaderEditor.TemplateSubShader].get_Item (Int32 index) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Collections.Generic/List.cs:633)
AmplifyShaderEditor.ParentGraph.CreateNewEmptyTemplate (System.String templateGUID) (at Assets/AmplifyShaderEditor/Plugins/Editor/Graphs/ParentGraph.cs:3294)
AmplifyShaderEditor.AmplifyShaderEditorWindow.CreateNewTemplateGraph (System.String templateGUID) (at Assets/AmplifyShaderEditor/Plugins/Editor/Menu/AmplifyShaderEditorWindow.cs:1337)
AmplifyShaderEditor.UIUtils.CreateNewEmptyTemplate (System.String templateGUID, System.String customPath) (at Assets/AmplifyShaderEditor/Plugins/Editor/Utils/UIUtils.cs:2046)
AmplifyShaderEditor.AmplifyShaderEditorWindow.CreateNewTemplateShader (System.String templateGUID) (at Assets/AmplifyShaderEditor/Plugins/Editor/Menu/AmplifyShaderEditorWindow.cs:1100)
AmplifyShaderEditor.TemplateMenuItems.ApplyTemplate7 () (at Assets/AmplifyShaderEditor/Plugins/Editor/Templates/TemplateMenuItems.cs:47)

To be honest the shader by itself works fine, I was just hoping in the future when I needed to edit it I could use Amplify.

Re: add multiple subshaders in one shader using the editor?

PostPosted: Wed Nov 28, 2018 3:30 pm
by Amplify_Borba
Thank you for your feedback, as I've stated in my previous reply we do plan to improve the UI and UX in order to make it more artist friendly.

Templates can be quite overwhelming for users with little to no coding experience and, unfortunately, we don't have the resources to provide support for coding. In any case, I've set up a simple sample for your convenience, to help better understand how to set up multiple sub shaders, you can find it in attachement:

UnlitTemplateSubshaderSample.zip
(1.23 KiB) Downloaded 324 times


This is one of our provided templates, the 'Default Unlit', which can be used as a reference for setting up a specific template, or even as a starting point, like any other template that we provide.

On a sidenote, I've noticed that in the shader code that you've shared you didn't use the necessary shader tags, which are essential for ASE to interpret the templates, allowing it to know where to access the necessary data. The safest bet if you're not comfortable with coding is to use one of the templates that already exists as a base, and build your own effect from there.

If you check the templates that we provide, or the samples provided in the wiki, you can see where they need to be placed. The wiki manual further elaborates on what each tag is responsible for and, depending on the type of template being created, you might have to place additional tags ( ex. Multipass shaders ) or place them in different places ( ex. Properties tag ). In short, its essential to understand the purpose of each tag and when / how to use it when working with templates, its an expected trade-off between ease-of-use and flexibility.

Regarding the sample I've sent, if you open its code and compare it to the original 'Default Unlit' template, you'll notice that all that has changed is the fact that I've duplicated the Subshader section. After saving the code and opening the shader in ASE, you will see that two Output nodes will be present, one for each Subshader:

Image

Since the original Subshader section is set up properly, with all the necessary tags, what happens after duplicating the section is exactly what I've stated in my previous reply, the template accounts for this additional Subshader pass.

From here you can proceed to edit your shader through the ASE canvas.

Please let me know if this helps, we do apologize for the fact that templates still have ways to go in terms of documentation and UI, and we definitely take all feedback into consideration. ASE was for the most part shaped by the suggestions and requests of its community, and we plan to keep it that way!