RzFX Flow trail breakdown

Hi everyone!

I`m glad to share a work what I do for fun recently.
It is a flow trail shader in Unity 2018.2.4.
Amplify shader editor 1.5.8 for shader.
Substance designer 2018 for the texture.

Final result.
https://www.youtube.com/watch?v=w7BofLsV6IQ

The shader graph. (Full size link: https://drive.google.com/open?id=1x5fW5yX-r6p6mdbO35OrLzPlvdqmmhDG )

The overview of the shader is included 4 part.

First: Define the main shape what I want for the trail.
Second: The way how to dissolve the shape. So I need a good motion for the mask.
Third : Fill the color.
Final : Optimize the visual. Mask some defect.

Here is the texture made within Substance designer for the shader.
RG: Work for distort the uv and the end of the trail dissolved.
B: The main shape of trail.

The first step.
Do the main motion of trail. And add a little distort noise at uv coordinate for B channel.
There is a tip that is the node “Constant Bias Scale”.
It remap the value of noise from 0~1 to -1~1. As a result, it will keep the distorted trail at the center.
And I multiply the gradient of U coordinate to keep the shape in the start position and more distortion in the end position. As the result, the shape of trail will be more variety.

Dissolve mask.
As the trail moving to the end will be dissolved by the noise from G channel.
In order to keep the initial opacity, it add the gradient of U coordinate.

Color.
To fill the two color from start to end. It is filled full size.
If it multiplied the value of opacity, the pixel which less than 1 goes to black.
So, I created a switch to do the dark edge or not.

Edge mask.
As the value of “Flow Strength” went over, the trail will move over the area.
So, I need a mask making it to be smooth fade out when it over the edge.

That is all.

In fact, there is no more special. But just within some adjustment to make it better.
Please feel free any feedback or idea. Thanks! :grinning:
Enjoy it.

Cheers!

Ryan

70 Likes

thanks for the breakdown! those trails look very cool!

2 Likes

Thank you for you compliment!
It is my pleasure and I`m inspired by you stunning game art tricks.
Cheers!

1 Like

Thanks, it will help a lot in learning.

1 Like

I’m very glad to hear that. Thanks!

Neat trails!

I haven’t used unity particle systems ever (been in proprietary for years), but here is something that might be worth investigating if you are interested.
When building an “Edge Mask”, there are many methods of approach (using texture, using u/v coordinates, using world / local position, distance to a vertex, etc.). Just depends on what your target goal is :slight_smile:
If you wanted a consistent trail falloff no matter the length, then you could do something like this:

Get vertex array[]

Locate the target vertex in the array (the vertex that represents the tip of the tail)
	Example:
		array.count = (get the number of segments)*2 >> find last vertex
        // or depending on how the vertices are appended to the array, it may be array[0] (the first vertex)

Get its position
	Example: 
		vertPosition = GetVertPosition(array[0]); // there should be a method for this

In the fragment shader get distance from Vertex to all pixel positions in world space
    Example:
		gradient = distance((pixel position world space),vertexPosition);

Divide by a value to control final gradient and clamp 
    Example:
		float falloff = 0.5;
		finalGradient = clamp((gradient / falloff), 0.0, 1.0);

I did a quick search in the docs and found a few things that suggests there might be a way to do this in Unity (can’t see why not).

TrailRenderer.GetPosition
Vector3 GetPosition(int index);

TrailRenderer Doc:

3 Likes

I recently started making texture as substance designer.
Your work is helpful to me. Thanks!

1 Like

Thank you for your research!
But Im not expert in scripting. Im just working with node base editor.

good work I like it。

Unity%20trail%20issue

Not sure if this is the right place to drop this, but I didn’t really wanna start a new topic just for this one issue.
I was trying to follow along with what you’ve done here (using unity shader graph so I’ve tried to recreate it as much as I can using similar nodes) but I’ve ran into this issue where the final output material doesn’t move or animate.

But as you can see in the nodes before it those seem to be working just fine.

I’ve tried using 3 different versions of unity (that include shader graph) as well as tried it over 2 different computers but the final result just won’t work. I’m at a loss at this point, so any help would be greatly appreciated

3 Likes

Hey! Looks nice! What shader editor are you using. Or did I miss it? Thx for answering. :slight_smile: @ryanzeng

Thanks!
It is Amplify shader editor.

1 Like

I`m not working with shader graph. I can not sure what is going wrong here.
Do you add the panner value to the B channel? Just like what you done below.

Could you send me the shader graph or more detail snapshot to my mail ( mzranca@gmail.com )?

Thanks for you send me the detail.
I post the result what I remake it within Shader Graph here, and for someone working with Shader graph for reference.
Wish it is helpful.
Cheers.

FlowTrail_ShaderGraph

18 Likes

This is amazing, thank you so much Ryan!!

I’ll definitely sit down and dissect this later tonight.

1 Like

Thank you very much !

1 Like

Awesome breakdown! Not only the exact effect I was trying to make at the moment, but I also learned a few new tricks! For instance I had no idea that you could use UV coordinates as smooth gradient masks… My life is forever changed! Thanks!

1 Like