Batching Filled Shapes with a Border

Avatar
  • updated
  • Answered

Hi,

I've got the following use case:

drawing a potentially large quantity of shapes that have both a fill and a border.(think draw.io or visio)

these entities should all have their own zorder so they dont overlap and can be reordered.

since shapes cannot have both a border and fill i have to create two gameobjects.

this breaks batching because the draw order goes fill>border>fill>border

is there some way to draw a filled shape with a border in a single draw call?

(if not would you consider this as a future feature?)


is there some way to batch draw calls in the above mentioned fill>border>fill>border case?

Reporting a bug? please specify Unity version:
Reporting a bug? please specify Shapes version:
Reporting a bug? please specify Render Pipeline:
Pinned replies
Avatar
Freya Holmér creator
  • Answer
  • Answered

ah, right, hm, this seems to be a side effect of how Unity does instancing I suppose :c

it does make sense since render order matters a lot here, and rendering all borders in one instance is just not possible since transparent shaders don't write depth, so I think this is a case that can't be solved without either:

  1. making them opaque and thus use the Z buffer, and then set render order at the top of the inspector to group all borders together, and then offset them by depth
  2. leaving them as is, without instancing
  3. alternatively, I can add a fill color option for hollow rectangles (and rings/any other bordered thing), which, feel free to request that in a separate topic here!
Avatar
Freya Holmér creator
  • Under Review

does changing render order of each game object help instancing the borders in one go?

Avatar

i'm not sure which order you mean

this is the kind of thing i'm trying to accomplish

if i increased the borders sorting layer order i end up with this

i actually just figured out i can batch at least some calls if i use opaque mode instead of transparent(depth buffer?)

i might be able to get away with only using transparent mode for shapes that are not in fact opaque.

if there is some better way to do this that would be fantastic though.

Avatar
Freya Holmér creator
  • Answer
  • Answered

ah, right, hm, this seems to be a side effect of how Unity does instancing I suppose :c

it does make sense since render order matters a lot here, and rendering all borders in one instance is just not possible since transparent shaders don't write depth, so I think this is a case that can't be solved without either:

  1. making them opaque and thus use the Z buffer, and then set render order at the top of the inspector to group all borders together, and then offset them by depth
  2. leaving them as is, without instancing
  3. alternatively, I can add a fill color option for hollow rectangles (and rings/any other bordered thing), which, feel free to request that in a separate topic here!