Advertisement
tonynogo

Demo 73 - Triangle mosaic

Jul 6th, 2017
4,542
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Shader "Unlit/TriangleMosaic"
  2. {
  3.     Properties
  4.     {
  5.         _MainTex ("Texture", 2D) = "white" {}
  6.         _TileNumX ("Tile number along X", float) = 0
  7.         _TileNumY ("Tile number along Y", float) = 0
  8.     }
  9.     SubShader
  10.     {
  11.         Tags { "RenderType"="Opaque" }
  12.  
  13.         Pass
  14.         {
  15.             CGPROGRAM
  16.             #pragma vertex vert
  17.             #pragma fragment frag
  18.            
  19.             #include "UnityCG.cginc"
  20.  
  21.             struct v2f
  22.             {
  23.                 float4 pos : SV_POSITION;
  24.                 float4 screenuv : TEXCOORD1;
  25.             };
  26.            
  27.             v2f vert (appdata_base v)
  28.             {
  29.                 v2f o;
  30.                 o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
  31.                 o.screenuv = ComputeScreenPos(o.pos);
  32.                 return o;
  33.             }
  34.            
  35.             float _TileNumX;
  36.             float _TileNumY;
  37.             sampler2D _MainTex;
  38.  
  39.             fixed4 frag (v2f i) : SV_Target
  40.             {
  41.                 float2 uv = i.screenuv.xy / i.screenuv.w;
  42.                 float2 TileNum = float2(_TileNumX, _TileNumY);
  43.                 float2 uv2 = floor(uv * TileNum) / TileNum;
  44.                 uv -= uv2;
  45.                 uv *= TileNum;
  46.  
  47.                 fixed4 col = tex2D( _MainTex, uv2 + float2(step(1.0 - uv.y, uv.x) / (2.0 * _TileNumX),
  48.                 step(uv.x,uv.y)/(2.0 * _TileNumY)));
  49.  
  50.                 return col;
  51.             }
  52.             ENDCG
  53.         }
  54.     }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement