我正在尝试编写一个可以将普通精灵变成像素艺术的精灵着色器。 并且它在纹理中工作得相对较好,但整个事物总是具有原始精灵的形状而不是整个正方形。 我怀疑那是因为那里原本没有顶点,着色器不会经过这些点,这就是为什么方块被切断了。 我可以以某种方式使这成为可能吗?
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
}
}
}