- Home /
Is it possible to change blend mode in shader at runtime?
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.
Answer by Juho_Oravainen · Jun 11, 2014 at 12:51 PM
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);
Your answer
Follow this Question
Related Questions
Change blend mode from outside shader? 3 Answers
Why is color multiplied with 2 in "Particles/Alpha Blended" shader? 1 Answer
Alpha Blending Problem 0 Answers
Does separate alpha blending in shaders work? 0 Answers
Alpha-test VS Alpha-blend shader 1 Answer