Barcode.shader 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. Shader "Unlit/Barcode"
  2. {
  3. Properties
  4. {
  5. _MainTex("Texture", 2D) = "white" {}
  6. _Color1 ("Color1", Color) = (0,0,0,1)
  7. _Color2 ("Color2", Color) = (1,1,1,1)
  8. _Row ("Row", int) = 5
  9. _Column("Column", int) = 5
  10. _Value ("Value", int) = 0
  11. }
  12. SubShader
  13. {
  14. Tags { "RenderType"="Opaque" }
  15. LOD 100
  16. Pass
  17. {
  18. CGPROGRAM
  19. #pragma vertex vert
  20. #pragma fragment frag
  21. #include "UnityCG.cginc"
  22. struct appdata
  23. {
  24. float4 vertex : POSITION;
  25. float2 texcoord1 : TEXCOORD1;
  26. };
  27. struct v2f
  28. {
  29. float4 uv : TEXCOORD0;
  30. float4 pos : SV_POSITION;
  31. };
  32. fixed4 _Color1;
  33. fixed4 _Color2;
  34. int _Value;
  35. int _Row;
  36. int _Column;
  37. v2f vert (appdata v)
  38. {
  39. v2f o;
  40. o.pos = UnityObjectToClipPos(v.vertex);
  41. o.uv = float4(v.texcoord1.xy, 0, 0);
  42. UNITY_TRANSFER_FOG(o,o.vertex);
  43. return o;
  44. }
  45. fixed4 frag(v2f i) : SV_Target
  46. {
  47. int x = floor(i.uv.x * _Row);
  48. int y = floor(i.uv.y * _Column);
  49. int bit = x + y * _Row;
  50. if ((_Value >> bit) & 1)
  51. return _Color2;
  52. return _Color1;
  53. }
  54. ENDCG
  55. }
  56. }
  57. }