Many immediately drawn bezier polylines, rotate existing path or create new paths for performance?

Avatar
  • updated
  • Answered

According to the tooltip using Draw.Rotation frequently to set the drawing matrix rotation can be expensive, due to needing to re-calculate the scale.

But I'd like to be able to draw many (potentially dozens) of the same bezier polyline path, but at different locations, scale, and rotations. 

What would be best practice for this situation? Should I rotate while using the same path or make a different path for each polyline? (and break instancing?) Is Draw.Rotate somehow more efficient than Draw.Rotation?

Reporting a bug? please specify Unity version:
2020.3
Reporting a bug? please specify Shapes version:
4.2.1
Reporting a bug? please specify Render Pipeline:
URP
Avatar
Freya Holmér creator
  • Answered

usually the right answer is almost always "test it on your platform", but I'm fairly certain modifying Draw.Matrix and reusing the same polyline will be faster, at least if it's dynamic. changing the shape or coordinates of a polyline can be expensive if done every frame, definitely more expensive than calling Draw.Rotate

  • Reuse the same polyline and modify Draw.Matrix between draw calls if the polyline path has its points/shape change dynamically
  • Use multiple polylines if they never change shape and remain static/drawn with the same transform

    Avatar
    john p kennedy
    Quote from Freya Holmér

    usually the right answer is almost always "test it on your platform", but I'm fairly certain modifying Draw.Matrix and reusing the same polyline will be faster, at least if it's dynamic. changing the shape or coordinates of a polyline can be expensive if done every frame, definitely more expensive than calling Draw.Rotate

    • Reuse the same polyline and modify Draw.Matrix between draw calls if the polyline path has its points/shape change dynamically
    • Use multiple polylines if they never change shape and remain static/drawn with the same transform

      Thank you so much for the fast reply!

      changing the shape or coordinates of a polyline can be expensive if done every frame

      I thought that immediate mode was essentially recreating the lines "from scratch" every frame anyway, and changing path points wouldn't matter too much.

      Avatar
      Freya Holmér creator

      if you cache the PolylinePath object, it won't reconstruct them every frame! the immediate mode documentation has information on that workflow