Skip to content

Instantly share code, notes, and snippets.

@v21
Last active August 29, 2015 14:18
Show Gist options
  • Save v21/d7e7c8289001f00a087b to your computer and use it in GitHub Desktop.
Save v21/d7e7c8289001f00a087b to your computer and use it in GitHub Desktop.
Pixelated.shader
Shader "Custom/Pixelated" {
Properties {
_MainTex ("Base (RGB)", 2D) = "white" {}
_PixelSize ("Width and height of pixel in px", Range(1,100)) = 1
}
SubShader {
Pass {
ZTest Always Cull Off ZWrite Off
Fog { Mode off }
CGPROGRAM
#pragma vertex vert_img
#pragma fragment frag
#pragma fragmentoption ARB_precision_hint_fastest
#include "UnityCG.cginc"
uniform sampler2D _MainTex;
uniform float4 _MainTex_TexelSize;
uniform float2 _PixelSize;
float4 frag (v2f_img i) : COLOR {
float2 d = _PixelSize*(_MainTex_TexelSize.xy);
float2 coord = float2(d*floor((((i.uv - float2(.5,.5))/d)) + float2(.5,.5))) + float2(.5,.5);
float4 result = tex2D(_MainTex, coord);
return result;
}
ENDCG
}
}
Fallback off
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment