system
1
Hi,
I want to change blend mode in shader at runtime,
because I don’t want to write many same shaders without blend mode.
I hope that I could change mode passed from material property like this:
Properties {
_BlendMode ("BlendMode", Blend) = (SrcAlpha OneMinusSrcAlpha)
}
Pass {
Blend [_BlendMode]
}
but ‘Blend’ is not supported.
it doesn’t work.
anyway, is there a way to do that?
thank you for reading my poor english.
Setting blend modes by scripting has been possible since 4.3.
On shaderlab add Float properties for the modes:
Properties {
MySrcMode ("SrcMode", Float) = 0
MyDstMode ("DstMode", Float) = 0
}
Pass {
Blend [MySrcMode] [MyDstMode]
}
On script side update the values with Material.SetInt() and BlendMode enums:
material.SetInt ("MySrcMode", UnityEngine.Rendering.BlendMode.SrcAlpha);
material.SetInt ("MyDstMode", UnityEngine.Rendering.BlendMode.Zero);