Search Unity

Dissolve shader for complex objects

Discussion in 'General Graphics' started by interpol_kun, Dec 21, 2020.

  1. interpol_kun

    interpol_kun

    Joined:
    Jul 28, 2016
    Posts:
    134
    Recently I got an interesting assignment which happens to be in Unity. I had to create the dissolve shader for a complex UI object (to be specific it's a card with multiple images, text objects (TextMeshPro) and panels).

    I had no problem writing custom script and shader for a single object, that's simple. But when it comes to a complex hierarchy, It's not that easy.

    I have to inform that I am using Legacy RP and plain ShaderLab.

    I tried to use masks. Well, I had to write a new class (CustomImage), which inherits Image component and overrides GetModifiedMaterial property (got that from this tutorial). To keep shader updating every frame, I have to trigger GetModifiedMaterial manually, by reassigning the CustomImage material every frame. That solution works, but, because it's still a mask, I loose all my fancy effects (dissolve smoothing and edge colors) and only get the basic dissolve silhouette.

    Assigning dissolve material to all children won't work either. Hard to replace TMP shaders and keep noise texture stretching across the board.

    Now I am really baffled. Because I see that CanvasGroup component, which can control all the children and root object, doesn't provide any useful functionality besides that (but I feel that it can). I thought about stencil buffer and other stuff. I mean, they did it for Hearthstone somehow...

    Here's the sample picture of the hacky masked dissolve which I applied on a prototype object (I picked some colours to distinguish the objects). As you can see, only white Image has the coloured border effect (fire), children just being masked out (which is the obvious way, mask does what it should). So mask is not suitable for the problem.

    So, any ideas how I can create a dissolve effect, which will dissolve my entire Card object, preserving all the effects I have on my shader?

    upload_2020-12-21_19-54-16.png