Hello guys,
I tried to create a Catmull-Rom Spline using VFX Graph but it doesn’t work as I thought. My method is:
Finidng t = ParticleID/TotalParticle.
Apply this function: p(t)=0.5×((2×p1)+(−p0+p2)×t+(2×p0−5×p1+4×p2−p3)×t2+(−p0+3×p1−3×p2+p3)×t3) (p0,p1,p2,p3 are the position which I wanna the line move over)
I tried to create a script to input values into the VFX Graph’s exposed component, but we can’t get the ParticleID. Where did I miss the point that caused this issue?
btw why shadergraph has customfunction but vfxgraph?
But VFXGraph also comes with a SampleBezier Operator. This should allow you to get a nice Bezier interpolation thanks to input Positions.
For this, you just need to give the input Positions and also a 0-1 value which is as you said:
ParticleID / (TotalParticle-1)
From here, you can go a little further and get dynamic Input Positions for your Bezier Sampling.
For this, the easiest road would be to use the provided Multiple Position Binder Script. This allows you to reference GameObjects, and the script gets their position and stores them in a small 2dTexture.
In VFXGraph create an exposed Texture2D property.
name it as you like.
Create an exposed Integer property.
name it as you like.
Select your VFX instance in the scene.
in the Inspector, Add a component
search for the Multiple Position binder script.
Click the Small V icon on the far right of each Property and bind it to your named property.
If the binding is correct, you should a a green square.
Check Every Frame.
Set your Target GameObjects that will be used as Target Position.
Back in VFXGraph, create a Sample AttributeMap Operator.
Use your Texture2D property for the Map and the Int Property for the Point Count.
Make sure that the output of the operator is Vector3. If not change it to Vector3.
Once wired, Right-click on the operator and Select duplicate with Edges three times.
Change the index of the copy so that you have for node with index 0,1,2,3.
Use the Vector3 Output of each node in the Sample Bezier operator.
Now, to finish, you could also use a Subgraph that comes with the Additional sample that can be found in the package manager. Once installed, you’ll be able to find a new Subgraph operator named Sample Multiple Position Map.
This Subgraph has been made to work with the Multiple Position Binder Script and offers some bezier smoothing controls.
Just a quick note, not sure if I’m missing something, but I think the original results were correct for a Catmull-Rom spline.
They are defined by 4 points, same as cubic bezier, but in this case the segment is defined between p1 and p2.
Just different type of splines