UnlitBillboard.Shader 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. // Unlit alpha-cutout billboard shader.
  2. // - no lighting
  3. // - no lightmap support
  4. Shader "MTE/Grass/UnlitBillboard"
  5. {
  6. Properties
  7. {
  8. _MainTex("Grass Texture", 2D) = "white" {}
  9. _Cutoff("Alpha cutoff", Range(0,1)) = 0.5
  10. }
  11. SubShader
  12. {
  13. Tags
  14. {
  15. "Queue" = "AlphaTest"
  16. "IgnoreProjector" = "True"
  17. "DisableBatching" = "True"
  18. "RenderType" = "TransparentCutout"
  19. }
  20. Lighting Off
  21. Pass
  22. {
  23. CGPROGRAM
  24. #pragma vertex vert
  25. #pragma fragment frag
  26. uniform sampler2D _MainTex;
  27. uniform float _Cutoff;
  28. struct vertexInput
  29. {
  30. float4 vertex : POSITION;
  31. float4 tex : TEXCOORD0;
  32. };
  33. struct vertexOutput
  34. {
  35. float4 pos : SV_POSITION;
  36. float4 tex : TEXCOORD0;
  37. };
  38. #if !defined(UnityObjectToViewPos)
  39. // Tranforms position from object to camera space
  40. inline float3 UnityObjectToViewPos( in float3 pos )
  41. {
  42. return mul(UNITY_MATRIX_V, mul(unity_ObjectToWorld, float4(pos, 1.0))).xyz;
  43. }
  44. inline float3 UnityObjectToViewPos(float4 pos) // overload for float4; avoids "implicit truncation" warning for existing shaders
  45. {
  46. return UnityObjectToViewPos(pos.xyz);
  47. }
  48. #endif
  49. vertexOutput vert(vertexInput input)
  50. {
  51. vertexOutput output;
  52. output.pos = mul(UNITY_MATRIX_P,
  53. float4(UnityObjectToViewPos(float3(0.0, 0.0, 0.0)), 1.0)
  54. + float4(input.vertex.x, input.vertex.y, 0.0, 0.0));
  55. output.tex = input.tex;
  56. return output;
  57. }
  58. float4 frag(vertexOutput input) : COLOR
  59. {
  60. float4 c = tex2D(_MainTex, float2(input.tex.xy));
  61. clip(c.a - _Cutoff);
  62. return c;
  63. }
  64. ENDCG
  65. }
  66. }
  67. }