- Home /
How to change Rendering Mode of Shader during run-time?
Hi Friends,
I would like to swap a material's rendering mode from Opaque to Transparent.
I found the following script in forums, but doesn't seem to work on run-time.Once we stop playing, it gets changed... but not during playmode. How to make it during run-time???
Material m = new Material(Shader.Find("Standard")); m.SetFloat("_Mode", 2); m.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.SrcAlpha); m.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha); m.SetInt("_ZWrite", 0); m.DisableKeyword("_ALPHATEST_ON"); m.EnableKeyword("_ALPHABLEND_ON"); m.DisableKeyword("_ALPHAPREMULTIPLY_ON"); m.renderQueue = 3000;
thanks, Jeeva
Answer by Jeeva3m · Feb 03, 2016 at 07:27 AM
Friends, instead of swapping the render mode of a shader, I just changed the shader itself from standard to Transparent/VertexLit with X. And now i could play with transparent settings, alpha levels and changing material color very well during run-time.
Replying to this old post, because I have for a week now tried to do this. $$anonymous$$y goal was to set opaque objects transparency during runtime, but fade rendering mode had an issue that alpha 1 wasn't solid. Despite googling every possible thread about how to change rendering mode during runtime, nothing worked (I'm very aware of keywords).
Then I came across this answer, and I truly believe, that this is only way to actually achieve this. Hopefully others having this issue can find this post too.