LWRP Multi-Pass Shader

Node-based Shader Editor

LWRP Multi-Pass Shader

Postby McGunn » Wed Jan 30, 2019 4:43 am

Hi, I recently purchased Amplify Shader editor due to the Lightweight Render Pipeline Support.
I've had some luck creating a few things, but I've been stuck for a long time on one major issue.

I'm trying to create an Xray shader, something similar to the following:
Image

Creating the effect where the object is visible when behind geometry is quite easy, you just switch the ZTest Mode to Greater.

However where I'm running into an issue is getting the shader to do both regular drawing of the object, as well as the unlit color when the Ztest is Great then (behind geometry)

I've tried to use Additional Use Passes.
And I've also tried adding extra passes to the template, and even extra subshaders. All to no avail. I'm wondering if perhaps this is not supported yet in LWRP, or if I may be missing something. Thanks.
McGunn
 
Posts: 6
Joined: Wed Jan 30, 2019 4:36 am

Re: LWRP Multi-Pass Shader

Postby Amplify_Borba » Thu Jan 31, 2019 2:45 pm

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

There could be several ways of achieving a X-Ray effect, and we do offer a sample which you can find in the AmplifyShaderEditor \ Examples \ Official \ XRay samples which shows one particular way of doing so, have you had the chance to check it out?

However where I'm running into an issue is getting the shader to do both regular drawing of the object, as well as the unlit color when the Ztest is Great then (behind geometry)


I'll need you to elaborate on this, as I didn't fully understand in which conditions you would have the X-Ray and the regular render to show. The more details you provide regarding your intended implementation and final result, the better we can help!
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: LWRP Multi-Pass Shader

Postby McGunn » Thu Jan 31, 2019 10:28 pm

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

There could be several ways of achieving a X-Ray effect, and we do offer a sample which you can find in the AmplifyShaderEditor \ Examples \ Official \ XRay samples which shows one particular way of doing so, have you had the chance to check it out?

However where I'm running into an issue is getting the shader to do both regular drawing of the object, as well as the unlit color when the Ztest is Great then (behind geometry)


I'll need you to elaborate on this, as I didn't fully understand in which conditions you would have the X-Ray and the regular render to show. The more details you provide regarding your intended implementation and final result, the better we can help!


Hi. Yes I tried to change the XRay sample into the LWRP Template, but it did not function. When I hook the nodes back up the LWRP template has a Vertex Position and Vertex Normal, and the template that the XRay example used had Local Vertex Position and Local Vertex Normal. I'm not sure if this is where the issue arises.

To elaborate on what I said: I'm trying to get the LWRP Shader to run 2 passes. One for when it is behind other geometry, and one for when it is not. I've seen this done by drawing the object as a single color with ZTest Greater, and then in a second pass drawing the object normally.

It's the thing being discussed in this Unity Forum Thread: https://forum.unity.com/threads/render-object-behind-others-with-ztest-greater-but-ignore-self.429493/
McGunn
 
Posts: 6
Joined: Wed Jan 30, 2019 4:36 am

Re: LWRP Multi-Pass Shader

Postby Amplify_Borba » Fri Feb 01, 2019 4:28 pm

It won't be an easy task to convert the XRay sample to LW, especially since the Outline node, which creates a separate pass for the effect, does not support Unity's SRP. I've registered this situation for the developer to consider, hopefully we'll be able to update the node sometime in the future to support SRP.

For this reason, you'll have to create your own logic for the outline or an alternate effect to use, and manually add the pass yourself to the shader template, more information on how to achieve this can be found in our wiki manual.
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: LWRP Multi-Pass Shader

Postby McGunn » Fri Feb 01, 2019 11:51 pm

Amplify_Borba wrote:It won't be an easy task to convert the XRay sample to LW, especially since the Outline node, which creates a separate pass for the effect, does not support Unity's SRP. I've registered this situation for the developer to consider, hopefully we'll be able to update the node sometime in the future to support SRP.

For this reason, you'll have to create your own logic for the outline or an alternate effect to use, and manually add the pass yourself to the shader template, more information on how to achieve this can be found in our wiki manual.


I have tried adding the second pass using that wiki page as a reference, and to no avail. If I remember correctly it only rendered one of the two passes. I'll try again and post my results in detail here soon.
McGunn
 
Posts: 6
Joined: Wed Jan 30, 2019 4:36 am

Re: LWRP Multi-Pass Shader

Postby McGunn » Sat Feb 02, 2019 2:32 am

Okay so what's happening is that Unity is only rendering the first pass (Pass 0), and the second pass seems to not render at all.

This is my shader graph:
Image

And this is my multipass LWRP template that I made following the wiki as a guide:
https://www.dropbox.com/s/s8fukg91ean9r2a/LightWeightSRPPBR_MultiPass.shader?dl=0
McGunn
 
Posts: 6
Joined: Wed Jan 30, 2019 4:36 am

Re: LWRP Multi-Pass Shader

Postby Amplify_Borba » Mon Feb 04, 2019 3:47 pm

Hey there, there are a few considerations to make in regards to the template you've shared, I'll try to be thorough as possible.

The first pass to be declared must be the Outline pass, and you'll need to pay attention to the ports that are being declared to ensure if they need to be linked or not to the other passes. The reason why they are hidden is because they are currently linked, which is also why the Color Port only assumes the value of the first pass.

You must also need to add the Cull Mode identifier to the new pass that you create, as per the following example:

( ... )
Tags{"LightMode" = "LightweightForward"}
Name "Xray"

Cull Front
Blend One Zero
ZWrite Off
ZTest LEqual
Offset 0,0
ColorMask RGBA
/*ase_stencil*/
( ... )

Then, the Vertex Normal port should be removed, since it won't be used for this specific effect:

( ... )
GraphVertexOutput vert (GraphVertexInput v/*ase_vert_input*/)
{
GraphVertexOutput o = (GraphVertexOutput)0;
UNITY_SETUP_INSTANCE_ID(v);
UNITY_TRANSFER_INSTANCE_ID(v, o);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
/*ase_vert_code:v=GraphVertexInput;o=GraphVertexOutput*/
v.vertex.xyz += /*ase_vert_out:Vertex Offset;Float3;3;-1;_Vertex*/ float3( 0, 0, 0 ) /*end*/;
v.ase_normal = /*ase_vert_out:Vertex Normal;Float3;4;-1;_Normal*/ v.ase_normal /*end*/;
o.position = TransformObjectToHClip(v.vertex.xyz);
return o;
}
( ... )

The Vertex Offset port needs to have its linking property removed, so it's not linked to other passes:

Before: v.vertex.xyz += /*ase_vert_out:Vertex Offset;Float3;3;-1;_Vertex*/ float3( 0, 0, 0 ) /*end*/;

After: v.vertex.xyz += /*ase_vert_out:Vertex Offset;Float3;3;-1;*/ float3( 0, 0, 0 ) /*end*/;

Lastly, you should also unlink the Alpha and Alpha Clip ports in the same manner:

( ... )
half4 frag (GraphVertexOutput IN /*ase_frag_input*/) : SV_Target
{
UNITY_SETUP_INSTANCE_ID(IN);
/*ase_frag_code:IN=GraphVertexOutput*/
float3 Color = /*ase_frag_out:Color;Float3;0*/float3(1,1,1)/*end*/;
float Alpha = /*ase_frag_out:Alpha;Float;1;-1;_Alpha*/1/*end*/;
float AlphaClipThreshold = /*ase_frag_out:Alpha Clip Threshold;Float;2;-1;_AlphaClip*/0/*end*/;
#if _AlphaClip
clip(Alpha - AlphaClipThreshold);
#endif
return half4(Color, Alpha);
}
ENDHLSL
( ... )

Here's a brief explanation of the tags, for reference:

float AlphaClipThreshold = /*ase_frag_out:Alpha Clip Threshold;Float;2;-1;_AlphaClip*/0/*end*/;

- ase_frag_out is the ASE Tag
- Alpha Clip Threshold is the Port Name
- Float is the Port Type
- 1 is the Port identifier
- -1 is the default order for the ports, meaning that they'll be ordered in the same order as they are declared in the template
- _AlphaClip is the linking property for Multi-Pass

With the changes suggested above the template should be working as expected, hope that this helps!
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: LWRP Multi-Pass Shader

Postby McGunn » Tue Feb 05, 2019 12:15 am

Hi, thank you for all your help so far.

I've done what you suggested in the shader template and it still doesn't seem to ever draw the second pass. (Pass 1)

I've put the template shader, the shader, and a material using the shader in a UnityPackage:
https://drive.google.com/open?id=1LYpkNcN417k5W5gXpB7lRTEpoph-xpkd

The result is that the object draws pass 0 when behind geometry, as it should. But it does not draw it's normal base pass.
Image


This is what the graph looks like:
Image



And just to clarify the look I'm going for is exactly that of Super Mario Sunshine when the character is occluded as seen here:
Image
McGunn
 
Posts: 6
Joined: Wed Jan 30, 2019 4:36 am

Re: LWRP Multi-Pass Shader

Postby Amplify_Borba » Tue Feb 05, 2019 4:20 pm

Thank you for the sample, I've escalated this matter to the developer as a potential issue as I've been unable to identify the problem, we'll be sure to get back in touch as soon as we have any findings to share.
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: LWRP Multi-Pass Shader

Postby McGunn » Tue Feb 05, 2019 11:20 pm

Amplify_Borba wrote:Thank you for the sample, I've escalated this matter to the developer as a potential issue as I've been unable to identify the problem, we'll be sure to get back in touch as soon as we have any findings to share.

Thank you very much.
McGunn
 
Posts: 6
Joined: Wed Jan 30, 2019 4:36 am

Next

Return to Amplify Shader Editor

Who is online

Users browsing this forum: No registered users and 10 guests