Custom local variable insert Position In Template Shader

Your feedback is very important to us. We are listening.

Custom local variable insert Position In Template Shader

Postby nothingcat » Thu Nov 01, 2018 3:17 am

Hi . I meet a problem when I am using Amplify Shader Editor Template Functions .When I was writing template Shader ,I usually use some calculated results as Input pass to a new Function Code .
When I declared a variable like
Code: Select all
/*ase_local_var*/ float3 tempColor;
.
And It was assigned with pre-calculated color result .
Code: Select all
tempColor = albedo.rgb;

Then it was used to calculate a additional Lighting effect like Snow
Code: Select all
 /*ase_frag_out: Replace Shader Function Here;Float3*/fioat3(0, 0, 0);

And I have to insert code after the line
Code: Select all
tempColor =albedo.rgb
and befor the replace Shader Function line .
And the declare local variable line will add at line /*ase_frag_code:i=VertexOutput*/
So, also ,there are many lines to add additional function , and lots of local variable need to be declared.It's necessary to have a keyword to control where to insert declare local variable line .

To deal with this , if i could use the declared local variable (In this case is : tempColor) instead of the variable (in this case ,the generated variable like float4 temp_cast_0 = (tempColor).xyzx ), I can declare all my local variable at begin and use them at anywhere I like .
nothingcat
 
Posts: 4
Joined: Wed Oct 31, 2018 6:53 am

Re: Custom local variable insert Position In Template Shader

Postby nothingcat » Thu Nov 01, 2018 7:14 am

Copy and paste function in c# script "TemplateLocalVarsNode.cs" .Then get local variable through
Code: Select all
m_localVarsData[ i ].LocalVarName

Directly use it can deal my problem .
nothingcat
 
Posts: 4
Joined: Wed Oct 31, 2018 6:53 am

Re: Custom local variable insert Position In Template Shader

Postby Amplify_Borba » Mon Nov 05, 2018 12:17 pm

Hello, thank you for getting in touch and for your support!

I'm afraid I didn't fully understood your issue, however, creating a tag / block specific for injecting local variables would generate all sorts of issues due to the inter-dependencies between them and the ASE instructions, so it would not be a viable solution for dealing with temporary variables.
You can prevent the generation of temporary variables by using the Swizzle or Break to Components nodes, in order to avoid casting which will generate those.

Regarding your Template Local Var node suggestion, could you please elaborate? That node gives direct access to all the local variables in the template that are preceded by the 'ase_local_var' tag, so that you can use the variables you declare in the template over in the ASE canvas.

If possible, could you provide more information regarding the context for utilizing the Local Var and the issue you're having, also sharing your template and shader so that we can best help you? Apologies for the inconvenience.
Customer Relations at Amplify Creations
Learn more about our offering: Amplify Creations Products
Amplify Shader Editor won the Asset Store Best Tool Award - Thank you for your support!
User avatar
Amplify_Borba
 
Posts: 1239
Joined: Mon Jul 24, 2017 9:50 am

Re: Custom local variable insert Position In Template Shader

Postby nothingcat » Thu Nov 15, 2018 3:42 am

Thanks for your reply.
The shader template like this(in fragment shader )
Code: Select all
/*ase_local_var*/half4 finalRGBA;
               /*ase_local_var*/float ndotl;
               fixed4 _MainTex_var;
               /*ase_local_var*/fixed3 albedo;
               /*ase_local_var*/float3 worldPos;
               /*ase_local_var*/half3 normalLocal;
               /*ase_local_var*/fixed metallic;


               _MainTex_var = tex2D(_MainTex,i.uv0) * _Color;
               albedo = _MainTex_var.rgb;
               worldPos = i.posWorld.xyz;
            #ifdef USE_NORMALMAP
               fixed4 _Normal_var = tex2D(_Normal,i.uv0);
               normalLocal = UnpackNormal(_Normal_var);
            #else
               fixed4 _Normal_var = 1.0;
               normalLocal = half3(0,0,1);
            #endif

            #ifndef NO_MSA
               fixed alpha = _MainTex_var.a;
            #else
               fixed alpha = 1.0;
            #endif

            #if defined(_ALPHATEST_ON)
               clip(alpha - _Cutoff);
            #endif

            #ifndef NO_MSA
               fixed4 control = tex2D(_Control,i.uv0);
            #else
               fixed4 control = fixed4(1.0, _MainTex_var.a, _Normal_var.a, 1.0);
            #endif
               metallic = control.r * metal;
               /*ase_local_var*/fixed smoothness;
               smoothness = control.g * smootha;
               /*ase_local_var*/fixed occlusion;
               occlusion = control.b;
               fixed emission = control.a;

            #if defined(_Raina)
               half rainAmount;
               rainAmount = _Rain * control.a;
               ApplyRain(worldPos, rainAmount, normalLocal, smoothness, metallic);
            #endif

            #if defined(_SNOW)
               /*ase_frag_out:Snow Function Replace Color;Float4*/ fixed4(0, 0, 0, 0) /*end*/;
               //ApplySnow(worldPos, i.normalDir, albedo, normalLocal, metallic, smoothness, occlusion);
            #endif

