So lets say I have a sprite. I use this sprite in a spriterenderer of some object and give the renderer a certain material that uses a shader of mine. Now when I place this in the editor, its distorted, the vertices are not placed correctly apparently. As soon as I duplicate the object though, the same sprite now gets used twice in the material, which results in the shader working correctly. I have no idea why this happens, could it be some tag? Here are some screenshots:
This is when I duplicate the object. It works suddenly.
Below are my tags and stuff for the shader:
Tags { “Queue”=“Transparent”
“IgnoreProjector”=“True”
“RenderType”=“Transparent”
“PreviewType”=“Plane”
“CanUseSpriteAtlas”=“True”
}
LOD 100
Cull Off
Lighting Off
ZWrite Off
Fog { Mode Off }
Blend SrcAlpha OneMinusSrcAlpha
I suspect this is another case of batching causing confusion.
When Unity batches meshes (including sprites) their vertex positions are pre-transformed into world space. A mesh by itself, those vertex positions are in local mesh space. I don’t use sprites myself, but it would seem this is true for a single sprite as well.
Try changing the float4 newV line to: float4 newV = mul(unity_ObjectToWorld, v.vertex);
And the o.vertex = line to: o.vertex = mul(UNITY_MATRIX_VP, newV);
I am having the same problem, but I’m using shadergraph and I don’t understand the code generated from the master node at all. My very ugly solution now is to create an extra game object with the same sprite and material and set scale to 0. It works unless you zoom very close to the sprite. Any help would be appreciated.