Merging shapes

Avatar
  • updated
  • Answered

Hello!

I'm looking for a way in Shapes to merge shapes, especially circles (discs), so that only the outer part of circles when a few of them overlap. Is there a way to do this with Shapes, or would I have to mess with shaders & more to do so?

The idea would be that only circles with the same color merge between each other, or to give an identifier to each disc and that only discs with the same identifier merge together.

I've looked in the documentation for something like this but couldn't find anything that suited me, maybe I missed it ? 😅

If it's not there, would you have any advice on where to start for me to add such feature?

Kind regards,

Louve

Reporting a bug? please specify Unity version:
Reporting a bug? please specify Shapes version:
Reporting a bug? please specify Render Pipeline:
Built-in render pipeline
Pinned replies
Avatar
Freya Holmér
  • Answer
  • Answered

the only way I can think of in Shapes is to use the stencil buffer for this, where you draw two discs for each ring:

First, a disc on the inner radius, that writes a value to the stencil buffer, and is otherwise invisible (set it to additive and make it black, but with alpha = 1)

Second, a disc for the outer radius, with the color you want, with a stencil buffer set to only render when that value is *not* present

inner invisible stencil disc:


outer disc:

looks like this:


note that this will break GPU instancing, so it's not super performant in component mode (though it can be in immediate mode if carefully set up), the more performant solutions are outside the scope of Shapes

Avatar
Freya Holmér
  • Answer
  • Answered

the only way I can think of in Shapes is to use the stencil buffer for this, where you draw two discs for each ring:

First, a disc on the inner radius, that writes a value to the stencil buffer, and is otherwise invisible (set it to additive and make it black, but with alpha = 1)

Second, a disc for the outer radius, with the color you want, with a stencil buffer set to only render when that value is *not* present

inner invisible stencil disc:


outer disc:

looks like this:


note that this will break GPU instancing, so it's not super performant in component mode (though it can be in immediate mode if carefully set up), the more performant solutions are outside the scope of Shapes

Avatar
Louve

Hello,

Thank you very much for your answer :)

I've tried what you suggest and unlike in your screenshot, I get a lot of Z fighting to decide which shape should draw their inner ring regardless.

I end up with either this:

or this

depending on my camera angle.


I've created two Shapes objects (discs) for each range I was testing, so 4 in total. They're on the exact same spot Y-wise, but slightly shifted apart on the X/Z axis as you can see.



Did I do something wrong, or am I missing something?


Warm regards,

Louve

Avatar
Louve

Hello,

Sorry for the very quick update.

All issues fixed by giving a -1 sorting order to the inner, black disc and by setting the outer red circle to Transparent instead of linear dodge ♥

Have an excellent day!

Louve