I’m trying to display several Images as billboards. All the Images are under the same Canvas. I’m using a billboard shader I’ve been working on (vertex part, the whole shader is attached):
v2f vert(appdata_t IN)
{
v2f OUT;
UNITY_SETUP_INSTANCE_ID(IN);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(OUT);
// Method 1
/*
float scaleX = length(mul(unity_ObjectToWorld, float4(1.0, 0.0, 0.0, 0.0)));
float scaleY = length(mul(unity_ObjectToWorld, float4(0.0, 1.0, 0.0, 0.0)));
OUT.vertex = mul(
UNITY_MATRIX_P,
float4(UnityObjectToViewPos(float3(0, 0, 0)), 1) + float4(IN.vertex.x * scaleX, IN.vertex.y * scaleY, 0, 0)
//mul(UNITY_MATRIX_MV, float4(0.0, 0.0, 0.0, 1.0)) + float4(IN.vertex.x * scaleX, IN.vertex.y * scaleY, 0.0f, 0.0f)
);
*/
// Method 2
float4x4 mv = UNITY_MATRIX_MV;
mv[0][0] = 1.0;
mv[0][1] = 0.0;
mv[0][2] = 0.0;
mv[1][0] = 0.0;
mv[1][1] = 1.0;
mv[1][2] = 0.0;
mv[2][0] = 0.0;
mv[2][1] = 0.0;
mv[2][2] = 1.0;
OUT.vertex = mul(
UNITY_MATRIX_P,
mul(mv, IN.vertex)
);
OUT.worldPosition = OUT.vertex;
OUT.texcoord = IN.texcoord;
OUT.color = IN.color * _Color;
return OUT;
}
The problem is that when the Image is not at the center of the canvas (0,0,0), the billboard rotation is not around it’s pivot, but the canvas pivot. Here is a small gif:
As you can see the Image on the left (2,0,0) is rotating around the same pivot of the left one (0,0,0), the Canvas pivot (0,0,0).
Here are some caps of the Images transforms and the Canvas transform:

I’ve tried several things but with no success. I’m still learning to programming shaders. Any suggestion is really welcome.
3221103–246915–Billboard UI Transparent Colored.shader (3.06 KB)