I am creating a mobile game with a nice ground model. The model is somewhat large (in scale), but only few (less than 200) polygons.
We do not plan on using the build-in unity terrain due it is recommanded not to on mobile development, and we can get build better looking 3D model with fewer polygons ourself.
We need a texture on this big model and kinda stumpled into a problem. Either we put a humongus texture on the ground, and can get all the details we want, or we put a tileing texture on the ground . The humongus texture is not really ideal, we need it to be something like 16kx16k for it to somewhat look good. So the humongus texture is out of the question.
The tile texture have the problem we cannot add any walking visual paths, it is only one tiling texture.
In Unity terrain it is possible to use paint on the terrain and add visual paths this way.
After looking around I have found this solution. And in general using splatmaps.
The best shader for this is in the above link:
Shader "Texture Array with Blendmap" {
Properties
{
_MainTex("Base (RGB)", 2D) = "white" {}
_BlendTex("Blend (RGB)", 2D) = "red" {}
}
Category{
Fog{ Color[_AddFog] }
// ------------------------------------------------------------------
// ARB fragment program
SubShader
{
Pass
{
Tags{ "LightMode" = "Always" }
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct v2f {
float4 pos : POSITION;
float2 uv_diffuse: TEXCOORD0;
float2 uv_blend : TEXCOORD1;
};
float4 _MainTex_ST, _BlendTex_ST;
v2f vert(appdata_base v)
{
v2f o;
o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
o.uv_diffuse = TRANSFORM_TEX(v.texcoord, _MainTex);
o.uv_blend = TRANSFORM_TEX(v.texcoord, _BlendTex);
return o;
}
uniform sampler2D _MainTex;
uniform sampler2D _BlendTex;
float4 frag(v2f i) : COLOR
{
half4 blend = tex2D(_BlendTex, i.uv_blend);
//TODO: Scale and offset sampling area so it is one pixel in from all
// sides - this will prevent bleeding from neighbour textures.
// That will become more difficult for lower mips, though.
float2 sampleScaled = float2(frac(i.uv_diffuse.x) * 0.5, frac(i.uv_diffuse.y) * 0.5);
half4 array_00 = tex2D(_MainTex, sampleScaled);
half4 array_01 = tex2D(_MainTex, sampleScaled + float2(0.0, 0.5));
half4 array_10 = tex2D(_MainTex, sampleScaled + float2(0.5, 0.0));
half4 color = array_00 * blend.r + array_01 * blend.g + array_10 * blend.b;
return color;
}
ENDCG
}
}
}
FallBack "VertexLit"
}
I have found 2 problems with this shader:
-
The problem is this shader “bleeds” one texture into another at the edges, and I don’t know how to fix it.
-
It only allows for 3 tileing subtextures, 4 would be prefered
Thanks