Hi guys, so... I'm trying to learn shaders, and I have some questions about the SpriteRenderer shader. Hope you guys could help me. > SpriteRenderer is a MonoBehaviour that uses the Sprites-Default.shader (okay, this is a fact) > When I, for example, change the Tint property by the SpriteRenderer Inspector, the Shader seems not to be modified, its color still is white. How does Unity does that under the hood? > The same goes with Textures. When I have two separate SpriteRenderers in my scene and I try to change one's texture, it does not affect the other, and they have the same material. How's that possible? Hope you guys can help me. This is killing me. Can't discover on my own. Thanks.
The SpriteRenderer modifies vertex colors, it does not affect the material. https://docs.unity3d.com/ScriptReference/SpriteRenderer-color.html
Great, that makes sense. But what about the textures? How can I set each texture separately without replicating in every object with the same material?
The shader uses PerRendererData flag in front of the the texture property: https://docs.unity3d.com/ScriptReference/MaterialProperty.PropFlags.PerRendererData.html This is another way to pass values to the shader without modifying the material. Is this what you were asking about?
What about when sprites have different meshes? I see that it still only makes a single drawcall. How does that work?
If the Sprites share the same material properties (which includes the source texture), they can be dynamically batched and have the meshes combined per draw to reduce draw calls (https://docs.unity3d.com/Manual/DrawCallBatching.html).