This is a pbr shader template . with snow effect added . which will use a texture to change the metallic and smoothness , also some other variables .
In here , the function replaced line , I directly use the original local variable name ,as input . and , don't need a temp_cast variable as Input .
The modify node code like this
Code: Select all
protected override void CommonInit(int uniqueId)
        {
            base.CommonInit(uniqueId);
            //AddOutputPort(WirePortDataType.FLOAT, "Example Output Port (Index 0)");
        }
        public override string GenerateShaderForOutput(int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar)
        {
            //foreach(var na in m_dataLabels)
            //{
            //    Debug.Log(na);
            //}
            return m_dataLabels[m_currentDataIdx];
        }


The final generated shader code like this
Code: Select all
   #if defined(_SNOW)
               ApplySnow(worldPos,i.normalDir,albedo,normalLocal,metallic,smoothness,occlusion);
               //ApplySnow(worldPos, i.normalDir, albedo, normalLocal, metallic, smoothness, occlusion);
        #endif
nothingcat
 
Posts: 4
Joined: Wed Oct 31, 2018 6:53 am

Re: Custom local variable insert Position In Template Shader

Postby Amplify_Borba » Thu Nov 15, 2018 10:36 am

Unfortunately, we can't change the code as you've suggested, but we'll try our best to help you sort this issue.

Can you share with us how exactly the ApplySnow(...) is coming up in the final code? Is it through a Custom Expression?
Customer Relations at Amplify Creations
Learn more about our offering: Amplify Creations Products
Amplify Shader Editor won the Asset Store Best Tool Award - Thank you for your support!
User avatar
Amplify_Borba
 
Posts: 1239
Joined: Mon Jul 24, 2017 9:50 am

Re: Custom local variable insert Position In Template Shader

Postby nothingcat » Fri Nov 16, 2018 8:56 am

Em.This issue has been fixed . Use the code I paste in previous reply . I just make a custom node to generate local variable name , to make it work as I expect .Thanks for your attention .
And this software really helps a lot . During development in a support department , shader usually becomes complicated and cant maintain as developer,after many effect was added , and different project want to customize shader. Use this tool to extract the main lighting calculation ,as Template .Then make other common effect like dissolve or snow as node.This will help us to control the size of shader , and deploy a custom shader to varies project . And this tool just work as our team expect , it's very very good!Thanks a lot !!
nothingcat
 
Posts: 4
Joined: Wed Oct 31, 2018 6:53 am

Re: Custom local variable insert Position In Template Shader

Postby Amplify_Borba » Fri Nov 16, 2018 11:23 am

Thank you for the kind words, we're glad to know that you're enjoying ASE and that it has proved helpful in your development pipeline!

We understand that the code shared above has fixed the issue you were having, and we also appreciate that you've shared it with the community. It is, however, a custom solution for a specific situation, since the temporary variables are generated for a reason, which is why we can't simply add it to the package, as it would likely have other repercussions.

We're still going to consider this situation as we further development, so thank you once again for bringing this matter to our attention.
Customer Relations at Amplify Creations
Learn more about our offering: Amplify Creations Products
Amplify Shader Editor won the Asset Store Best Tool Award - Thank you for your support!
User avatar
Amplify_Borba
 
Posts: 1239
Joined: Mon Jul 24, 2017 9:50 am


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 0 guests

cron