Advertisement
Guest User

Untitled

a guest
Sep 22nd, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
  2.  
  3. // Upgrade NOTE: replaced '_Object2World' with 'unity_ObjectToWorld'
  4.  
  5. Shader "Over2D/Tiler"
  6. {
  7.     Properties
  8.     {
  9.         _MainTex("Sprite Texture", 2D) = "white" {}
  10.         _Color("Tint", Color) = (1,1,1,1)
  11.         [MaterialToggle] PixelSnap("Pixel snap", Float) = 0
  12.     }
  13.  
  14.         SubShader
  15.     {
  16.         Tags
  17.     {
  18.         "Queue" = "Transparent"
  19.         "IgnoreProjector" = "True"
  20.         "RenderType" = "Transparent"
  21.         "PreviewType" = "Plane"
  22.         "CanUseSpriteAtlas" = "True"
  23.     }
  24.  
  25.         Cull Off
  26.         Lighting Off
  27.         ZWrite Off
  28.         Blend One OneMinusSrcAlpha
  29.  
  30.         Fog{ Mode Off }
  31.  
  32.         Pass
  33.         {
  34.             CGPROGRAM
  35.     #pragma vertex vert
  36.     #pragma fragment frag
  37.     #pragma multi_compile _ PIXELSNAP_ON
  38.     #include "UnityCG.cginc"
  39.  
  40.             struct appdata
  41.             {
  42.                 float4 vertex   : POSITION;
  43.                 float2 uv : TEXCOORD0;
  44.             };
  45.  
  46.             struct v2f
  47.             {
  48.                 float4 vertex   : SV_POSITION;
  49.                 half2 uv  : TEXCOORD0;
  50.             };
  51.  
  52.             fixed4 _Color;
  53.             sampler2D _MainTex;
  54.             //сюда юнити передаёт тайлинг и оффсет текстуры
  55.             float4 _MainTex_ST;
  56.  
  57.             v2f vert(appdata IN)
  58.             {
  59.                 v2f OUT;
  60.                 OUT.vertex = UnityObjectToClipPos(IN.vertex);
  61.                 //тайлим текстуру
  62.                 float xScale = length(float3(unity_ObjectToWorld[0][0], unity_ObjectToWorld[1][0], unity_ObjectToWorld[2][0])) / _MainTex_ST.x;
  63.                 float yScale = length(float3(unity_ObjectToWorld[0][1], unity_ObjectToWorld[1][1], unity_ObjectToWorld[2][1])) / _MainTex_ST.y;
  64.                 OUT.uv = IN.uv * half2(xScale, yScale);
  65.  
  66.         #ifdef PIXELSNAP_ON
  67.                 OUT.vertex = UnityPixelSnap(OUT.vertex);
  68.         #endif
  69.  
  70.                 return OUT;
  71.             }
  72.  
  73.             fixed4 SampleSpriteTexture(float2 uv)
  74.             {
  75.                 //сдвигаем Offset текстуры на заданную величину
  76.                 uv += _MainTex_ST.zw;
  77.  
  78.                 fixed4 color = tex2D(_MainTex, uv);
  79.  
  80.                 return color;
  81.             }
  82.  
  83.             fixed4 frag(v2f IN) : SV_Target
  84.             {
  85.                 fixed4 c = SampleSpriteTexture(IN.uv);
  86.                 c.rgb *= _Color;
  87.                 c.rgb *= c.a;
  88.                 return c;
  89.             }
  90.             ENDCG
  91.         }
  92.     }
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement