ApplyTransparency.shader 986 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. Shader "Hidden/TriLib/ApplyTransparency"
  2. {
  3. SubShader
  4. {
  5. // No culling or depth
  6. Cull Off ZWrite Off ZTest Always
  7. Pass
  8. {
  9. CGPROGRAM
  10. #pragma vertex vert
  11. #pragma fragment frag
  12. #include "UnityCG.cginc"
  13. struct appdata
  14. {
  15. float4 vertex : POSITION;
  16. float2 uv : TEXCOORD0;
  17. };
  18. struct v2f
  19. {
  20. float2 uv : TEXCOORD0;
  21. float4 vertex : SV_POSITION;
  22. };
  23. v2f vert(appdata v)
  24. {
  25. v2f o;
  26. o.vertex = UnityObjectToClipPos(v.vertex);
  27. o.uv = v.uv;
  28. return o;
  29. }
  30. sampler2D _TransparencyTexture;
  31. sampler2D _DiffuseTexture;
  32. int _HasTransparencyTexture;
  33. int _HasDiffuseTexture;
  34. float4 frag(v2f i) : SV_Target
  35. {
  36. float4 diffuse = _HasDiffuseTexture ? tex2D(_DiffuseTexture, i.uv) : float4(1.0,1.0,1.0,1.0);
  37. float alpha = _HasTransparencyTexture ? tex2D(_TransparencyTexture, i.uv).x : diffuse.w;
  38. return float4(diffuse.xyz, alpha);
  39. }
  40. ENDCG
  41. }
  42. }
  43. }