イラスト、モデリング、Unity、VR関連

unityとかblenderとかvr関連の作業メモ

shader 3DBillboard

o.posに代入している値は、スケール、トランスフォームを無視して座標変換を行っている。 (これらの要素はワールド変換行列が含まれる) float4(0,0,0,1)を変えれば任意の位置に移動できる

Shader "Custom/Billboard"{
  Properties{
      _MainTex ("Texture", 2D) = "white" {}
			_Scale("Scale",Range(0.1,1)) = 1
  }
  SubShader{
    Tags { "Queue"="Transparent" "RenderType"="Transparent" }
    Blend SrcAlpha OneMinusSrcAlpha
    Pass{
  		Cull Back
			Lighting Off
      CGPROGRAM
      #pragma vertex vert
      #pragma fragment frag
      #include "UnityCG.cginc"
      struct v2f{
        float4 pos : SV_POSITION;
        float2 uv : TEXCOORD0;
    	};
      sampler2D _MainTex;
      float4 _MainTex_ST;
  		float _Scale;

      v2f vert (appdata_base v){
        v2f o;
				o.pos = mul(UNITY_MATRIX_P, mul(UNITY_MATRIX_MV, float4(0,0,0,1)) + float4(v.vertex.x,v.vertex.y,v.vertex.z,0.0) * float4(_Scale, _Scale, _Scale, 1.0));
        o.uv = TRANSFORM_TEX(v.texcoord, _MainTex);
        return o;
      }
      fixed4 frag (v2f i) : SV_Target{
        fixed4 col = tex2D(_MainTex, i.uv);
        return col;
      }
      ENDCG
    }
  }
}