Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
- // Upgrade NOTE: replaced '_Object2World' with 'unity_ObjectToWorld'
- Shader "Over2D/Tiler"
- {
- Properties
- {
- _MainTex("Sprite Texture", 2D) = "white" {}
- _Color("Tint", Color) = (1,1,1,1)
- [MaterialToggle] PixelSnap("Pixel snap", Float) = 0
- }
- SubShader
- {
- Tags
- {
- "Queue" = "Transparent"
- "IgnoreProjector" = "True"
- "RenderType" = "Transparent"
- "PreviewType" = "Plane"
- "CanUseSpriteAtlas" = "True"
- }
- Cull Off
- Lighting Off
- ZWrite Off
- Blend One OneMinusSrcAlpha
- Fog{ Mode Off }
- Pass
- {
- CGPROGRAM
- #pragma vertex vert
- #pragma fragment frag
- #pragma multi_compile _ PIXELSNAP_ON
- #include "UnityCG.cginc"
- struct appdata
- {
- float4 vertex : POSITION;
- float2 uv : TEXCOORD0;
- };
- struct v2f
- {
- float4 vertex : SV_POSITION;
- half2 uv : TEXCOORD0;
- };
- fixed4 _Color;
- sampler2D _MainTex;
- //сюда юнити передаёт тайлинг и оффсет текстуры
- float4 _MainTex_ST;
- v2f vert(appdata IN)
- {
- v2f OUT;
- OUT.vertex = UnityObjectToClipPos(IN.vertex);
- //тайлим текстуру
- float xScale = length(float3(unity_ObjectToWorld[0][0], unity_ObjectToWorld[1][0], unity_ObjectToWorld[2][0])) / _MainTex_ST.x;
- float yScale = length(float3(unity_ObjectToWorld[0][1], unity_ObjectToWorld[1][1], unity_ObjectToWorld[2][1])) / _MainTex_ST.y;
- OUT.uv = IN.uv * half2(xScale, yScale);
- #ifdef PIXELSNAP_ON
- OUT.vertex = UnityPixelSnap(OUT.vertex);
- #endif
- return OUT;
- }
- fixed4 SampleSpriteTexture(float2 uv)
- {
- //сдвигаем Offset текстуры на заданную величину
- uv += _MainTex_ST.zw;
- fixed4 color = tex2D(_MainTex, uv);
- return color;
- }
- fixed4 frag(v2f IN) : SV_Target
- {
- fixed4 c = SampleSpriteTexture(IN.uv);
- c.rgb *= _Color;
- c.rgb *= c.a;
- return c;
- }
- ENDCG
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement