Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
I want to improve the performance of Variable Mix Shapes
#1
Hello.
I have always used your wonderful assets.

I am using Curvy Generator to generate the following mesh.

[Image: light.dotup.org59848.png]
[Image: light.dotup.org59847.png]

I am dynamically changing the parameters related to this mesh with a script I created, and I Refresh() the Generator to reflect the changes in the Curvy Splines.

Code:
public static void RefreshPathAndShape()
{
    // Step.1: Change the position of the CPs on the path
    ReadOnlyCollection<CurvySplineSegment> cpList = s_splinePath.ControlPointsList;
    int cpCount = cpList.Count;
    for (int i = 0; i < cpCount; i++)
    {
        cpList[i].SetLocalPosition(s_positionBuffer[i]);
    }

    // Step.2: Change the position of CPs on the shape (in A and B)
    ReadOnlyCollection<CurvySplineSegment> aCpList = s_splineShapeA.ControlPointsList;
    ReadOnlyCollection<CurvySplineSegment> bCpList =  s_splineShapeB.ControlPointsList;
    for (int i = 0; i < s_splineShapeACpPositionBufferList.Length; i++)
    {
        aCpList[i].SetLocalPosition(s_splineShapeACpPositionBufferList[i]);
        bCpList[i].SetLocalPosition(s_splineShapeBCpPositionBufferList[i]);
    }

    // Step.3: Change TCB (in A and B)
    s_splineShapeA.Tension = s_aTension;
    s_splineShapeA.Continuity = s_aContinuity;
    s_splineShapeA.Bias = s_aBias;
    s_splineShapeB.Tension = s_bTension;
    s_splineShapeB.Continuity = s_bContinuity;
    s_splineShapeB.Bias = s_bBias;

    // Step.4: Update Generator (Manual)
    s_generator.Refresh();
}

The reason for separating Shape A and Shape B is because Variable Mix Shapes are used.
[Image: light.dotup.org59849.png]

And now, we were doing performance testing and observed an event where the frame rate dropped when the CPs position was changed by processing Step.1.
We used Deep Profiling to check and found that the BuildShapeExtrusion class was the cause of the slowdown.

   
   

I was wondering about the second image, the load caused by ModifierVariableMixShapes.
Indeed, I am using Variable Mix Shapes.
But at this time, I did not change the parameters in Step.2 and Step.3 (they have not changed from the previous values) and the CP positions and TCB values for Shape A and Shape B were exactly the same.
If we comment out the process in Step.2 and Step.3, we still have this load as well.

I feel that if Shape A and Shape B in Variable Mix Shapes have the same parameters, there is no need to run ModifierVariableMixShapes.OnSlotDataRequest().
Hopefully, I can try to improve the frame rate by not executing this.

In transitioning from the first to the second image result, I am unclear as to how this came to be done and would like to investigate more deeply or improve it.
Do you have any suggestions?
Reply
#2
Hi Yanke
Sorry for not answering yet. I should be able to provide an answer in about 12 hours.
Sorry again, and thanks for your patience
Please consider leaving a review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
Reply
#3
Also, what version of Unity do you use?
Please consider leaving a review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
Reply
#4
Sorry, I forgot to mention the version information.

It is as follows
Unity 2022.3.4f1
Curvy Splines 8.7.1
Reply
#5
The Variable Mix Shape module generates a shape for each point of the path. So even if the shapes and mixing parameters are unchanged, changing number and/or position of the path's points means that different shapes should be generated. If you are sure that the generated shapes will stay the same regardless of the changes you apply on the path, then you can do the following changes to avoid the shapes regeneration:
Go to CGDataRequestShapeRasterization, and remove the Equals and GetHashCode methods.
Did this help?
Also, in case you are not aware of it: https://curvyeditor.com/documentation/performancetips/start
If after this you are still not satisfied with the result, please write me again.
Have a nice day
Please consider leaving a review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
Reply
#6
Thank you for your answer!

I have investigated and it seems that the ModifierVariableMixShapes process is executed when the RelativeDistances in CGPath changes.
I will consider rewriting the Curvy Splines code, but I will dig a little deeper to see what I can do about it in my code.
Reply
#7
This matter has been resolved.
I have made changes to the code on the Curvy Splines side and also to be able to control it from my code.

Add the following properties to the CGDataRequestShapeRasterization.

Code:
public static bool IsChangeShape = true;

Add the following at the beginning of Equals() and GetHashCode() in the same class, respectively

Code:
if (!IsChangeShape)
    return base.Equals(obj);
Code:
if (!IsChangeShape)
    return base.GetHashCode();

The above is the code on the Curvy Splines side.
In my code, I do the following processing before Refresh() of Generator and set IsChangeShape to true only when TCB or positions is changed.

Code:
bool isAnyChangePosition = false;
for (int cpIdx = 0; cpIdx < shapeCpCount; cpIdx++)
{
    Vector3 aPos = s_splineShapeACpPositionBufferList[cpIdx];
    Vector3 bPos = s_splineShapeBCpPositionBufferList[cpIdx];

    if (!isAnyChangePosition)
        isAnyChangePosition = aPos != bPos;
}

CGDataRequestShapeRasterization.IsChangeShape =
    s_splineShapeA.Tension != s_splineShapeB.Tension
    || s_splineShapeA.Continuity != s_splineShapeB.Continuity
    || s_splineShapeA.Bias != s_splineShapeB.Bias
    || isAnyChangePosition;

I understand from your response that the different shape need to be updated even though the TCB parameters and CPs locations have not been changed.
Maybe this hack will generate a mesh with a shape that is not strictly correct.

However, in my case this was sufficient.
This technique may only work in my case, but I leave it here as reference information.

I could not have reached this point without your precise answer.
Thank you very much!
Reply
#8
Hi
Glad to know that you solved the issue. Thank you very much for sharing your code with everyone.
Have a great day
Please consider leaving a review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Shapes points orientation itsGama 3 8 01-18-2023, 02:51 PM
Last Post: _Aka_
  Input Spline Shapes from Prefabs destroys graph tairoark 5 7 11-24-2022, 05:08 PM
Last Post: _Aka_
Thumbs Up variable width and branching from main track for racing AdAstra 4 17 08-09-2022, 12:08 PM
Last Post: _Aka_
  Upgrading Unity causes significant performance degradation yanke 3 7 05-23-2022, 03:40 PM
Last Post: _Aka_

Forum Jump: