Shader macro?

Node-based Shader Editor
Post Reply
Rokki
Posts: 5
Joined: Sun Mar 25, 2018 9:33 am

Shader macro?

Post by Rokki »

Hi,
How do I use the Shader macro? Custom expression?
Will ASE generate the following code:
             Struct v2f
             {
                 V2F_SHADOW_CASTER;
             };
             V2f vert( appdata_base v)
             {
                 V2f o;
                 TRANSFER_SHADOW_CASTER_NORMALOFFSET(o)
                 Return o;
             }
             Float4 frag(v2f i):SV_Target
             {
                 SHADOW_CASTER_FRAGMENT(i)
             }



Thanks.
User avatar
Amplify_Borba
Posts: 1239
Joined: Mon Jul 24, 2017 9:50 am

Re: Shader macro?

Post by Amplify_Borba »

Hey there, thank you for getting in touch!

You may use Macros with the Custom Expression node in Call Mode, which is set in the node parameters.

I'm afraid that I don't fully understand your next question, as you've posted code for a vertex frag shader, which goes into Shader Templates territory. Could you provide further details in order for us to best help you?
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!
Rokki
Posts: 5
Joined: Sun Mar 25, 2018 9:33 am

Re: Shader macro?

Post by Rokki »

Amplify_Borba wrote:Hey there, thank you for getting in touch!

You may use Macros with the Custom Expression node in Call Mode, which is set in the node parameters.

I'm afraid that I don't fully understand your next question, as you've posted code for a vertex frag shader, which goes into Shader Templates territory. Could you provide further details in order for us to best help you?



Thank you for your reply.

The code is obtained from here:
https://docs.unity3d.com/Manual/SL-Vert ... mples.html
Shader name is "Lit/Shadow Casting".

In Frag Shader,What I Need is:
fixed4 frag (v2f i) : SV_Target
{
SHADOW_CASTER_FRAGMENT(i)
}

So I modified the template like this:
fixed4 frag (v2f i /*ase_frag_input*/) : SV_Target
{
/*ase_frag_code:i=v2f*/

/*ase_frag_out:TestFragOutput;Float4*//*end*/
}
and I used Custom Expression with call mode.

finally,I got this:
fixed4 frag (v2f i ) : SV_Target
{
float localMyCustomExpression2 = ( 0 );
SHADOW_CASTER_FRAGMENT(i)
float4 temp_cast_0 = (localMyCustomExpression2).xxxx;
temp_cast_0
}

How do I output the exact expression directly, is there any other way or technique?
User avatar
Amplify_Borba
Posts: 1239
Joined: Mon Jul 24, 2017 9:50 am

Re: Shader macro?

Post by Amplify_Borba »

Thank you for providing additional details.

Just for clarification, while macros should function correctly through custom expression nodes, the parse that is done to their code might have some caveats which would have to be investigated on a case by case basis. You'll have to specify which macro that you've tried using is causing an unexpected behavior and send us the template file that you're using, so that we can test and correct it on our side.

I'm sharing a template that, despite having multiple empty passes, provides support for the Light Attenuation node so that you won't have to use that macro specifically.
MultiPassHair.zip
(1.31 KiB) Downloaded 272 times
Feel free to check it out and let me know if you have any further questions, thanks!
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!
Rokki
Posts: 5
Joined: Sun Mar 25, 2018 9:33 am

Re: Shader macro?

Post by Rokki »

Thank you so much.
My template was simply modified from unlit, and it has not yet been completed.
Thank you for your template file.
User avatar
Amplify_Borba
Posts: 1239
Joined: Mon Jul 24, 2017 9:50 am

Re: Shader macro?

Post by Amplify_Borba »

No problem, glad to have helped!

Please let me know if you have any follow-up questions, thanks!
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!
Post Reply