http://nordicedu.com/tkokblog/wordpress/?tag=perrendererdata
MaterialPropertyBlock and SpriteRenderer
Posted on 10.12.2014
Once again the “Unity-way” supraised me. I made this simple Dissolve shader for sprites. There were many difficulties on a way but the most ambiguous one was releated to SpriteRenderer and MaterialPropertyBlock.
When you do your own shader for sprites and want to use the MaterialPropertyBlock to send some [PerRendererData] you have to use Renderer.GetMaterialPropertyBlock first becouse Unity uses MaterialPropertyBlocks internaly for Sprite rendering and you don’t want to mess it up.
1 2 3 4 5 6 7 8 9 10 11 |
//Inside C# Monobehaviour script materialPropertyBlock.Clear(); sr.GetPropertyBlock(materialPropertyBlock); materialPropertyBlock.AddFloat(dissolvePropertyID, dissolveValue); sr.SetPropertyBlock(materialPropertyBlock); //Inside the shader Properties{ [PerRendererData] _SliceAmount("Slice Amount", Float) = 0.5 [PerRendererData] _MainTex("Sprite Texture", 2D) = "white" {} } |
Posted in Uncategorized | Tagged Material, MaterialPropertyBlock, PerRendererData, Shader, Sprite, SpriteRenderer,