Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
11
Help us understand the problem. What is going on with this article?
@gatosyocora

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

More than 1 year has passed since last update.

はじめに

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

環境

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について

11
Help us understand the problem. What is going on with this article?
Why not register and get more from Qiita?
  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
gatosyocora
高知で大学生やっています。 VRに興味ありでVR学会認定VR技術者です

Comments

No comments
Sign up for free and join this conversation.
Sign Up
If you already have a Qiita account Login
11
Help us understand the problem. What is going on with this article?