- Home /
How do I take matrix values intended for Material.SetMatrix and apply them to Material.SetTextureOffset ?
I have a script that performs various operations (scroll, rotate, stretch etc) on a texture using matrix calculations and the function Material.SetMatrix.
However due to performance issues with Material.SetMatrix, I have been requested to use Material.SetTextureOffset instead.
I want to ask: Is there a general way to take the values in my calulcated matrix, apply them to a 2D vector and pass the 2D vector to Material.SetTextureOffset ?
Some of my calculations require matrix math (like "stretch") and I would like to be able to keep the calculations. I have no idea how to do some of the calcs without matrices.
Any advice or suggestions welcome.
Example Rotation Code:
Vector2 rotationCenter = new Vector2 (0.5f, 0.5f);
float rotValue = (some value changed over time)
rotation = Quaternion.Euler (0f, 0f, rotValue);
scale = Vector3.one;
Matrix4x4 m = Matrix4x4.TRS ( Vector3.zero, rotation, scale );
Matrix4x4 t = Matrix4x4.TRS (-rotationCenter, Quaternion.identity, scale);
Matrix4x4 t_inverse = Matrix4x4.TRS (rotationCenter, Quaternion.identity, scale);
tex_matrix = t_inverse * m * t;
Your answer
Follow this Question
Related Questions
Offset textures individually into specific world directions 2 Answers
Rotating a Rotated GUI Texture 0 Answers
Rotating Textures 0 Answers
Instantiate with Object Rotation *180 (Rotation Offset) 2 Answers