Page 1 of 1

Shader macro?

PostPosted: Mon Apr 02, 2018 8:32 am
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.

Re: Shader macro?

PostPosted: Mon Apr 02, 2018 4:37 pm
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?

Re: Shader macro?

PostPosted: Tue Apr 03, 2018 1:24 am
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?

Re: Shader macro?

PostPosted: Tue Apr 03, 2018 10:21 am
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.32 KiB) Downloaded 122 times


Feel free to check it out and let me know if you have any further questions, thanks!

Re: Shader macro?

PostPosted: Wed Apr 04, 2018 12:03 am
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.

Re: Shader macro?

PostPosted: Wed Apr 04, 2018 11:12 am
by Amplify_Borba
No problem, glad to have helped!

Please let me know if you have any follow-up questions, thanks!