Can I get the scale in the transform of the object I attach a shader to? If so, how?

It seems that this produce unsigned scaled because of the length calculation but is there a way to get the signed scale ? I achieved to do it but when rotating the mesh it breaks.

1 Like

Does rotation not get stored in those cells of the matrix as well? I thought these matrices were position, rotation, and scale matrices multiplied together (in some order). Or is that not actually how they work? Like, wouldn’t rotation affect this value, or does the length() take care of that?

Yes, rotation, scale, and translation. Translation sits by itself, but the scale and rotation are represented by the 3x3 of the matrix. The 3x3 part of the matrix is basically 3 scaled vectors that give the axis and magnitude of the x, y, and z coordinates for the space you’re transforming from in the space you’re transforming to.

Ah, okay. That is what I thought. I think I see why this works. Because each of these scaled vectors (x, y, and z axis), when scale is 1, are normal vectors, have length of 1. So by taking the length of each of these you are figuring out how long they are, which would be equal to their scale. Right?

Correct.

3 Likes

my problem too, how to find signed scale ?

The short version is … you can’t.

The long version is you can find out if the scale has an odd number of negatively scaled axis by doing a dot product between one axis vector the cross product of the other two axes. But there’s no way to tell the difference between a transform matrix with two negatively scaled axes and one with no negatively scaled axes that’s been rotated 180 degrees on two axis. They produce the same transform matrix. Similarly you can’t tell the difference between any one or all three negatively scaled axes as certain rotations with those scales can produce the same transform matrix. If you really need to know the sign of the scale you need to get this in c# and pass it to the material manually.

1 Like