Hello there! I’m trying to write one of my first shaders, solving a problem I have with displaying a high resolution game map.currently I use 12 square planes with different originally seamless textures on them, aligned perfectly to each other. At certain camera distances, there is still a seam visible because of - naturally - the imperfection of single precision floating point operations. My idea now was to instead of use 12 separate planes, I would use one plane and a shader that gets these 12 textures as a 3D texture, using whichever texture applies to the current uv position as a source.
Aside from having problems with the 3D texture “filling” (they seem to overlay each other instead of being separate textures), I still get a seam at certain distances, which I can’t really explain. Maybe one of the gurus here can help me out with this one or have a better alternative to realising this (e.g. using submaterials on a custom made plane, which would require reworking the underlying plane mesh every time the resolution of the map changes, but ok).
I have simplified the code to just 2 textures for now, just to get the hang of it, but it still won’t work. I have based my code on the “unlit” base shader of Unity:
Shader "Unlit/CraftyMapShader"
{
Properties
{
_texsizeX("MapSizeX", Int) = 1
_texsizeY("MapSizeY", Int) = 1
// _MainTex ("Texture", 3D) = "white" {}
_Tex1("Texture 1", 2D) = "white" {}
_Tex2("Texture 2", 2D) = "white" {}
}
SubShader
{
Tags { "RenderType"="Opaque" }
LOD 100
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
};
sampler2D _Tex1;
sampler2D _Tex2;
float _texsizeX;
float _texsizeY;
v2f vert (appdata v)
{
v2f o;
o.vertex = mul(UNITY_MATRIX_MVP, v.vertex);
o.uv = v.uv;
return o;
}
fixed4 frag(v2f i) : SV_Target
{
int2 mypos = int2(floor(i.uv.x * _texsizeX), floor(i.uv.y * _texsizeY));
float2 xuv = float2(i.uv.x * _texsizeX, i.uv.y * _texsizeY);
float2 uv = float2(xuv.x - floor(xuv.x), i.uv.y - floor(xuv.y));
if( mypos.x == 0 )
return tex2D(_Tex1, uv);
else
return tex2D(_Tex2, uv);
}
ENDCG
}
}
}
And this is what happens:
One distance is fine:
And another is not
Especially when using an animated zoom, these little one-pixel-lines are extremely annoying and especially visible. Any help would be greatly appreciated, thank you!