Material Swap: Dedicated Component/Behavior
in progress
Raz
It would be beneficial to have a
dedicated component/state behavior for performing Material Swaps
(changing what material is being used by a specific renderer slot). When working with Avatars, there's a number of good use cases for swapping materials:- Making non-animatable changes to the material's render settings (blending, queue, ZWrite, Stencil, etc.) to swap from opaque to transparent, or to change the behavior of the material
- Changing materials to heavier effects like Grabpass (stealth/distortion effects, slime effects, etc) or Tessellation/Geometry (dissolving into dust etc.), allowing the avatar to stay lighter under conditions where it's not needed
- Large-scale style/texture changes - ex. changing between stylized tonal shading (Liltoon/Silent Crosstone/Poiyomi Shademapping) and more "PBR"-ish shading, like the unity Standard shader. In some cases these can be animated and adjusted at runtime, but often it's unwieldy or not supported without custom shader work
- Completely disabling a material by changing it to a no-op/discard material
However, animating material swaps has some well documented bugs. For example, the fifth slot (element 4) is not changeable by the animation system, and instead modifies the second slot (element 2). This bug was fixed in Unity 2021.2.X [1] but has not yet been backported to the current VRChat Unity Version (fix is in 2019.4.39f1). Additionally, material swapping with WD OFF has strange behavior, requiring tools or debug editing to create a correct mask, and there are sometimes issues with material swaps not being applied properly to all clones [2].
Additionally, any avatar with an animator that has material swap animations will have those materials (and any associated textures) added to the assetbundle whether they're used or not, unnecessarily bloating download size.
As such, having a dedicated component or state behavior that directly changes materials for a given slot could fix and simplify the workflow for changing materials:
- As a component, it would be added to a Renderer GameObject, with slots corresponding to the renderer's slots, populated with the renderer's existing materials. Users would add additional materials for slots to change to, and have an animatable property to change a slot's material away from the default. Animating a numeric field is much more straightforward than animating whole materials, and allows easily changing base and swapped materials without having to re-do animations.
- As a state behavior, it would reference a user-specified Renderer GameObject, and would simply swap a specified material slot on that renderer to a specified material. An option to reset the slot to the originally specified material could be provided. This would be simpler in operation than the component workflow, but would be less flexible.
Additional functionality such as Changing Texture references at runtime [3] could extend the component/behavior to allow for more complex material changes, without requiring a shader to have specific functionality.
---
Log In
Fax
updated the status to
in progress
Thanks for requesting this feature! We're working on something like this. We'll share more info in an upcoming creators roadmap update.
Raz
Slight Correction: The issue with element 2 and 4 primarily occurs when attempting to animate both. Still significant, but slightly different circumstance.
Mysteryem
One of the material swap Unity bugs not directly mentioned here is that masked layers (when the mask has non-empty transforms), prevent material swap animations of all but material slot 0. This becomes a problem when being forced to mask FX layers when using WD OFF with transform animations in the Gesture layer.
Mysteryem
As of a few updates ago to the VRC SDK, this issue can now be worked around by putting the required mask on the top layer of the FX controller and the animations on other layers (previously, the mask on the top layer in FX was ignored). The other layers will inherit the masking from the top layer, but since those layers don't have masks themselves, it avoids the Unity bug preventing material swap animation of all but slot 0.