Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

add rotation in the biliboard shader

Discussion in 'Shaders' started by leekinon, Jul 2, 2015.

  1. leekinon

    leekinon

    Joined:
    Dec 4, 2013
    Posts:
    21
    How to add rotation in the billboard shader?

    Here is my shader code:

    Code (CSharp):
    1. Shader "Custom/Billboard" {
    2.     Properties {
    3.        _MainTex ("Texture Image", 2D) = "white" {}
    4.        _CutOff("Cut off", float) = 0.1
    5.     }
    6.     SubShader {
    7.        Pass {  
    8.           CGPROGRAM
    9.  
    10.           #pragma vertex vert
    11.           #pragma fragment frag
    12.  
    13.           // User-specified uniforms          
    14.           uniform sampler2D _MainTex;      
    15.           uniform float _CutOff;
    16.  
    17.           struct vertexInput {
    18.              float4 vertex : POSITION;
    19.              float4 tex : TEXCOORD0;
    20.           };
    21.           struct vertexOutput {
    22.              float4 pos : SV_POSITION;
    23.              float4 tex : TEXCOORD0;
    24.           };
    25.  
    26.           vertexOutput vert(vertexInput input)
    27.           {
    28.              vertexOutput output;
    29.  
    30.              output.pos = mul(UNITY_MATRIX_P,
    31.                mul(UNITY_MATRIX_MV, float4(0.0, 0.0, 0.0, 1.0))
    32.                - float4(input.vertex.x, input.vertex.z, 0.0, 0.0));
    33.  
    34.              output.tex = input.tex;
    35.  
    36.              return output;
    37.           }
    38.  
    39.           float4 frag(vertexOutput input) : COLOR
    40.           {
    41.            
    42.              float4 color = tex2D(_MainTex, float2(input.tex.xy));  
    43.              if(color.a < _CutOff) discard;
    44.              return color;
    45.           }
    46.         ENDCG
    47.         }//endpass
    48.     }
    49.     //FallBack "Diffuse"
    50. }
    51.