- Home /
 
 
               Question by 
               plindsey · May 25, 2017 at 02:57 PM · 
                shadersspritesbillboards  
              
 
              Need help applying an x-rotation to a billboard shader (i.e. cylindrical sprite)
Hello,
I was wondering if anyone can help me with this billboard example from https://en.wikibooks.org/wiki/Cg_Programming/Unity/Billboards
 Shader "Custom/Billboard" {
    Properties {
       _MainTex ("Texture Image", 2D) = "white" {}
       _ScaleX ("Scale X", Float) = 1.0
       _ScaleY ("Scale Y", Float) = 1.0
       _Cutoff ("Alpha cutoff", Range (0,1)) = 0.5
    }
    SubShader {
       Pass {   
          CGPROGRAM
  
          #pragma vertex vert  
          #pragma fragment frag 
 
          // User-specified uniforms            
          uniform sampler2D _MainTex;        
          uniform float _ScaleX;
          uniform float _ScaleY;
          uniform float _Cutoff;
 
          struct vertexInput {
             float4 vertex : POSITION;
             float4 tex : TEXCOORD0;
          };
          struct vertexOutput {
             float4 pos : SV_POSITION;
             float4 tex : TEXCOORD0;
          };
  
          vertexOutput vert(vertexInput input) 
          {
             vertexOutput output;
 
              output.pos = mul(UNITY_MATRIX_P, mul(UNITY_MATRIX_MV, float4(0.0, 0.0, 0.0, 1.0)) + float4(input.vertex.x, input.vertex.y, 0.0, 0.0) * float4(_ScaleX, _ScaleY, 1.0, 1.0));
              output.tex = input.tex;
 
             return output;
          }
  
          float4 frag(vertexOutput input) : COLOR
          {
             float4 textureColor = tex2D(_MainTex, input.tex.xy);  
             if (textureColor.a < _Cutoff)
                // alpha value less than user-specified threshold?
             {
                discard; // yes: discard this fragment
             }
             return tex2D(_MainTex, float2(input.tex.xy));   
          }
  
          ENDCG
       }
    }
 }
 
               I want to apply a matrix to rotate on the X Axis so that the sprite acts like the default Unity sprite when the camera is above or below looking up or down on the sprite.
I can't quite figure out what exactly I need to do and I get lost with what seems to be 3 different ways to write shaders also.
Can someone please point me in the right direction?
               Comment
              
 
               
              Your answer