Different vertex world position on Scene/Game view in Screen Space Canvas

Hi, I’ve created UI shader which needs to handle world position of vertex. On Camera Space Canvas everything works fine but on Screen Space Canvas position of vertex is different.
So from shader like:

v2f vert(appdata_t v)
{
   v2f OUT;
   UNITY_SETUP_INSTANCE_ID(v);
   UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(OUT);
   OUT.vertexPos = v.vertex;
   OUT.worldPos = mul(unity_ObjectToWorld, v.vertex);
   OUT.vertex = UnityObjectToClipPos(v.vertex);
   return OUT;
}

half4 frag(v2f IN) : SV_Target
{           
   half4 color = frac(length(IN.worldPos.xy - _Pos.xy) / 50); //on example screen _Pos is (0,0)
   color.a = 1;

#ifdef UNITY_UI_CLIP_RECT
   color.a *= UnityGet2DClipping(IN.vertexPos.xy, _ClipRect);
#endif

   return color;
}

On scene view I have (it’s proper one, there is world pos (0,0)):

But on game view (it’s wrong):

Any idea how to fix this? I thought about offsetting value in shader but it will still make that on scene view or game view value will be wrong. I cannot even handle different previews because there is no that kind of define.

The screen space canvas doesn’t have a proper world matrix since the expectation is that it lives only ever in screen space. Screen space objects get drawn with an identity object to world matrix, which means its “world” is effectively the view space.

I understand expectations but still world space matrix could be, in both views, the same as visibility is manipulated by VP matrix.

Ok, so maybe with other way: I have center of Image and I want to show distance from it on another Image (per pixel). How should I do that if in SSCanvas I shouldn’t use world matrix?

You’re assuming it’s the same VP matrix, which I don’t think it is for screen space canvases.

Ideally a screen space UI exists at the near plane of the camera, so even if there was a valid world space, it’d be tiny.