tonynogo

Demo 12 - Pixelation

Jul 6th, 2017
6,543
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Shader "Custom/Pixelation" {
  2.     Properties {
  3.         _MainTex ("Base (RGB)", 2D) = "white" {}
  4.         _PixelNumberX ("Pixel number along X", float) = 500
  5.         _PixelNumberY ("Pixel number along X", float) = 500
  6.     }
  7.  
  8.     SubShader {
  9.         Pass {
  10.             Tags { "RenderType"="Opaque" }
  11.        
  12.             CGPROGRAM
  13.             #pragma vertex vert
  14.             #pragma fragment frag
  15.             #include "UnityCG.cginc"
  16.  
  17.             sampler2D _MainTex;
  18.             float _PixelNumberX;
  19.             float _PixelNumberY;
  20.  
  21.             struct v2f {
  22.                 half4 pos : POSITION;
  23.                 half2 uv : TEXCOORD0;
  24.             };
  25.  
  26.             float4 _MainTex_ST;
  27.  
  28.             v2f vert(appdata_base v) {
  29.                 v2f o;
  30.                 o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
  31.                 o.uv = TRANSFORM_TEX(v.texcoord, _MainTex);
  32.                 return o;
  33.             }
  34.  
  35.             half4 frag(v2f i) : COLOR {
  36.                 half ratioX = 1 / _PixelNumberX;
  37.                 half ratioY = 1 / _PixelNumberY;
  38.                 half2 uv = half2((int)(i.uv.x / ratioX) * ratioX, (int)(i.uv.y / ratioY) * ratioY);
  39.                 return tex2D(_MainTex, uv);
  40.             }
  41.  
  42.             ENDCG
  43.         }
  44.     }
  45.     FallBack "Diffuse"
  46. }
Advertisement
Add Comment
Please, Sign In to add comment