Get the scale of object related to worldspace

I am trying to get the scale of object related to world space.

Try using _Object2World. But it included rotation transform. I get wrong scale if the object rotated.

Any idea to get the scale with pure shader?

_Object2World (or unity_ObjectToWorld in 5.4+) is your best bet for getting scale if you want a pure shader solution. The trick is you have to extract the scale from the matrix regardless of the rotation which isn’t totally trivial, and if your mesh import scale isn’t 1.0 then it’ll have additional scaling from that as well.

If your scaling is always going to be uniform, you can just do this:
float scale = length(float3(unity_ObjectToWorld[0].x, unity_ObjectToWorld[1].x, unity_ObjectToWorld[2].x));

But the above issues will still be there. The only 100% for sure way to get this to work is to pass the value to the shader via script.

Thanks. This help.:wink: