How can we improve custom shaders user experience?

(Vladyslav Batyrenko) #1

In this post I’ll try to describe a problem with introducing custom shaders in Amethyst from user’s perspective. I’ll explain how I achieved applying custom shaders in my game Grumpy Visitors. I assume that it’s the only available way to achieve this, according to How to use shaders? and some other discussions I had in Discord while asking around.

My goal was to paint some sprite parts with a custom shader. So that, for example, with applied shader I could turn this image
image
into something like this:
image
image

In order to implement that I had to copy-paste the whole DrawFlat2DDesc and the corresponding plugin with changing only a few parts:

  • the shader itself
  • joining an additional component in order to render only my mage with this pass

This did the job, but then my mage was rendered by two different passes: original DrawFlat2DDesc and my copy-pasted one. In order to workaround that I had to add HiddenPropagate component to my mage, which would exclude the mage from the original pass, and then I had to change my pass to draw even hidden meshes. That’s the only workaround I was able to come up with.

There turned out to be another issue. As I use two sprites for rendering my mage (legs and torso), I also need them to be sorted. Now here is the problem: they are hidden and therefore are not processed by SpriteVisibilitySortingSystem. There were two obvious choices: to copy-paste the system again or to manually sort my legs and torso in the rendering pass. I chose copy-pasting… Any approach would be ugly ):

Summing it up, in order to make this idea working I had to write roughly 600 lines of copy-pasted code incorporating into it some ugly hacks. (For comparison the shader I wanted to use contained ~25 lines.)

I believe Amethyst has plenty of room to enhance user experience in this aspect. Unfortunately I’m here not to propose solutions (due to my lack of knowledge and experience), but I hope I’m bringing up an important topic. I apologize if I missed existing discussions about the issue or if there are already worked out plans to improve this.
I hope my topic will help.

9 Likes