Bilboard Rotation

 


  1. Shader "Tut/Project/Billboard_2" {
  2.     Properties {
  3.         _MainTex ("Base (RGB)", 2D) = "white" {}
  4.     }
  5.     SubShader {
  6.         Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" }
  7.         pass{
  8.         Cull Off
  9.         ZTest Always
  10.         Blend SrcAlpha OneMinusSrcAlpha
  11.         CGPROGRAM
  12.         #pragma vertex vert
  13.         #pragma fragment frag
  14.         #include "UnityCG.cginc"
  15.         sampler2D _MainTex;
  16.         struct v2f {
  17.             float4 pos:SV_POSITION;
  18.             float2 texc:TEXCOORD0;
  19.         };
  20.         v2f vert(appdata_base v)
  21.         {
  22.             v2f o;
  23.             float4 ori=mul(UNITY_MATRIX_MV,float4(0,0,0,1));
  24.             float4 vt=v.vertex;
  25.             //vt.y=vt.z;
  26.             float2 r1=float2(_Object2World[0][0],_Object2World[0][2]);
  27.             float2 r2=float2(_Object2World[2][0],_Object2World[2][2]);
  28.             float2 vt0=vt.x*r1;
  29.             vt0+=vt.z*r2;
  30.             vt.xy=vt0;
  31.             vt.z=0;
  32.             vt.xyz+=ori.xyz;//result is vt.z==ori.z ,so the distance to camera keeped ,and screen size keeped
  33.             o.pos=mul(UNITY_MATRIX_P,vt);
  34.  
  35.             o.texc=v.texcoord;
  36.             return o;
  37.         }
  38.         float4 frag(v2f i):COLOR
  39.         {
  40.             return tex2D(_MainTex,i.texc);
  41.         }
  42.         ENDCG
  43.         }//endpass
  44.     }
  45. }

  1. private void Start(){
  2. Debug.Log(FindDegree(0, 1));
  3. }
  4. public static float FindDegree(int x, int y){
  5. float value = (float)((Mathf.Atan2(x, y) / Math.PI) * 180f);
  6. if(value < 0) value += 360f;
  7. return value;
  8. }

댓글

이 블로그의 인기 게시물

About AActor!!! "UObject" has no member "BeginPlay"

UNREAL Android build information

C++ 생성자 위임 (delegating constructor)