Help us understand the problem. What is going on with this article?

Shaderでオブジェクトやテクスチャのスケールと縦横比を取得する

はじめに

よく忘れるので備忘録です

環境

Unity 5.6.3p1
Unity 2017.4.15f1

オブジェクトのスケール比

スケールx
float sX = 1/sqrt(pow(unity_WorldToObject[0].x, 2) + pow(unity_WorldToObject[0].y, 2) + pow(unity_WorldToObject[0].z, 2))

スケールy
float sY = 1/sqrt(pow(unity_WorldToObject[1].x, 2) + pow(unity_WorldToObject[1].y, 2) + pow(unity_WorldToObject[1].z, 2));

スケールz
float sZ = 1/sqrt(pow(unity_WorldToObject[2].x, 2) + pow(unity_WorldToObject[2].y, 2) + pow(unity_WorldToObject[2].z, 2));

xとyの比
X:Y = sX/sY : 1

使用用途によってはWorldToObjectの部分をObjectToWorldにしてもいいかもしれないです

MainTexの縦横比

縦の解像度
float h = _MainTex_TexelSize.y;

横の解像度
float w = _MainTex_TexelSize.x;

縦横比
縦:横 = h/w : 1

_MainTexと宣言されたプロパティが存在し,
コード内でfloat4 _MainTex_TexelSize;と書いておく必要があります
プロパティ名が_MainTex以外のテクスチャ(_Hoge)に対しても_Hoge_TexelSizeと書くことで使えます

参考文献

スケール成分
_MainTex_TexelSizeについて

Why do not you register as a user and use Qiita more conveniently?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away