Hi all,
I have a known problem with seams on a tile map.
What I’ve:
- Textures are power of 2
- Filter mode Point
- the pixel perfect cam from: https://www.assetstore.unity3d.com/en/#!/content/64563
Tile map
Custom Shader:
Settings for this Atlas:
_AtlasSizeInTiles = (4,4,0,0)
_NumberOfTiles = 16
_MapSizeInTiles depends on the game map itself
Shader "Unlit/TileMapShader"
{
Properties
{
_Tilemap("Tilemap", 2D) = "black" {}
_Atlasmap("Atlasmap", 2D) = "white" {}
_NumberOfTiles("Number of Tiles", Int) = 1
_AtlasSizeInTiles("Atlas Size in Tiles", Vector) = (128, 128,0,0)
_MapSizeInTiles("Map Size in Tiles", Vector) = (128, 128,0,0)
}
SubShader
{
Tags { "RenderType"="Opaque" }
LOD 100
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma multi_compile _ PIXELSNAP_ON
//#pragma multi_compile _ PIXELSNAP_ON
// make fog work
//#pragma multi_compile_fog
#include "UnityCG.cginc"
struct appdata
{
float4 vertex : POSITION;
float2 uv0 : TEXCOORD0;
float2 uv1 : TEXCOORD1;
float2 uv2 : TEXCOORD2;
float2 uv3 : TEXCOORD3;
};
struct v2f
{
float2 uv0 : TEXCOORD0;
float2 uv1 : TEXCOORD1;
float2 uv2 : TEXCOORD2;
float2 uv3 : TEXCOORD3;
float4 vertex : SV_POSITION;
};
sampler2D _Tilemap;
sampler2D _Atlasmap;
float4 _Atlasmap_TexelSize;
half _NumberOfTiles;
half2 _AtlasSizeInTiles;
half2 _MapSizeInTiles;
v2f vert (appdata v)
{
v2f result;
//result.vertex = v.vertex;
result.uv0 = v.uv0;
result.uv1 = v.uv1;
result.uv2 = v.uv2;
result.uv3 = v.uv3;
result.vertex = mul(UNITY_MATRIX_MVP, v.vertex);
result.vertex = UnityPixelSnap(result.vertex);
return result;
}
float2 CalcUV(float mapInput, float2 uv) {
int index = mapInput * _NumberOfTiles;
int xpos = index % _AtlasSizeInTiles.x;
int ypos = index / _AtlasSizeInTiles.y;
ypos += 1;
float2 uv_tile = float2(xpos, ypos) / (_AtlasSizeInTiles);
float2 offset = frac(uv * _MapSizeInTiles.xy) / _AtlasSizeInTiles.xy;
// Pixel Perfect
//offset = round(offset * _Atlasmap_TexelSize.zw) * _Atlasmap_TexelSize.xy;
offset = trunc(offset * _Atlasmap_TexelSize.zw) * _Atlasmap_TexelSize.xy;
//offset = floor(offset * _Atlasmap_TexelSize.zw) * _Atlasmap_TexelSize.xy;
uv_tile += float2(offset.x, -offset.y);
return uv_tile;
}
fixed4 frag (v2f i) : SV_Target
{
float2 flipped_uv0 = float2(i.uv0.x, 1.0 - i.uv0.y);
float2 flipped_uv1 = float2(i.uv1.x, 1.0 - i.uv1.y);
float2 flipped_uv2 = float2(i.uv2.x, 1.0 - i.uv2.y);
float2 flipped_uv3 = float2(i.uv3.x, 1.0 - i.uv3.y);
float2 uv0 = CalcUV(tex2D(_Tilemap, flipped_uv0).r, i.uv0);
float2 uv1 = CalcUV(tex2D(_Tilemap, flipped_uv1).r, i.uv1);
float2 uv2 = CalcUV(tex2D(_Tilemap, flipped_uv2).r, i.uv2);
float2 uv3 = CalcUV(tex2D(_Tilemap, flipped_uv3).r, i.uv3);
uv0.y = 1.0f - uv0.y;
uv1.y = 1.0f - uv1.y;
uv2.y = 1.0f - uv2.y;
uv3.y = 1.0f - uv3.y;
return tex2D(_Atlasmap, uv0);
//return half4(uv0.x, uv0.y, 0, 0);
}
ENDCG
}
}
}
Can anyone help me?
Thanks in advance