Skip to content

Instantly share code, notes, and snippets.

@sugi-cho
Last active December 20, 2015 15:19
Show Gist options
  • Save sugi-cho/6153795 to your computer and use it in GitHub Desktop.
Save sugi-cho/6153795 to your computer and use it in GitHub Desktop.
http://sugi.cc/post/57405474012/get-angle-in-shader UnityのShaderで、角度を求める(0~1)
float PI = 3.14159265359;
float x = (atan2(v.vertex.z,v.vertex.x) - PI/2.0);
float y = 2.0*PI;
float angle = (x - y * floor(x/y))/(2.0*PI);
//いちばん、Unityで、ただしそうな、かきかた
float2 p = IN.uv - float2(0.5,0.5);
angle = fmod(atan2(p.y,p.x)-PI/2+2*PI, 2*PI)/(2*PI);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment