I'm trying to write a sprite shader that can turn normal sprites into pixel art. And it works relatively well IN the texture, but the entire things always has the shape of the original sprite instead of being whole squares. I suspect that is because there is originally no vertices there, the shader doesnt go through these spots and thats why the squares are cut off. Can I somehow make this possible though?
Shader "Own/Pixel"
{
Properties
{
[PerRendererData]_MainTex("Texture", 2D) = "white" {}
_PosCorrection("Pos Correction", Range(0,1000)) = 1
_ColorCorrection("Color Correction", Float) = 1
}
SubShader
{
Tags
{
"Queue" = "AlphaTest"
"IgnoreProjector" = "True"
"RenderType" = "Transparent"
"PreviewType" = "Plane"
"CanUseSpriteAtlas" = "True"
}
ZWrite off
Cull Off
Lighting Off
Blend One OneMinusSrcAlpha
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma multi_compile _ PIXELSNAP_ON
#include "UnityCG.cginc"
struct input
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct output
{
float2 uv : TEXCOORD0;
fixed4 color : COLOR;
float4 vertex : SV_POSITION;
};
float _ColorCorrection;
float _PosCorrection;
output vert(input v)
{
output o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.vertex = UnityPixelSnap(o.vertex);
o.uv = v.uv;
return o;
}
sampler2D _MainTex;
fixed4 frag(output i) : COLOR
{
float4 col = tex2D(_MainTex, round(i.uv*_PosCorrection) / _PosCorrection);
//// just invert the colors
//col.r = round(col.r * _ColorCorrection);
//col.g = round(col.g * _ColorCorrection);
//col.b = round(col.b * _ColorCorrection);
col.rgb *= col.a;
//return float4(col.rgb / _ColorCorrection,col.a);
return col;
}
ENDCG
}
}
}