Advertisement
Guest User

PixelEffect.shader

a guest
Apr 19th, 2019
834
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Shader "Hidden/PixelEffect"
  2. {
  3.     Properties
  4.     {
  5.         _MainTex ("Texture", 2D) = "white" {}
  6.         _PixelSize("Pixel width", float) = 1.0
  7.        
  8.     }
  9.     SubShader
  10.     {
  11.  
  12.         Cull Off ZWrite Off ZTest Always
  13.         Stencil{
  14.             Ref 1
  15.             ReadMask 1
  16.             Comp Equal
  17.             Pass Keep
  18.         }
  19.         Pass
  20.         {
  21.             CGPROGRAM
  22.             #pragma vertex vert
  23.             #pragma fragment frag
  24.            
  25.             #include "UnityCG.cginc"
  26.  
  27.             struct appdata
  28.             {
  29.                 half4 vertex : POSITION;
  30.                 half2 uv : TEXCOORD0;
  31.             };
  32.  
  33.             struct v2f
  34.             {
  35.                 half2 uv : TEXCOORD0;
  36.                 half4 vertex : SV_POSITION;
  37.             };
  38.  
  39.             v2f vert (appdata v)
  40.             {
  41.                 v2f o;
  42.                 o.vertex = UnityObjectToClipPos(v.vertex);
  43.                 o.uv = v.uv;
  44.                 return o;
  45.             }
  46.            
  47.             sampler2D _MainTex;
  48.             half _PixelSize;
  49.        
  50.        
  51.  
  52.             fixed4 frag (v2f i) : SV_Target
  53.             {
  54.                 fixed4 col = tex2D(_MainTex, i.uv);
  55.                 float2 pixels = _PixelSize * (1 / _ScreenParams.xy);
  56.                 float2 pixeluv = float2(pixels * round(i.uv / pixels));
  57.                 col = tex2D(_MainTex, pixeluv);
  58.                 return col;
  59.             }
  60.             ENDCG
  61.         }
  62.     }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement