How can I do a curved world shader?

Node-based Shader Editor

How can I do a curved world shader?

Postby exerion » Tue Aug 29, 2017 5:52 am

Hi =D

I'd like to do a mesh curving shader like I assume they're using in Subway Surfer(see attached image). My camera view is more like that of an RTS game and I would like the curve to make the terrain appear to drop of gradually in the distance.

Can I do this in Amplify?

There is asset on the Unity asset store called Curved World that does what I wan't but I would rather do it in Amplify.
https://www.assetstore.unity3d.com/en/#!/content/26165

Thanks =D
Attachments
8387-Subway_Surfers_3.PNG
8387-Subway_Surfers_3.PNG (242.18 KiB) Viewed 5217 times
exerion
 
Posts: 11
Joined: Tue Aug 29, 2017 5:25 am

Re: How can I do a curved world shader?

Postby Amplify_Borba » Tue Aug 29, 2017 10:04 am

Hello,

Thank you for your interest in Amplify Shader Editor!

It actually depends on the technique you intend to use for that effect, we'll need some additional information in order to further assist you with that.

I'm not too familiar with the Curve World shader package, however, one of our users has successfully used it with ASE and we would be happy to share the details on how to set it up.

Looking forward to your reply!
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: How can I do a curved world shader?

Postby exerion » Wed Aug 30, 2017 12:24 am

Thanks for the reply =D

Technique...hmm I just mostly need to know whether I can move vertices in this manner relative to a camera using ASE.
I've attached some images to illustrate the effect I'd like to achieve.

The following image illustrates what I'm trying to do with shaders from the side. Since the effect we want is quite subtle it could possibly just affect the vertices height to create a curve rather than moving them around a sphere.
Curved.png
Curved.png (29.15 KiB) Viewed 5145 times


This image illustrates the desired effect on a ground plane viewed from the camera's perspective.
CurvedGrid.png
CurvedGrid.png (163.76 KiB) Viewed 5145 times


I think I need to be able to offset the vertices height in world space based on the position of the camera =D
exerion
 
Posts: 11
Joined: Tue Aug 29, 2017 5:25 am

Re: How can I do a curved world shader?

Postby Amplify_Borba » Wed Aug 30, 2017 10:16 am

No worries, glad to be of assistance!

Within what is possible with shaders alone, ASE provides you with the necessary tools to manipulate vertices, although you might have to do some research on how to tackle that as it is not something easy to setup.

Since we're not familiar with Curved World we can't provide any information on their technique, although it seems that you will have to develop a few dedicated scripts ( external to ASE ), in a similar fashion to what they do, if you mean to achieve the exact results.

In case you're interested in a simpler method, I can suggest that you try out our new Shader Templates to create a simple image effect such as a "Fish Eye" effect or a similar camera disortion.

Please 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!
User avatar
Amplify_Borba
 
Posts: 1239
Joined: Mon Jul 24, 2017 9:50 am

Re: How can I do a curved world shader?

Postby exerion » Wed Sep 06, 2017 1:32 am

We can't use image effects as this is for a mobile game, it would be to slow.

We've managed to get something working but because we can only set the vertex positions in local space it does weird things if the object rotates.

In the General settings you can set the Vertex Output to Absolute or Relative but these are both in local space. I need a World option or the ability to supply a World Offset. I need to be able to offset the vertices height in world space.

Anyone? =D
exerion
 
Posts: 11
Joined: Tue Aug 29, 2017 5:25 am

Re: How can I do a curved world shader?

Postby Ricardo Teixeira » Thu Sep 07, 2017 11:49 am

exerion wrote:We can't use image effects as this is for a mobile game, it would be to slow.
We've managed to get something working but because we can only set the vertex positions in local space it does weird things if the object rotates.
In the General settings you can set the Vertex Output to Absolute or Relative but these are both in local space. I need a World option or the ability to supply a World Offset. I need to be able to offset the vertices height in world space.
Anyone? =D


You can apply absolute world space offsets but it really depends on how you built it, without examining a sample I'm not sure what to recommend, it's a tricky effect.

Why not use Curve World?

1. Step one is the inclusion of the curvedworld cginc file. You have to be careful with this inclusions because unity doesn't let you automatically detect where the file is by name, you have to specify the file path. In the following image notice how I added the include with the string: "../cginc/CurvedWorld_Base.cginc" this is because my shader file was in a folder next to the cginc folder where the file is, so the "../" part of the string goes up one folder, the "/cginc/" part looks inside the cginc folder and the last part is the file itself. You could simply use "CurvedWorld_Base.cginc" IF your shader file was next to this file. I hope I made myself clear on this one, this is simply how unity works with shaders, nothing we can do about it :\ If you happen to move the file to a different folder you have to fix the file path and recompile the shader again or else it will fail to include the file.

Image

That is it! Now you can use everything else like you would in a normal ASE shader and it should work in curved world.

Image

As an alternative, you could build your own template.
Found a good bend example here: http://grrava.blogspot.pt/2015/05/bendi ... unity.html

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: How can I do a curved world shader?

Postby exerion » Mon Sep 11, 2017 5:37 am

Hi Ricardo =D

We got it all working thanks to your help. For those who want to do something similar this is how we did it. Note it technically doesn't curve the world around it just lowers the verts at an increasing amount the greater the distance from the CurveSphereTip vector3.

We have made a Amplify Shader Function. I would attach the shader function asset file but it's not permitted. You could make the CurveSphereTip vector3(defines the curve origin) and the CurveMultiplier float(defines how much curve) parameters global so you can control the curve globally rather than having to set it on each material. You can see how this is done in the great link Ricardo posted - http://grrava.blogspot.com.au/2015/05/bending-world-with-unity.html
Function.png
Function.png (132.35 KiB) Viewed 5098 times


Add the shader function to your shader (you may have to restart ASE before you can add it). Set Vertex Output to Absolute.
Abolute.png
Abolute.png (107.95 KiB) Viewed 5098 times


If you didn't make the CurveSphereTip and CurveMultiplier global you can adjust the settings on a material that is using your shader. This is what you can expect to see.
ShaderSettings.png
ShaderSettings.png (86.97 KiB) Viewed 5097 times


Ricardo, we're not sure how to globally disable and enable the effect. We tried to enable/disable the Keyword using Shader.EnableKeyword/DisableKeyword but the checkbox in the material inspector seems to override whatever we do.

When we're ready to reveal our game we'll post some screenshots =D
exerion
 
Posts: 11
Joined: Tue Aug 29, 2017 5:25 am

Re: How can I do a curved world shader?

Postby Ricardo Teixeira » Mon Sep 11, 2017 4:19 pm

exerion wrote:Hi Ricardo =D

We got it all working thanks to your help. For those who want to do something similar this is how we did it. Note it technically doesn't curve the world around it just lowers the verts at an increasing amount the greater the distance from the CurveSphereTip vector3.

We have made a Amplify Shader Function. I would attach the shader function asset file but it's not permitted. You could make the CurveSphereTip vector3(defines the curve origin) and the CurveMultiplier float(defines how much curve) parameters global so you can control the curve globally rather than having to set it on each material. You can see how this is done in the great link Ricardo posted - http://grrava.blogspot.com.au/2015/05/bending-world-with-unity.html
Function.png


Add the shader function to your shader (you may have to restart ASE before you can add it). Set Vertex Output to Absolute.
Abolute.png


If you didn't make the CurveSphereTip and CurveMultiplier global you can adjust the settings on a material that is using your shader. This is what you can expect to see.
ShaderSettings.png


Ricardo, we're not sure how to globally disable and enable the effect. We tried to enable/disable the Keyword using Shader.EnableKeyword/DisableKeyword but the checkbox in the material inspector seems to override whatever we do.

When we're ready to reveal our game we'll post some screenshots =D


That's awesome, happy to know that you got it working with ASE. Great job!

We accept user submissions if you are interested, fully credited.

That's the current expected behavior for the Static Switch node, enabling the Material Property will override disabling it via code. There's an alternative but, unfortunately, we found a small issue while testing it on our side. The Keyword Switch node applies any changes to all shaders but it's missing a key piece of code in the current version, we are going to correct the problem and update ASE as soon as possible.

If you wan't to try it out before the official fix, be sure to manually add multi_compile under the Additional Pragmas parameters in your main shader options(Output Node).

Please note that when using the Keyword Switch node, you will have to reference the Material that's using the shader( e.g. mat.EnableKeyword() ).

Our apologies for the inconvenience. Thank you for your valuable feedback!
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: How can I do a curved world shader?

Postby exerion » Tue Sep 12, 2017 12:53 am

Hey thanks for the reply =D

So if we wanted to create a shader feature that can be enabled/disabled globally, how would we go about it? ie when the player disables 'curve world' in the options menu in our game. It does not seem feasible to iterate over every material in the game and disable the keyword one by one? Isn't this what Shader.Enable/Disable keyword is for?

Thanks =D
exerion
 
Posts: 11
Joined: Tue Aug 29, 2017 5:25 am

Re: How can I do a curved world shader?

Postby Ricardo Teixeira » Tue Sep 12, 2017 9:25 am

exerion wrote:Hey thanks for the reply =D
So if we wanted to create a shader feature that can be enabled/disabled globally, how would we go about it? ie when the player disables 'curve world' in the options menu in our game. It does not seem feasible to iterate over every material in the game and disable the keyword one by one? Isn't this what Shader.Enable/Disable keyword is for?
Thanks =D


You can use the Static Switch node to disable it globally(Shader.Enable/Disable), just keep in mind that Material Properties override it, best to keep them toggled off. The Keyword Switch node should also work as a Global toggle but it does require you to reference one of the materials using the shader, we will let you know as soon as we correct the issues I mentioned earlier.

We recommend using the Static Switch for now.

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

Next

Return to Amplify Shader Editor

Who is online

Users browsing this forum: No registered users and 0 guests