Enabling multiple materials on canvas renderer
I need to apply multiple shader effects to the UI image. To do this I decided to capitalise on the CanvasRenderer's multiple materials support and created this script:
public class MaterialImage : RawImage
{
public Texture2D tex;
public Material[] materials;
protected override void UpdateMaterial()
{
canvasRenderer.materialCount = materials.Length;
for (int index = 0; index < materials.Length; index++) {
canvasRenderer.SetMaterial(materials[index], index);
}
canvasRenderer.SetTexture(tex);
}
}
Although, this applyes only one material, the first one in the array. The questions are:
1. How to make multiple materials work with the Canvas Renderer?
2. Are there better ways to apply multiple shaders to the UI image?
Thanks in advance!
Answer by Lex_87 · Aug 24, 2017 at 12:40 PM
Hello!
It seems multiple materials are something about material per submesh. But I try to implement several submesh per CanvasRenderer holder and it looks wrong. I have the first submesh visible only.
Anybody knows what am I doing wrong?
Answer by Yiming075 · Feb 05 at 03:45 AM
Since the mesh is drawn at once. So it is impossible to have multiple materials on a single UI.
Your answer
![](https://koobas.hobune.stream/wayback/20220612130926im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Material.SetFloat not working 0 Answers
Tint a UI sprite with a gradient 0 Answers
sprites / diffuse does not support rectmask 1 Answer
Can I make a dynamic wave ui with shader ? 0 Answers
Applying a UI-Overlay-Shader on a Canvas. Problems! 0 Answers