decentraland / unity-renderer

Unity implementation of Decentraland Client
https://play.decentraland.org
Apache License 2.0
136 stars 93 forks source link

Spike: Improving the Avatar Toon Shader #4893

Closed eordano closed 1 year ago

eordano commented 1 year ago

We should look into the feasibility of the Toon Shader -- it looks like we could have many performance wins from a rewrite of this system. Not convinced of the dynanic atlassing approach, as it would require creating new textures, but we are anyways allocating new meshes.

From the technical review:

===

Even though the game uses simple toon shading for its characters, the avatar shader itself is 20k lines long and uses 12 textures as inputs. The length stems from the fact that the shader was created with a shader graph in the past, but this was eventually abandoned and the team continued to use the compiled shader graph code as the main shader. This makes the shader extremely difficult to maintain, understand, and reason about.

In Decentraland, player avatars are highly customizable. To reduce rendering complexity the current implementation merges the sub-meshes of the player avatars into a single mesh which is then rendered using the toon shader. To be able to support the high amount of custom body parts and wearables the shader is then provided with up to 12 textures to sample from. Due to the nature of execution on GPUs, all 12 textures will always be sampled from, regardless if anything is actually bound to them.

As this is such an important part of the game, there are multiple steps we could take to make this shader more performant and future-proof:

aixaCode commented 1 year ago

Closing, moved into shape up