SpriteBillboard.shader 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. Shader "udSDK/Demo/SpriteBillboard"
  2. {
  3. Properties {
  4. _MainTex ("Texture Image", 2D) = "white" {}
  5. _ZOffset ("Z Offset", float) = 0.0
  6. }
  7. SubShader
  8. {
  9. Tags
  10. {
  11. "Queue" = "Transparent"
  12. "RenderType" = "Opaque"
  13. }
  14. Pass
  15. {
  16. ZWrite On
  17. AlphaToMask On
  18. CGPROGRAM
  19. #include "UnityCG.cginc"
  20. #pragma vertex vert
  21. #pragma fragment frag
  22. // User-specified uniforms
  23. uniform sampler2D _MainTex;
  24. uniform float _ZOffset;
  25. struct vertexInput {
  26. float4 vertex : POSITION;
  27. float4 tex : TEXCOORD0;
  28. };
  29. struct vertexOutput {
  30. float4 pos : SV_POSITION;
  31. float4 tex : TEXCOORD0;
  32. };
  33. vertexOutput vert(vertexInput input)
  34. {
  35. vertexOutput output;
  36. float3 scale = float3(
  37. length(unity_ObjectToWorld._m00_m10_m20),
  38. length(unity_ObjectToWorld._m01_m11_m21),
  39. length(unity_ObjectToWorld._m02_m12_m22)
  40. );
  41. output.pos = mul(UNITY_MATRIX_P,
  42. float4(UnityObjectToViewPos((float3)0), 1.0+_ZOffset)
  43. + float4(input.vertex.x, input.vertex.y, 0.0, 0.0) *
  44. float4(scale.x, scale.y, 1.0, 1.0)
  45. );
  46. output.tex = input.tex;
  47. return output;
  48. }
  49. float4 frag(vertexOutput input) : COLOR
  50. {
  51. return tex2D(_MainTex, float2(input.tex.xy)) * input.tex.a;
  52. }
  53. ENDCG
  54. }
  55. }
  56. }