GPU instancing does not work when drawing Polyline repeatedly in Immediate mode

Avatar
  • updated

Use a class that extends the ImmediateModeShapeDrawer class.

using( Draw.Command( cam ) ) {
    Color tmpCenter = new Color(0 / 255f, 85 / 255f, 46 / 255f, 1.0f);
    Color tmpBothEnd = new Color(62 / 255f, 179 / 255f, 112 / 255f, 1.0f);
    Color tmpUnitColor = (tmpBothEnd - tmpCenter) / 10;

    Draw.LineGeometry = LineGeometry.Billboard;

    using (PolylinePath p = new PolylinePath())
    {
        p.AddPoints(polylineVts); // polylineVts is Vector3[]

        for (int i = 0; i < 10; i++)
        {
            Draw.Polyline(
                path: p
                , thickness: 1.0f / (i + 1)
                , closed: false
                , color: tmpBothEnd - (tmpUnitColor * i)
            );
        }
    }
}

In order to implement a pseudo-gradient in the horizontal direction of the Polyline, the same Polyline is drawn many times in the same frame with only the thickness and color changed.
From reading the documentation, I am aware that the above code can be drawn without regenerating the mesh.

However, in reality, changing the number of loops increases the number of SetPass calls.
When I look at the IM Monitor, it shows "1 polygon/polyline path assets", so it appears to be recognized as a single Polyline from the Shapes perspective.

(Perhaps I am not understanding you well enough)

Perhaps this kind of usage is not expected, but could you please enlighten us?

Reporting a bug? please specify Unity version:
2020.3.22f1
Reporting a bug? please specify Shapes version:
4.1.3
Reporting a bug? please specify Render Pipeline:
Built-in render pipeline
Avatar
ushui

Changing to Simple joins enabled GPU instancing and reduced SetPass calls!

This is enough for my case. Thank you very much.

We look forward to a big polyline update.

Please take care of your health.

Avatar
Freya Holmér creator

GPU instancing for polylines only works when using Miter or Simple joins - the other join types break instancing.

This is something I hope to fix for the next big polyline update, though unfortunately it's probably pretty far aways away at the moment as I'm all wrapped up in other projects at the moment!