Skip to content

Instantly share code, notes, and snippets.

@hakanai
Last active January 5, 2018 05:12
Show Gist options
  • Save hakanai/597379f3499a0d18291af0bc1aff050c to your computer and use it in GitHub Desktop.
Save hakanai/597379f3499a0d18291af0bc1aff050c to your computer and use it in GitHub Desktop.
Shader "Pixelate" {
Properties {
_CellSize ("Cell Size", Vector) = (0.02, 0.02, 0, 0)
}
SubShader {
Tags { "RenderType"="Opaque" }
LOD 200
GrabPass { "_PixelationGrabTexture"}
Pass {
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct v2f {
float4 pos : SV_POSITION;
float4 grabUV : TEXCOORD0;
};
float4 _CellSize;
v2f vert(appdata_base v) {
v2f o;
o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
o.grabUV = ComputeGrabScreenPos(o.pos);
return o;
}
sampler2D _PixelationGrabTexture;
float4 frag(v2f IN) : COLOR {
float2 steppedUV = IN.grabUV.xy/IN.grabUV.w;
steppedUV /= _CellSize.xy;
steppedUV = round(steppedUV);
steppedUV *= _CellSize.xy;
return tex2D(_PixelationGrabTexture, steppedUV);
}
ENDCG
}
}
}
Shader "Custom\Pixelate"
{
Properties
{
_CellSize ("Cell Size", Vector) = (0.02, 0.02, 0, 0)
}
SubShader {
Tags { "RenderType"="Opaque" "Queue" = "Transparent" }
LOD 200
GrabPass { "_PixelationGrabTexture"}
Pass {
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct v2f {
float4 pos : SV_POSITION;
float4 grabUV : TEXCOORD0;
};
float4 _CellSize;
v2f vert(appdata_base v) {
v2f o;
o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
o.grabUV = ComputeGrabScreenPos(o.pos);
return o;
}
sampler2D _PixelationGrabTexture;
float4 frag(v2f IN) : COLOR
{
float2 steppedUV = IN.grabUV.xy/IN.grabUV.w;
steppedUV /= _CellSize.xy;
steppedUV = round(steppedUV);
steppedUV *= _CellSize.xy;
return tex2D(_PixelationGrabTexture, steppedUV);
}
ENDCG
}
}
}
Shader "Custom/Pixelate New"
{
Properties
{
_PixelSize("Pixel Size", Float) = 10
}
SubShader
{
Tags{ "Queue" = "Transparent" "IgnoreProjector" = "True" }
Blend Off
Lighting Off
Fog{ Mode Off }
ZWrite Off
LOD 200
Cull Off
GrabPass{ "_GrabTexture" }
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct v2f
{
float4 pos : SV_POSITION;
float4 uv : TEXCOORD0;
};
float _PixelSize;
v2f vert(appdata_base v)
{
v2f o;
o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
o.uv = ComputeGrabScreenPos(o.pos);
return o;
}
sampler2D _GrabTexture;
float4 frag(v2f IN) : COLOR
{
float2 steppedUV = IN.uv.xy / IN.uv.w;
steppedUV /= _PixelSize / _ScreenParams.xy;
steppedUV = round(steppedUV);
steppedUV *= _PixelSize / _ScreenParams.xy;
return tex2D(_GrabTexture, steppedUV);
}
ENDCG
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment