Add Pass to Standard Shader

Node-based Shader Editor

Add Pass to Standard Shader

Postby Rob_Positomic » Thu Mar 01, 2018 6:11 am

Hi all,

I have been able to combine the Curved World Asset with ASE and get it to work. However, I need the Curved World vertex offset to apply after the surface shading occurs.I believe I need to add a new Pass to the Shader for this; and to make sure that I can still edit in ASE; this should be done using a template.

I'm curious to confirm this is the right approach, and if anyone has done something similar - or can give me a rough guide as to what I need to do to pull this together.
Rob_Positomic
 
Posts: 5
Joined: Fri Jan 19, 2018 2:05 am

Re: Add Pass to Standard Shader

Postby Ricardo Teixeira » Thu Mar 01, 2018 12:49 pm

Rob_Positomic wrote:Hi all,

I have been able to combine the Curved World Asset with ASE and get it to work. However, I need the Curved World vertex offset to apply after the surface shading occurs.I believe I need to add a new Pass to the Shader for this; and to make sure that I can still edit in ASE; this should be done using a template.
I'm curious to confirm this is the right approach, and if anyone has done something similar - or can give me a rough guide as to what I need to do to pull this together.


Hello Rob,

Thank you for getting in touch, we would be happy to help!

I must admit that I'm not entirely familiar with Curved World, or its specific requirements, but our users seem to be using it without a custom template. Are you looking to implement a specific feature or technique that we should be aware of?

If you are comfortable with shader programming, a template is the most flexible solution; in the end it really depends on your specific requirements.

You can use Curve World by adding its cginc and using a simple custom expression, check the link bellow for additional information.

Curve World Shaders with ASE

Multi-pass support, along with relevant template samples, will be available soon.

Looking forward to your reply!
Sales & 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
Ricardo Teixeira
 
Posts: 954
Joined: Fri Aug 09, 2013 2:26 pm

Re: Add Pass to Standard Shader

Postby Rob_Positomic » Sun Mar 04, 2018 5:49 am

Thanks Ricardo,

I'm not very proficient with shaders; but from what I understand, Curved World is a vertex shader which manipulates the position of mesh vertices so that the meshes "curve over a horizon" the further they are from the viewer. I have already been able to implement using the instructions given. This results in the vertex being manipulated before the surface shading is applied - this is probably fine for 99% of use cases.

In my case, the problem is that I have built a terrain shader which looks at the height of a vertex to determine if it should apply a 'land' or 'water' texture. Because the vertex offset calculation is applied prior to the surface shader logic, this results in a bug where underwater textures are being applied and visible on the sides of mountains the distance.

I think that when multi-pass support is available, and the templates as examples are available, that should help me to fix my problem :) Looking forward to it.
Rob_Positomic
 
Posts: 5
Joined: Fri Jan 19, 2018 2:05 am

Re: Add Pass to Standard Shader

Postby Ricardo Teixeira » Mon Mar 05, 2018 4:12 pm

Rob_Positomic wrote:Thanks Ricardo,

I'm not very proficient with shaders; but from what I understand, Curved World is a vertex shader which manipulates the position of mesh vertices so that the meshes "curve over a horizon" the further they are from the viewer. I have already been able to implement using the instructions given. This results in the vertex being manipulated before the surface shading is applied - this is probably fine for 99% of use cases.

In my case, the problem is that I have built a terrain shader which looks at the height of a vertex to determine if it should apply a 'land' or 'water' texture. Because the vertex offset calculation is applied prior to the surface shader logic, this results in a bug where underwater textures are being applied and visible on the sides of mountains the distance.

I think that when multi-pass support is available, and the templates as examples are available, that should help me to fix my problem :) Looking forward to it.


Hello,

I wish I had some additional information to add but, as I mentioned, I'm not too familiar with all the Curve World requirements.

Can you share your shader for further examination on our side?

I'll keep you posted on any multi-pass related developments.

Thanks!
Sales & 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
Ricardo Teixeira
 
Posts: 954
Joined: Fri Aug 09, 2013 2:26 pm

Re: Add Pass to Standard Shader

Postby Rob_Positomic » Wed Mar 07, 2018 12:23 pm

A bit hard to post the entire shader, but this is the main part.

The bottom section "slope exposure" is at the end of the land based texture calculations. The top section "water level.." figures out what sort of texture to apply to a mesh when the height is roughly around or below 0. And will override anything come out of the land area in that case. As you can see I have configured the CurvedWorldShader as per the instructions on your site

TerrainShader.png
TerrainShader.png (238.64 KiB) Viewed 3733 times


Here is the outcome; when we're up close - without any curved world bending occurring; the beachline is at the appropriate height (note its position comparative to the trees)
Mountain-Close.png
Mountain-Close.png (223.61 KiB) Viewed 3733 times


However, as we draw backwards; the beachline "rises" up the mountain, as the Curved World Shader starts to manipulate the vertices:
Mountain-Distant.png
Mountain-Distant.png (167.98 KiB) Viewed 3733 times


The code generated by ASE applies the Curved World function ("vertexDataFunc") in the "v2f"; and then afterwards the surface shading ("surf") in the frag function. I understand that this is the appropriate order of operations for a shader, so not disputing that at all. I believe I need to take the "vertexDataFunc" and all its related code out of the first pass, and add it into a second pass to get the effect I'm after.

However if there's another way; Id be glad to hear it :)


Code: Select all
         v2f vert( appdata_full v )
         {
            v2f o;
            UNITY_SETUP_INSTANCE_ID( v );
            UNITY_INITIALIZE_OUTPUT( v2f, o );
            UNITY_TRANSFER_INSTANCE_ID( v, o );
            Input customInputData;
            vertexDataFunc( v, customInputData );
            float3 worldPos = mul( unity_ObjectToWorld, v.vertex ).xyz;
            fixed3 worldNormal = UnityObjectToWorldNormal( v.normal );
            o.worldNormal = worldNormal;
            o.customPack1.xy = customInputData.uv_texcoord;
            o.customPack1.xy = v.texcoord;
            o.worldPos = worldPos;
            TRANSFER_SHADOW_CASTER_NORMALOFFSET( o )
            return o;
         }
         fixed4 frag( v2f IN
         #if !defined( CAN_SKIP_VPOS )
         , UNITY_VPOS_TYPE vpos : VPOS
         #endif
         ) : SV_Target
         {
            UNITY_SETUP_INSTANCE_ID( IN );
            Input surfIN;
            UNITY_INITIALIZE_OUTPUT( Input, surfIN );
            surfIN.uv_texcoord = IN.customPack1.xy;
            float3 worldPos = IN.worldPos;
            fixed3 worldViewDir = normalize( UnityWorldSpaceViewDir( worldPos ) );
            surfIN.worldPos = worldPos;
            surfIN.worldNormal = IN.worldNormal;
            SurfaceOutputStandard o;
            UNITY_INITIALIZE_OUTPUT( SurfaceOutputStandard, o )
            surf( surfIN, o );
            #if defined( CAN_SKIP_VPOS )
            float2 vpos = IN.pos;
            #endif
            SHADOW_CASTER_FRAGMENT( IN )
         }
Rob_Positomic
 
Posts: 5
Joined: Fri Jan 19, 2018 2:05 am

Re: Add Pass to Standard Shader

Postby Ricardo Teixeira » Wed Mar 07, 2018 1:09 pm

Greetings,

Thank you for the additional information, I really appreciate it.

Unfortunately, I'm a bit overloaded at the moment; I will have to examine the Curve world package in order to determine how they handle this type of situations. Is there any chance you can share your actual shader via PM?

Thanks!
Sales & 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
Ricardo Teixeira
 
Posts: 954
Joined: Fri Aug 09, 2013 2:26 pm


Return to Amplify Shader Editor

Who is online

Users browsing this forum: No registered users and 77 guests